Panda3D
eggTransform.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file eggTransform.h
10  * @author drose
11  * @date 2002-06-21
12  */
13 
14 #ifndef EGGTRANSFORM_H
15 #define EGGTRANSFORM_H
16 
17 #include "pandabase.h"
18 #include "luse.h"
19 #include "eggObject.h"
20 
21 /**
22  * This represents the <Transform> entry of a group or texture node: a list of
23  * component transform operations, applied in order, that describe a net
24  * transform matrix.
25  *
26  * This may be either a 3-d transform, and therefore described by a 4x4
27  * matrix, or a 2-d transform, described by a 3x3 matrix.
28  */
29 class EXPCL_PANDA_EGG EggTransform {
30 PUBLISHED:
31  EggTransform();
32  EggTransform(const EggTransform &copy);
33  EggTransform &operator = (const EggTransform &copy);
34  virtual ~EggTransform();
35 
36  INLINE void clear_transform();
37 
38  void add_translate2d(const LVector2d &translate);
39  void add_translate3d(const LVector3d &translate);
40  void add_rotate2d(double angle);
41  void add_rotx(double angle);
42  void add_roty(double angle);
43  void add_rotz(double angle);
44  void add_rotate3d(double angle, const LVector3d &axis);
45  void add_rotate3d(const LQuaterniond &quat);
46  void add_scale2d(const LVecBase2d &scale);
47  void add_scale3d(const LVecBase3d &scale);
48  void add_uniform_scale(double scale);
49  INLINE void add_matrix3(const LMatrix3d &mat);
50  INLINE void add_matrix4(const LMatrix4d &mat);
51 
52  INLINE bool has_transform() const;
53  INLINE bool has_transform2d() const;
54  INLINE void set_transform2d(const LMatrix3d &mat);
55  INLINE bool has_transform3d() const;
56  INLINE void set_transform3d(const LMatrix4d &mat);
57  INLINE LMatrix3d get_transform2d() const;
58  INLINE const LMatrix4d &get_transform3d() const;
59  INLINE bool transform_is_identity() const;
60 
61  enum ComponentType {
62  CT_invalid,
63  CT_translate2d,
64  CT_translate3d,
65  CT_rotate2d,
66  CT_rotx,
67  CT_roty,
68  CT_rotz,
69  CT_rotate3d,
70  CT_scale2d,
71  CT_scale3d,
72  CT_uniform_scale,
73  CT_matrix3,
74  CT_matrix4
75  };
76 
77  INLINE int get_num_components() const;
78  INLINE ComponentType get_component_type(int n) const;
79  INLINE double get_component_number(int n) const;
80  INLINE const LVecBase2d &get_component_vec2(int n) const;
81  INLINE const LVecBase3d &get_component_vec3(int n) const;
82  INLINE const LMatrix3d &get_component_mat3(int n) const;
83  INLINE const LMatrix4d &get_component_mat4(int n) const;
84 
85  void write(std::ostream &out, int indent_level,
86  const std::string &label) const;
87 
88 protected:
89  void internal_clear_transform();
90  void internal_add_matrix(const LMatrix3d &mat);
91  void internal_add_matrix(const LMatrix4d &mat);
92  INLINE void internal_set_transform(const LMatrix3d &mat);
93  INLINE void internal_set_transform(const LMatrix4d &mat);
94 
95  virtual void transform_changed();
96 
97 private:
98  class Component {
99  public:
100  INLINE Component(ComponentType type, double number = 0.0);
101  INLINE Component(const Component &copy);
102  INLINE void operator = (const Component &copy);
103  INLINE ~Component();
104 
105  ComponentType _type;
106  double _number;
107  LVecBase2d *_vec2;
108  LVecBase3d *_vec3;
109  LMatrix3d *_mat3;
110  LMatrix4d *_mat4;
111  };
112 
113  bool _is_transform_2d;
115  Components _components;
116  LMatrix4d _transform;
117 };
118 
119 #include "eggTransform.I"
120 
121 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This represents the <Transform> entry of a group or texture node: a list of component transform opera...
Definition: eggTransform.h:29