OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreTransform.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Transform_H__
29 #define __Transform_H__
30 
31 #include "OgreArrayMatrix4.h"
32 #include "OgreArrayMemoryManager.h"
33 
34 namespace Ogre
35 {
37  struct Transform
38  {
40  unsigned char mIndex;
41 
44 
47 
50 
53 
56 
59 
62 
65 
68 
72 
76 
78  mIndex( 0 ),
79  mParents( 0 ),
80  mOwner( 0 ),
81  mPosition( 0 ),
82  mOrientation( 0 ),
83  mScale( 0 ),
84  mDerivedPosition( 0 ),
86  mDerivedScale( 0 ),
87  mDerivedTransform( 0 ),
89  mInheritScale( 0 )
90  {
91  }
92 
105  void copy( const Transform &inCopy )
106  {
107  mParents[mIndex] = inCopy.mParents[inCopy.mIndex];
108  mOwner[mIndex] = inCopy.mOwner[inCopy.mIndex];
109 
110  Vector3 tmp;
111  Quaternion qTmp;
112 
113  //Position
114  inCopy.mPosition->getAsVector3( tmp, inCopy.mIndex );
116 
117  //Orientation
118  inCopy.mOrientation->getAsQuaternion( qTmp, inCopy.mIndex );
120 
121  //Scale
122  inCopy.mScale->getAsVector3( tmp, inCopy.mIndex );
123  mScale->setFromVector3( tmp, mIndex );
124 
125  //Derived position
126  inCopy.mDerivedPosition->getAsVector3( tmp, inCopy.mIndex );
128 
129  //Derived orientation
130  inCopy.mDerivedOrientation->getAsQuaternion( qTmp, inCopy.mIndex );
132 
133  //Derived scale
134  inCopy.mDerivedScale->getAsVector3( tmp, inCopy.mIndex );
136 
138 
140  mInheritScale[mIndex] = inCopy.mInheritScale[inCopy.mIndex];
141  }
142 
151  void rebasePtrs( const MemoryPoolVec &newBasePtrs, const ptrdiff_t diff )
152  {
153  mParents = reinterpret_cast<Node**>( newBasePtrs[NodeArrayMemoryManager::Parent] + diff );
154  mOwner = reinterpret_cast<Node**>( newBasePtrs[NodeArrayMemoryManager::Owner] + diff );
155 
156  mPosition = reinterpret_cast<ArrayVector3*>(
157  newBasePtrs[NodeArrayMemoryManager::Position] + diff );
158  mOrientation = reinterpret_cast<ArrayQuaternion*>(
159  newBasePtrs[NodeArrayMemoryManager::Orientation] + diff );
160  mScale = reinterpret_cast<ArrayVector3*>(
161  newBasePtrs[NodeArrayMemoryManager::Scale] + diff );
162 
163  mDerivedPosition = reinterpret_cast<ArrayVector3*>(
164  newBasePtrs[NodeArrayMemoryManager::DerivedPosition] + diff );
165  mDerivedOrientation = reinterpret_cast<ArrayQuaternion*>(
166  newBasePtrs[NodeArrayMemoryManager::DerivedOrientation] + diff );
167  mDerivedScale = reinterpret_cast<ArrayVector3*>(
168  newBasePtrs[NodeArrayMemoryManager::DerivedScale] + diff );
169 
170  mDerivedTransform = reinterpret_cast<Matrix4*>(
171  newBasePtrs[NodeArrayMemoryManager::WorldMat] + diff );
172 
173  mInheritOrientation = reinterpret_cast<bool*>(
174  newBasePtrs[NodeArrayMemoryManager::InheritOrientation] + diff );
175  mInheritScale = reinterpret_cast<bool*>(
176  newBasePtrs[NodeArrayMemoryManager::InheritScale] + diff );
177  }
178 
182  void advancePack()
183  {
186  ++mPosition;
187  ++mOrientation;
188  ++mScale;
191  ++mDerivedScale;
195  }
196 
197  void advancePack( size_t numAdvance )
198  {
199  mParents += ARRAY_PACKED_REALS * numAdvance;
200  mOwner += ARRAY_PACKED_REALS * numAdvance;
201  mPosition += numAdvance;
202  mOrientation += numAdvance;
203  mScale += numAdvance;
204  mDerivedPosition += numAdvance;
205  mDerivedOrientation += numAdvance;
206  mDerivedScale += numAdvance;
207  mDerivedTransform += ARRAY_PACKED_REALS * numAdvance;
208  mInheritOrientation += ARRAY_PACKED_REALS * numAdvance;
209  mInheritScale += ARRAY_PACKED_REALS * numAdvance;
210  }
211  };
212 }
213 
214 #endif
Class encapsulating a standard 4x4 homogeneous matrix.
Definition: OgreMatrix4.h:79
Represents the transform of a single object, arranged in SoA (Structure of Arrays) ...
Definition: OgreTransform.h:37
void getAsQuaternion(Quaternion &out, size_t index) const
void copy(const Transform &inCopy)
Copies all the scalar data from the parameter into this.
void setFromQuaternion(const Quaternion &v, size_t index)
Node ** mParents
Holds the pointers to each parent. Ours is mParents[mIndex].
Definition: OgreTransform.h:43
ArrayVector3 *RESTRICT_ALIAS mScale
Stores the scaling factor applied to a node.
Definition: OgreTransform.h:55
void rebasePtrs(const MemoryPoolVec &newBasePtrs, const ptrdiff_t diff)
Rebases all the pointers from our SoA structs so that they point to a new location calculated from a ...
void getAsVector3(Vector3 &out, size_t index) const
void advancePack()
Advances all pointers to the next pack, i.e.
Node ** mOwner
The Node that owns this Transform. Ours is mOwner[mIndex].
Definition: OgreTransform.h:46
#define RESTRICT_ALIAS
Definition: OgrePlatform.h:448
Implementation of a Quaternion, i.e.
Matrix4 *RESTRICT_ALIAS mDerivedTransform
Caches the full transform into a 4x4 matrix. Note it's not Array form! (It's AoS) ...
Definition: OgreTransform.h:67
ArrayQuaternion *RESTRICT_ALIAS mOrientation
Stores the orientation of a node relative to it's parent.
Definition: OgreTransform.h:52
Cache-friendly array of 3-dimensional represented as a SoA array.
void setFromVector3(const Vector3 &v, size_t index)
ArrayVector3 *RESTRICT_ALIAS mDerivedScale
Caches the combined scale from all parent nodes.
Definition: OgreTransform.h:64
#define ARRAY_PACKED_REALS
Standard 3-dimensional vector.
Definition: OgreVector3.h:50
bool *RESTRICT_ALIAS mInheritOrientation
Stores whether this node inherits orientation from it's parent.
Definition: OgreTransform.h:71
unsigned char mIndex
Which of the packed values is ours. Value in range [0; 4) for SSE2.
Definition: OgreTransform.h:40
ArrayVector3 *RESTRICT_ALIAS mDerivedPosition
Caches the combined position from all parent nodes.
Definition: OgreTransform.h:58
vector< char * >::type MemoryPoolVec
ArrayVector3 *RESTRICT_ALIAS mPosition
Stores the position/translation of a node relative to its parent.
Definition: OgreTransform.h:49
bool *RESTRICT_ALIAS mInheritScale
Stores whether this node inherits scale from it's parent.
Definition: OgreTransform.h:75
Cache-friendly array of Quaternion represented as a SoA array.
void advancePack(size_t numAdvance)
Class representing a general-purpose node an articulated scene graph.
Definition: OgreNode.h:58
ArrayQuaternion *RESTRICT_ALIAS mDerivedOrientation
Caches the combined orientation from all parent nodes.
Definition: OgreTransform.h:61