2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file SG_Spatial.h
32 #ifndef __SG_SPATIAL_H__
33 #define __SG_SPATIAL_H__
35 #include <MT_Vector3.h>
36 #include <MT_Point3.h>
37 #include <MT_Matrix3x3.h> // or Quaternion later ?
38 #include "SG_IObject.h"
40 #include "SG_ParentRelation.h"
44 class SG_ParentRelation;
47 * SG_Spatial contains spatial information (local & world position, rotation
48 * and scaling) for a Scene graph node.
49 * It also contains a link to the node's parent.
51 class SG_Spatial : public SG_IObject
55 MT_Point3 m_localPosition;
56 MT_Matrix3x3 m_localRotation;
57 MT_Vector3 m_localScaling;
59 MT_Point3 m_worldPosition;
60 MT_Matrix3x3 m_worldRotation;
61 MT_Vector3 m_worldScaling;
63 SG_ParentRelation * m_parent_relation;
68 bool m_ogldirty; // true if the openGL matrix for this object must be recomputed
71 inline void ClearModified()
76 inline void SetModified()
79 ActivateScheduleUpdateCallback();
81 inline void ClearDirty()
86 * Define the relationship this node has with it's parent
87 * node. You should pass an unshared instance of an SG_ParentRelation
88 * allocated on the heap to this method. Ownership of this
89 * instance is assumed by this class.
90 * You may call this function several times in the lifetime
91 * of a node to change the relationship dynamically.
92 * You must call this method before the first call to UpdateSpatialData().
93 * An assertion will be fired at run-time in debug if this is not
95 * The relation is activated only if no controllers of this object
96 * updated the coordinates of the child.
101 SG_ParentRelation *relation
104 SG_ParentRelation * GetParentRelation()
106 return m_parent_relation;
113 * Apply a translation relative to the current position.
114 * if local then the translation is assumed to be in the
115 * local coordinates of this object. If not then the translation
116 * is assumed to be in global coordinates. In this case
117 * you must provide a pointer to the parent of this object if it
118 * exists otherwise if there is no parent set it to NULL
123 const MT_Vector3& trans,
124 const SG_Spatial *parent,
128 void SetLocalPosition(const MT_Point3& trans)
130 m_localPosition = trans;
134 void SetWorldPosition(const MT_Point3& trans)
136 m_worldPosition = trans;
142 const MT_Matrix3x3& rot,
146 void SetLocalOrientation(const MT_Matrix3x3& rot)
148 m_localRotation = rot;
152 // rot is arrange like openGL matrix
153 void SetLocalOrientation(const float* rot)
155 m_localRotation.setValue(rot);
159 void SetWorldOrientation(const MT_Matrix3x3& rot)
161 m_worldRotation = rot;
164 void RelativeScale(const MT_Vector3& scale)
166 m_localScaling = m_localScaling * scale;
170 void SetLocalScale(const MT_Vector3& scale)
172 m_localScaling = scale;
176 void SetWorldScale(const MT_Vector3& scale)
178 m_worldScaling = scale;
181 const MT_Point3& GetLocalPosition() const
183 return m_localPosition;
186 const MT_Matrix3x3& GetLocalOrientation() const
188 return m_localRotation;
191 const MT_Vector3& GetLocalScale() const
193 return m_localScaling;
196 const MT_Point3& GetWorldPosition() const
198 return m_worldPosition;
201 const MT_Matrix3x3& GetWorldOrientation() const
203 return m_worldRotation;
206 const MT_Vector3& GetWorldScaling() const
208 return m_worldScaling;
211 void SetWorldFromLocalTransform()
213 m_worldPosition= m_localPosition;
214 m_worldScaling= m_localScaling;
215 m_worldRotation= m_localRotation;
220 MT_Transform GetWorldTransform() const;
222 bool ComputeWorldTransforms(const SG_Spatial *parent, bool& parentUpdated)
224 return m_parent_relation->UpdateChildCoordinates(this,parent,parentUpdated);
229 * Bounding box functions.
236 void SetBBox(SG_BBox& bbox)
242 bool inside(const MT_Point3 &point) const;
243 void getBBox(MT_Point3 *box) const;
244 void getAABBox(MT_Point3 *box) const;
246 MT_Scalar Radius() const { return m_radius; }
247 void SetRadius(MT_Scalar radius) { m_radius = radius; }
248 bool IsModified() { return m_modified; }
249 bool IsDirty() { return m_ogldirty; }
252 friend class SG_Controller;
253 friend class KX_BoneParentRelation;
254 friend class KX_VertexParentRelation;
255 friend class KX_SlowParentRelation;
256 friend class KX_NormalParentRelation;
259 * Protected constructor this class is not
260 * designed for direct instantiation
266 SG_Callbacks& callbacks
270 const SG_Spatial& other
274 virtual ~SG_Spatial();
277 * Update the world coordinates of this spatial node. This also informs
278 * any controllers to update this object.
283 const SG_Spatial *parent,
289 #ifdef WITH_CXX_GUARDEDALLOC
290 MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_Spatial")
294 #endif //__SG_SPATIAL_H__