Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
transformable.h
1 #pragma once
2 
3 #include "../types.h"
4 #include "./locateable.h"
5 
6 namespace smlt {
7 
8 typedef sig::signal<void ()> TransformationChangedSignal;
9 
10 
17  public Locateable {
18 
19  DEFINE_SIGNAL(TransformationChangedSignal, signal_transformation_changed);
20 
21 public:
22  virtual ~Transformable() {}
23 
24  smlt::Vec3 position() const { return position_; }
25  smlt::Vec2 position_2d() const { return Vec2(position_.x, position_.y); }
26  smlt::Quaternion rotation() const { return rotation_; }
27  smlt::Vec3 scale() const { return scaling_; }
28 
29  virtual void move_to(const smlt::Vec3& pos);
30  virtual void move_to(const smlt::Vec2& pos);
31  virtual void move_to(float x, float y, float z);
32  virtual void move_to(float x, float y);
33 
34  virtual void move_by(const smlt::Vec3& pos);
35  virtual void move_by(const smlt::Vec2& pos);
36  virtual void move_by(float x, float y, float z);
37  virtual void move_by(float x, float y);
38 
39  virtual void move_forward_by(float amount);
40  virtual void move_right_by(float amount);
41  virtual void move_up_by(float amount);
42 
43  virtual void rotate_to(const smlt::Degrees& angle, float axis_x, float axis_y, float axis_z);
44  virtual void rotate_to(const smlt::Degrees& angle, const smlt::Vec3& axis);
45  virtual void rotate_to(const smlt::Quaternion& rotation);
46 
47  virtual void rotate_x_by(const smlt::Degrees& angle);
48  virtual void rotate_y_by(const smlt::Degrees& angle);
49  virtual void rotate_z_by(const smlt::Degrees& angle);
50  virtual void rotate_by(const smlt::Degrees& angle_x, const smlt::Degrees& angle_y, const smlt::Degrees& angle_z);
51  virtual void rotate_by(const smlt::Vec3& angles);
52 
53  virtual void scale_x_by(const float scale);
54  virtual void scale_y_by(const float scale);
55  virtual void scale_z_by(const float scale);
56  virtual void scale_by(float x);
57  virtual void scale_by(const Vec3& x);
58  virtual void scale_to(const float x, const float y, const float z);
59 
60  virtual void rotate_around(const smlt::Vec3& axis, const smlt::Degrees& degrees);
61 
62  void rotate_global_x_by(const smlt::Degrees& degrees);
63  void rotate_global_y_by(const smlt::Degrees& degrees);
64  void rotate_global_z_by(const smlt::Degrees& degrees);
65 
66  virtual void look_at(const smlt::Vec3& target, const Vec3 &up=Vec3::POSITIVE_Y);
67  virtual void look_at(float x, float y, float z, const Vec3 &up=Vec3::POSITIVE_Y);
68 
69  Vec3 right() const;
70  Vec3 up() const;
71  Vec3 forward() const;
72 
73  void constrain_to_aabb(const AABB& region);
74  bool is_constrained() const;
75  void remove_constraint();
76 
77 protected:
78  void set_position(const Vec3& p);
79  void set_rotation(const Quaternion& q);
80  void set_scaling(const Vec3& s);
81 
82  virtual void on_transformation_changed() {}
83 
84  /* Called when a transformation is attempted, even if it doesn't
85  * result in any change */
86  virtual void on_transformation_change_attempted() {}
87 
88  Vec3 position_;
89  Quaternion rotation_;
90  Vec3 scaling_ = Vec3(1, 1, 1);
91 
92  std::unique_ptr<AABB> constraint_;
93 };
94 
95 }
smlt::Locateable
The Locateable class.
Definition: locateable.h:12
smlt::Vec3
Definition: vec3.h:23
smlt::Quaternion
Definition: quaternion.h:24
smlt
Definition: animation.cpp:25
smlt::Degrees
Definition: degrees.h:7
smlt::AABB
Definition: aabb.h:22
smlt::Transformable
The Transformable class.
Definition: transformable.h:17
smlt::Vec2
Definition: vec2.h:13
smlt::sig::signal< void()>