T3DTransform.h
Engine/source/T3D/sceneComponent/T3DTransform.h
Classes:
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _T3DTRANSFORM_H_ 25#define _T3DTRANSFORM_H_ 26 27#include "ts/tsShapeInstance.h" 28#include "math/mMatrix.h" 29 30//--------------------------------------------------------- 31// T3DTransform 32//--------------------------------------------------------- 33 34class Transform3D 35{ 36public: 37 38 class IDirtyListener 39 { 40 public: 41 virtual void onTransformDirty() = 0; 42 }; 43 44 // local/object/world matrix access 45 46 void setWorldMatrix(const MatrixF & world); 47 void setObjectMatrix(const MatrixF & objMatrix); 48 virtual void setLocalMatrix(const MatrixF & localMatrix) = 0; 49 50 virtual void getWorldMatrix(MatrixF & worldMatrix, bool includeLocalScale) const = 0; 51 virtual void getObjectMatrix(MatrixF & objectMatrix, bool includeLocalScale) const = 0; 52 virtual void getLocalMatrix(MatrixF & localMatrix, bool includeLocalScale) const = 0; 53 54 MatrixF getWorldMatrix() const 55 { 56 MatrixF world; 57 getWorldMatrix(world, true); 58 return world; 59 } 60 61 MatrixF getObjectMatrix() const 62 { 63 MatrixF objMatrix; 64 getObjectMatrix(objMatrix, true); 65 return objMatrix; 66 } 67 68 MatrixF getLocalMatrix() const 69 { 70 MatrixF loc; 71 getLocalMatrix(loc, true); 72 return loc; 73 } 74 75 // local position/rotation/scale 76 77 virtual Point3F getPosition() const = 0; 78 virtual void setPosition(const Point3F & position) = 0; 79 80 virtual QuatF getRotation() const = 0; 81 virtual void setRotation(const QuatF & rotation) = 0; 82 83 virtual Point3F getScale() const = 0; 84 virtual void setScale(const Point3F & scale) = 0; 85 86 // scale tests 87 88 bool hasLocalScale() const 89 { 90 return (_flags & Transform3D::LocalHasScale) != Transform3D::None; 91 } 92 93 bool hasObjectScale() const; 94 bool hasWorldScale() const; 95 96 // parent/child methods 97 98 Transform3D * getParentTransform() const 99 { 100 return _parentTransform; 101 } 102 103 void setParentTransform(Transform3D * parent); 104 105 IDirtyListener * getDirtyListener() const 106 { 107 return _dirtyListener; 108 } 109 110 void setDirtyListener(IDirtyListener * dirtyListener) 111 { 112 _dirtyListener = dirtyListener; 113 } 114 115 bool isChildOf(Transform3D * parent, bool recursive) const; 116 117protected: 118 119 enum TransformFlags 120 { 121 None = 0, 122 LocalHasScale = 1 << 0, 123 LocalPositionDirty = 1 << 1, 124 LocalRotationDirty = 1 << 2, 125 LocalScaleDirty = 1 << 3, 126 LocalDirty = LocalPositionDirty | LocalRotationDirty | LocalScaleDirty, 127 ParentDirty = 1 << 4, 128 LastFlag = 1 << 4 129 }; 130 131 Transform3D * _parentTransform; 132 IDirtyListener * _dirtyListener; 133 U32 _flags; 134}; 135 136//--------------------------------------------------------- 137// Transform3DInPlace 138//--------------------------------------------------------- 139 140class Transform3DInPlace : public Transform3D 141{ 142public: 143 144 Transform3DInPlace() : _position(0,0,0), _rotation(0,0,0,1), _scale(1,1,1) 145 { 146 } 147 148 Point3F getPosition() const; 149 void setPosition(const Point3F & position); 150 151 QuatF getRotation() const; 152 void setRotation(const QuatF & rotation); 153 154 Point3F getScale() const; 155 void setScale(const Point3F & scale); 156 157 void getWorldMatrix(MatrixF & worldMat, bool includeLocalScale) const; 158 void getObjectMatrix(MatrixF & objectMat, bool includeLocalScale) const; 159 void getLocalMatrix(MatrixF & localMat, bool includeLocalScale) const; 160 void setLocalMatrix(const MatrixF & localMat); 161 162protected: 163 164 Point3F _position; 165 QuatF _rotation; 166 Point3F _scale; 167}; 168 169//--------------------------------------------------------- 170// TSTransform3D 171//--------------------------------------------------------- 172 173class TSTransform3D : public Transform3D, public TSCallback 174{ 175public: 176 TSTransform3D(TSShapeInstance * si, S32 nodeIndex); 177 178 Point3F getPosition() const; 179 void setPosition(const Point3F & position); 180 181 QuatF getRotation() const; 182 void setRotation(const QuatF & rotation); 183 184 Point3F getScale() const; 185 void setScale(const Point3F & scale); 186 187 void getWorldMatrix(MatrixF & worldMat, bool includeLocalScale) const; 188 void getObjectMatrix(MatrixF & objectMat, bool includeLocalScale) const; 189 void getLocalMatrix(MatrixF & localMat, bool includeLocalScale) const; 190 void setLocalMatrix(const MatrixF & localMatrix); 191 192 // Define TSCallback interface 193 void setNodeTransform(TSShapeInstance * si, S32 nodeIndex, MatrixF & localTransform); 194 195protected: 196 197 enum TSTransformFlags 198 { 199 HandleLocal = Transform3D::LastFlag << 1, 200 LastFlag = Transform3D::LastFlag << 1 201 }; 202 203 bool doHandleLocal() const 204 { 205 return (_flags & (TransformFlags)TSTransform3D::HandleLocal) != Transform3D::None; 206 } 207 208 void setHandleLocal(bool handleLocal); 209 MatrixF & getTSLocal(MatrixF & mat) const; 210 211 TSShapeInstance * _shapeInstance; 212 int _nodeIndex; 213 214 Point3F _position; 215 QuatF _rotation; 216 Point3F _scale; 217}; 218 219#endif // _T3DTRANSFORM_H_ 220