Blender V2.61 - r43446

SG_Spatial.h

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