Simulant  21.12-246
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
spherical_billboard.h
1 #pragma once
2 
3 #include "../behaviour.h"
4 #include "../stage_node_behaviour.h"
5 #include "../../generic/managed.h"
6 
7 namespace smlt {
8 namespace behaviours {
9 
11  public StageNodeBehaviour,
12  public RefCounted<SphericalBillboard> {
13 
14 public:
16  target_(target) {}
17 
18  void set_target(StageNode* target) {
19  target_ = target;
20  }
21 
22  void late_update(float dt) override {
23  _S_UNUSED(dt);
24 
25  if(target_) {
26  auto dir = (
27  target_->absolute_position() - stage_node->absolute_position()
28  ).normalized();
29 
30  auto rot = smlt::Vec3::NEGATIVE_Z.rotation_to(dir);
31  stage_node->rotate_to_absolute(rot);
32  }
33  }
34 
35  const char* name() const override {
36  return "spherical_billboard";
37  }
38 private:
39  StageNode* target_ = nullptr;
40 };
41 
42 }
43 }
smlt::behaviours::StageNodeBehaviour
Definition: stage_node_behaviour.h:12
smlt::RefCounted
Definition: managed.h:65
smlt
Definition: animation.cpp:25
smlt::behaviours::SphericalBillboard
Definition: spherical_billboard.h:12
smlt::StageNode
Definition: stage_node.h:61