|
Blender
V2.59
|
00001 /* 00002 * $Id: SG_Spatial.h 35082 2011-02-22 19:30:37Z jesterking $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00021 * All rights reserved. 00022 * 00023 * The Original Code is: all of this file. 00024 * 00025 * Contributor(s): none yet. 00026 * 00027 * ***** END GPL LICENSE BLOCK ***** 00028 */ 00029 00034 #ifndef __SG_SPATIAL_H 00035 #define __SG_SPATIAL_H 00036 00037 #include <MT_Vector3.h> 00038 #include <MT_Point3.h> 00039 #include <MT_Matrix3x3.h> // or Quaternion later ? 00040 #include "SG_IObject.h" 00041 #include "SG_BBox.h" 00042 #include "SG_ParentRelation.h" 00043 00044 00045 class SG_Node; 00046 class SG_ParentRelation; 00047 00053 class SG_Spatial : public SG_IObject 00054 { 00055 00056 protected: 00057 MT_Point3 m_localPosition; 00058 MT_Matrix3x3 m_localRotation; 00059 MT_Vector3 m_localScaling; 00060 00061 MT_Point3 m_worldPosition; 00062 MT_Matrix3x3 m_worldRotation; 00063 MT_Vector3 m_worldScaling; 00064 00065 SG_ParentRelation * m_parent_relation; 00066 00067 SG_BBox m_bbox; 00068 MT_Scalar m_radius; 00069 bool m_modified; 00070 bool m_ogldirty; // true if the openGL matrix for this object must be recomputed 00071 00072 public: 00073 inline void ClearModified() 00074 { 00075 m_modified = false; 00076 m_ogldirty = true; 00077 } 00078 inline void SetModified() 00079 { 00080 m_modified = true; 00081 ActivateScheduleUpdateCallback(); 00082 } 00083 inline void ClearDirty() 00084 { 00085 m_ogldirty = false; 00086 } 00101 void 00102 SetParentRelation( 00103 SG_ParentRelation *relation 00104 ); 00105 00106 SG_ParentRelation * GetParentRelation() 00107 { 00108 return m_parent_relation; 00109 } 00110 00111 00112 00113 00123 void 00124 RelativeTranslate( 00125 const MT_Vector3& trans, 00126 const SG_Spatial *parent, 00127 bool local 00128 ); 00129 00130 void SetLocalPosition(const MT_Point3& trans) 00131 { 00132 m_localPosition = trans; 00133 SetModified(); 00134 } 00135 00136 void SetWorldPosition(const MT_Point3& trans) 00137 { 00138 m_worldPosition = trans; 00139 } 00140 00141 00142 void 00143 RelativeRotate( 00144 const MT_Matrix3x3& rot, 00145 bool local 00146 ); 00147 00148 void SetLocalOrientation(const MT_Matrix3x3& rot) 00149 { 00150 m_localRotation = rot; 00151 SetModified(); 00152 } 00153 00154 // rot is arrange like openGL matrix 00155 void SetLocalOrientation(const float* rot) 00156 { 00157 m_localRotation.setValue(rot); 00158 SetModified(); 00159 } 00160 00161 void SetWorldOrientation(const MT_Matrix3x3& rot) 00162 { 00163 m_worldRotation = rot; 00164 } 00165 00166 void RelativeScale(const MT_Vector3& scale) 00167 { 00168 m_localScaling = m_localScaling * scale; 00169 SetModified(); 00170 } 00171 00172 void SetLocalScale(const MT_Vector3& scale) 00173 { 00174 m_localScaling = scale; 00175 SetModified(); 00176 } 00177 00178 void SetWorldScale(const MT_Vector3& scale) 00179 { 00180 m_worldScaling = scale; 00181 } 00182 00183 const MT_Point3& GetLocalPosition() const 00184 { 00185 return m_localPosition; 00186 } 00187 00188 const MT_Matrix3x3& GetLocalOrientation() const 00189 { 00190 return m_localRotation; 00191 } 00192 00193 const MT_Vector3& GetLocalScale() const 00194 { 00195 return m_localScaling; 00196 } 00197 00198 const MT_Point3& GetWorldPosition() const 00199 { 00200 return m_worldPosition; 00201 } 00202 00203 const MT_Matrix3x3& GetWorldOrientation() const 00204 { 00205 return m_worldRotation; 00206 } 00207 00208 const MT_Vector3& GetWorldScaling() const 00209 { 00210 return m_worldScaling; 00211 } 00212 00213 void SetWorldFromLocalTransform() 00214 { 00215 m_worldPosition= m_localPosition; 00216 m_worldScaling= m_localScaling; 00217 m_worldRotation= m_localRotation; 00218 } 00219 00220 00221 00222 MT_Transform GetWorldTransform() const; 00223 00224 bool ComputeWorldTransforms(const SG_Spatial *parent, bool& parentUpdated) 00225 { 00226 return m_parent_relation->UpdateChildCoordinates(this,parent,parentUpdated); 00227 } 00228 00229 00233 SG_BBox& BBox() 00234 { 00235 return m_bbox; 00236 } 00237 00238 void SetBBox(SG_BBox& bbox) 00239 { 00240 m_bbox = bbox; 00241 } 00242 00243 00244 bool inside(const MT_Point3 &point) const; 00245 void getBBox(MT_Point3 *box) const; 00246 void getAABBox(MT_Point3 *box) const; 00247 00248 MT_Scalar Radius() const { return m_radius; } 00249 void SetRadius(MT_Scalar radius) { m_radius = radius; } 00250 bool IsModified() { return m_modified; } 00251 bool IsDirty() { return m_ogldirty; } 00252 00253 protected: 00254 friend class SG_Controller; 00255 friend class KX_BoneParentRelation; 00256 friend class KX_VertexParentRelation; 00257 friend class KX_SlowParentRelation; 00258 friend class KX_NormalParentRelation; 00259 00265 SG_Spatial( 00266 void* clientobj, 00267 void* clientinfo, 00268 SG_Callbacks& callbacks 00269 ); 00270 00271 SG_Spatial( 00272 const SG_Spatial& other 00273 ); 00274 00275 00276 virtual ~SG_Spatial(); 00277 00283 bool 00284 UpdateSpatialData( 00285 const SG_Spatial *parent, 00286 double time, 00287 bool& parentUpdated 00288 ); 00289 00290 00291 #ifdef WITH_CXX_GUARDEDALLOC 00292 public: 00293 void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:SG_Spatial"); } 00294 void operator delete( void *mem ) { MEM_freeN(mem); } 00295 #endif 00296 }; 00297 00298 #endif //__SG_SPATIAL_H 00299