Panda3D
|
00001 // Filename: eggTransform.h 00002 // Created by: drose (21Jun02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef EGGTRANSFORM_H 00016 #define EGGTRANSFORM_H 00017 00018 #include "pandabase.h" 00019 #include "luse.h" 00020 #include "eggObject.h" 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Class : EggTransform 00024 // Description : This represents the <Transform> entry of a group 00025 // or texture node: a list of component transform 00026 // operations, applied in order, that describe a net 00027 // transform matrix. 00028 // 00029 // This may be either a 3-d transform, and therefore 00030 // described by a 4x4 matrix, or a 2-d transform, 00031 // described by a 3x3 matrix. 00032 //////////////////////////////////////////////////////////////////// 00033 class EXPCL_PANDAEGG EggTransform { 00034 PUBLISHED: 00035 EggTransform(); 00036 EggTransform(const EggTransform ©); 00037 EggTransform &operator = (const EggTransform ©); 00038 virtual ~EggTransform(); 00039 00040 INLINE void clear_transform(); 00041 00042 void add_translate2d(const LVector2d &translate); 00043 void add_translate3d(const LVector3d &translate); 00044 void add_rotate2d(double angle); 00045 void add_rotx(double angle); 00046 void add_roty(double angle); 00047 void add_rotz(double angle); 00048 void add_rotate3d(double angle, const LVector3d &axis); 00049 void add_rotate3d(const LQuaterniond &quat); 00050 void add_scale2d(const LVecBase2d &scale); 00051 void add_scale3d(const LVecBase3d &scale); 00052 void add_uniform_scale(double scale); 00053 INLINE void add_matrix3(const LMatrix3d &mat); 00054 INLINE void add_matrix4(const LMatrix4d &mat); 00055 00056 INLINE bool has_transform() const; 00057 INLINE bool has_transform2d() const; 00058 INLINE void set_transform2d(const LMatrix3d &mat); 00059 INLINE bool has_transform3d() const; 00060 INLINE void set_transform3d(const LMatrix4d &mat); 00061 INLINE LMatrix3d get_transform2d() const; 00062 INLINE const LMatrix4d &get_transform3d() const; 00063 INLINE bool transform_is_identity() const; 00064 00065 enum ComponentType { 00066 CT_invalid, 00067 CT_translate2d, 00068 CT_translate3d, 00069 CT_rotate2d, 00070 CT_rotx, 00071 CT_roty, 00072 CT_rotz, 00073 CT_rotate3d, 00074 CT_scale2d, 00075 CT_scale3d, 00076 CT_uniform_scale, 00077 CT_matrix3, 00078 CT_matrix4 00079 }; 00080 00081 INLINE int get_num_components() const; 00082 INLINE ComponentType get_component_type(int n) const; 00083 INLINE double get_component_number(int n) const; 00084 INLINE const LVecBase2d &get_component_vec2(int n) const; 00085 INLINE const LVecBase3d &get_component_vec3(int n) const; 00086 INLINE const LMatrix3d &get_component_mat3(int n) const; 00087 INLINE const LMatrix4d &get_component_mat4(int n) const; 00088 00089 void write(ostream &out, int indent_level, 00090 const string &label) const; 00091 00092 protected: 00093 void internal_clear_transform(); 00094 void internal_add_matrix(const LMatrix3d &mat); 00095 void internal_add_matrix(const LMatrix4d &mat); 00096 INLINE void internal_set_transform(const LMatrix3d &mat); 00097 INLINE void internal_set_transform(const LMatrix4d &mat); 00098 00099 virtual void transform_changed(); 00100 00101 private: 00102 class Component { 00103 public: 00104 INLINE Component(ComponentType type, double number = 0.0); 00105 INLINE Component(const Component ©); 00106 INLINE void operator = (const Component ©); 00107 INLINE ~Component(); 00108 00109 ComponentType _type; 00110 double _number; 00111 LVecBase2d *_vec2; 00112 LVecBase3d *_vec3; 00113 LMatrix3d *_mat3; 00114 LMatrix4d *_mat4; 00115 }; 00116 00117 bool _is_transform_2d; 00118 typedef pvector<Component> Components; 00119 Components _components; 00120 LMatrix4d _transform; 00121 }; 00122 00123 #include "eggTransform.I" 00124 00125 #endif