00001 // Filename: eggTransform3d.I 00002 // Created by: drose (21Jun02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: EggTransform3d::Component::Constructor 00021 // Access: Public 00022 // Description: 00023 //////////////////////////////////////////////////////////////////// 00024 INLINE EggTransform3d::Component:: 00025 Component(EggTransform3d::ComponentType type, double number) : 00026 _type(type), 00027 _number(number) 00028 { 00029 _vector = (LVector3d *)NULL; 00030 _matrix = (LMatrix4d *)NULL; 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: EggTransform3d::Component::Copy Constructor 00035 // Access: Public 00036 // Description: 00037 //////////////////////////////////////////////////////////////////// 00038 INLINE EggTransform3d::Component:: 00039 Component(const EggTransform3d::Component ©) : 00040 _type(copy._type), 00041 _number(copy._number) 00042 { 00043 _vector = (LVector3d *)NULL; 00044 _matrix = (LMatrix4d *)NULL; 00045 if (copy._vector != (LVector3d *)NULL) { 00046 _vector = new LVector3d(*copy._vector); 00047 } 00048 if (copy._matrix != (LMatrix4d *)NULL) { 00049 _matrix = new LMatrix4d(*copy._matrix); 00050 } 00051 } 00052 00053 //////////////////////////////////////////////////////////////////// 00054 // Function: EggTransform3d::Component::Copy Assignment Operator 00055 // Access: Public 00056 // Description: 00057 //////////////////////////////////////////////////////////////////// 00058 INLINE void EggTransform3d::Component:: 00059 operator = (const EggTransform3d::Component ©) { 00060 _type = copy._type; 00061 _number = copy._number; 00062 if (_vector != (LVector3d *)NULL) { 00063 delete _vector; 00064 _vector = (LVector3d *)NULL; 00065 } 00066 if (_matrix != (LMatrix4d *)NULL) { 00067 delete _matrix; 00068 _matrix = (LMatrix4d *)NULL; 00069 } 00070 if (copy._vector != (LVector3d *)NULL) { 00071 _vector = new LVector3d(*copy._vector); 00072 } 00073 if (copy._matrix != (LMatrix4d *)NULL) { 00074 _matrix = new LMatrix4d(*copy._matrix); 00075 } 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: EggTransform3d::Component::Destructor 00080 // Access: Public 00081 // Description: 00082 //////////////////////////////////////////////////////////////////// 00083 INLINE EggTransform3d::Component:: 00084 ~Component() { 00085 if (_vector != (LVector3d *)NULL) { 00086 delete _vector; 00087 } 00088 if (_matrix != (LMatrix4d *)NULL) { 00089 delete _matrix; 00090 } 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: EggTransform3d::clear_transform 00095 // Access: Public 00096 // Description: Resets the transform to empty, identity. 00097 //////////////////////////////////////////////////////////////////// 00098 INLINE void EggTransform3d:: 00099 clear_transform() { 00100 internal_clear_transform(); 00101 transform_changed(); 00102 } 00103 00104 //////////////////////////////////////////////////////////////////// 00105 // Function: EggTransform3d::add_matrix 00106 // Access: Public 00107 // Description: Appends an arbitrary 4x4 matrix to the current 00108 // transform. 00109 //////////////////////////////////////////////////////////////////// 00110 INLINE void EggTransform3d:: 00111 add_matrix(const LMatrix4d &mat) { 00112 internal_add_matrix(mat); 00113 transform_changed(); 00114 } 00115 00116 //////////////////////////////////////////////////////////////////// 00117 // Function: EggTransform3d::has_transform 00118 // Access: Public 00119 // Description: Returns true if the transform is nonempty, false if 00120 // it is empty (no transform components have been 00121 // added). 00122 //////////////////////////////////////////////////////////////////// 00123 INLINE bool EggTransform3d:: 00124 has_transform() const { 00125 return !_components.empty(); 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: EggTransform3d::set_transform 00130 // Access: Public 00131 // Description: Sets the overall transform as a 4x4 matrix. This 00132 // completely replaces whatever componentwise transform 00133 // may have been defined. 00134 //////////////////////////////////////////////////////////////////// 00135 INLINE void EggTransform3d:: 00136 set_transform(const LMatrix4d &mat) { 00137 internal_set_transform(mat); 00138 transform_changed(); 00139 } 00140 00141 //////////////////////////////////////////////////////////////////// 00142 // Function: EggTransform3d::get_transform 00143 // Access: Public 00144 // Description: Returns the overall transform as a 4x4 matrix. 00145 //////////////////////////////////////////////////////////////////// 00146 INLINE const LMatrix4d &EggTransform3d:: 00147 get_transform() const { 00148 return _transform; 00149 } 00150 00151 //////////////////////////////////////////////////////////////////// 00152 // Function: EggTransform3d::transform_is_identity 00153 // Access: Public 00154 // Description: Returns true if the described transform is identity, 00155 // false otherwise. 00156 //////////////////////////////////////////////////////////////////// 00157 INLINE bool EggTransform3d:: 00158 transform_is_identity() const { 00159 return _components.empty() || 00160 _transform.almost_equal(LMatrix4d::ident_mat(), 0.0001); 00161 } 00162 00163 //////////////////////////////////////////////////////////////////// 00164 // Function: EggTransform3d::get_num_components 00165 // Access: Public 00166 // Description: Returns the number of components that make up the 00167 // transform. 00168 //////////////////////////////////////////////////////////////////// 00169 INLINE int EggTransform3d:: 00170 get_num_components() const { 00171 return _components.size(); 00172 } 00173 00174 //////////////////////////////////////////////////////////////////// 00175 // Function: EggTransform3d::get_component_type 00176 // Access: Public 00177 // Description: Returns the type of the nth component. 00178 //////////////////////////////////////////////////////////////////// 00179 INLINE EggTransform3d::ComponentType EggTransform3d:: 00180 get_component_type(int n) const { 00181 nassertr(n >= 0 && n < (int)_components.size(), CT_invalid); 00182 return _components[n]._type; 00183 } 00184 00185 //////////////////////////////////////////////////////////////////// 00186 // Function: EggTransform3d::get_component_number 00187 // Access: Public 00188 // Description: Returns the solitary number associated with the nth 00189 // component. In the case of a rotation, this is the 00190 // angle in degrees to rotate; in the case of uniform 00191 // scale, this is the amount of the scale. Other types 00192 // do not use this property. 00193 //////////////////////////////////////////////////////////////////// 00194 INLINE double EggTransform3d:: 00195 get_component_number(int n) const { 00196 nassertr(n >= 0 && n < (int)_components.size(), 0.0); 00197 return _components[n]._number; 00198 } 00199 00200 //////////////////////////////////////////////////////////////////// 00201 // Function: EggTransform3d::get_component_vector 00202 // Access: Public 00203 // Description: Returns the 3-component vector associated with the 00204 // nth component. This may be the translate vector, 00205 // rotate axis, or non-uniform scale. It is an error to 00206 // call this if the component type does not use a vector 00207 // property. 00208 //////////////////////////////////////////////////////////////////// 00209 INLINE const LVector3d &EggTransform3d:: 00210 get_component_vector(int n) const { 00211 nassertr(n >= 0 && n < (int)_components.size(), LVector3d::zero()); 00212 nassertr(_components[n]._vector != (LVector3d *)NULL, LVector3d::zero()); 00213 return *_components[n]._vector; 00214 } 00215 00216 //////////////////////////////////////////////////////////////////// 00217 // Function: EggTransform3d::get_component_matrix 00218 // Access: Public 00219 // Description: Returns the 4x4 matrix associated with the nth 00220 // component. It is an error to call this if the 00221 // component type is not CT_matrix. 00222 //////////////////////////////////////////////////////////////////// 00223 INLINE const LMatrix4d &EggTransform3d:: 00224 get_component_matrix(int n) const { 00225 nassertr(n >= 0 && n < (int)_components.size(), LMatrix4d::ident_mat()); 00226 nassertr(_components[n]._matrix != (LMatrix4d *)NULL, LMatrix4d::ident_mat()); 00227 return *_components[n]._matrix; 00228 } 00229 00230 //////////////////////////////////////////////////////////////////// 00231 // Function: EggTransform3d::internal_set_transform 00232 // Access: Protected 00233 // Description: Sets the overall transform without calling 00234 // transform_changed(). 00235 //////////////////////////////////////////////////////////////////// 00236 INLINE void EggTransform3d:: 00237 internal_set_transform(const LMatrix4d &mat) { 00238 internal_clear_transform(); 00239 internal_add_matrix(mat); 00240 }