VInterpController.h
Engine/source/Verve/VActor/VInterpController.h
Classes:
class
Detailed Description
1 2//----------------------------------------------------------------------------- 3// Verve 4// Copyright (C) 2014 - Violent Tulip 5// 6// Permission is hereby granted, free of charge, to any person obtaining a copy 7// of this software and associated documentation files (the "Software"), to 8// deal in the Software without restriction, including without limitation the 9// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10// sell copies of the Software, and to permit persons to whom the Software is 11// furnished to do so, subject to the following conditions: 12// 13// The above copyright notice and this permission notice shall be included in 14// all copies or substantial portions of the Software. 15// 16// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22// IN THE SOFTWARE. 23//----------------------------------------------------------------------------- 24#ifndef _VT_VINTERPCONTROLLER_H_ 25#define _VT_VINTERPCONTROLLER_H_ 26 27#ifndef _MATH_H_ 28#include "math/mMath.h" 29#endif 30 31//----------------------------------------------------------------------------- 32 33class VInterpController 34{ 35protected: 36 37 Point3F mPosition[2]; 38 QuatF mRotation[2]; 39 40public: 41 42 //------------------------------------------------------------------------- 43 // Interpolation Methods. 44 //------------------------------------------------------------------------- 45 46 /// Get Position. 47 Point3F getPosition( const F32 &pDelta ) 48 { 49 // Interpolate Position. 50 Point3F interpPosition; 51 interpPosition.interpolate( mPosition[1], mPosition[0], pDelta ); 52 // Return Interpolated Point. 53 return interpPosition; 54 }; 55 56 /// Get Rotation. 57 QuatF getRotation( const F32 &pDelta ) 58 { 59 // Interpolate Rotation. 60 QuatF interpRotation; 61 interpRotation.interpolate( mRotation[1], mRotation[0], pDelta ); 62 // Return Interpolated Quat. 63 return interpRotation; 64 }; 65 66 /// Get Transform. 67 MatrixF getTransform( const F32 &pDelta ) 68 { 69 // Get Position. 70 const Point3F interpPosition = getPosition( pDelta ); 71 // Get Rotation. 72 const QuatF interpRotation = getRotation( pDelta ); 73 74 // Setup Matrix. 75 MatrixF transform; 76 interpRotation.setMatrix( &transform ); 77 // Set Position. 78 transform.setPosition( interpPosition ); 79 80 // Return Matrix. 81 return transform; 82 }; 83 84 //------------------------------------------------------------------------- 85 // Delta Methods. 86 //------------------------------------------------------------------------- 87 88 /// Reset Delta. 89 void resetDelta( const Point3F &pPosition, const QuatF &pRotation ) 90 { 91 mPosition[0] = mPosition[1] = pPosition; 92 mRotation[0] = mRotation[1] = pRotation; 93 }; 94 95 /// Reset Delta. 96 void resetDelta( const MatrixF &pMatrix ) 97 { 98 // Setup Quat. 99 QuatF rotationQuat( pMatrix ); 100 // Reset Delta. 101 resetDelta( pMatrix.getPosition(), rotationQuat ); 102 }; 103 104 /// Reset Delta (Vector) 105 void resetDelta( const Point3F &pPosition, const VectorF &pForwardVector ) 106 { 107 // Assert. 108 AssertFatal( pForwardVector.isUnitLength(), "VInterpController::resetDelta() - Forward Vector hasn't been Normalized." ); 109 110 // Static Up Vector. 111 static const VectorF sUpVector( 0.f, 0.f, 1.f ); 112 113 // X-Axis. 114 VectorF xVec = mCross( pForwardVector, sUpVector ); 115 xVec.normalize(); 116 // Z-Axis. 117 VectorF zVec = mCross( xVec, pForwardVector ); 118 zVec.normalize(); 119 120 // Setup Object Transform. 121 MatrixF transform; 122 transform.setColumn( 0, xVec ); 123 transform.setColumn( 1, pForwardVector ); 124 transform.setColumn( 2, zVec ); 125 transform.setColumn( 3, pPosition ); 126 127 // Reset Delta. 128 resetDelta( transform ); 129 }; 130 131 /// Reset Delta (AngAxis) 132 void resetDelta( const Point3F &pPosition, const AngAxisF &pAngAxis ) 133 { 134 // Setup Matrix. 135 MatrixF transform; 136 pAngAxis.setMatrix( &transform ); 137 // Set Position. 138 transform.setPosition( pPosition ); 139 140 // Reset Delta. 141 resetDelta( transform ); 142 }; 143 144 /// Push Delta. 145 void pushDelta( const Point3F &pPosition, const QuatF &pRotation ) 146 { 147 mPosition[1] = pPosition; 148 mRotation[1] = pRotation; 149 }; 150 151 /// Push Delta (Matrix) 152 void pushDelta( const MatrixF &pMatrix ) 153 { 154 // Setup Quat. 155 QuatF rotationQuat( pMatrix ); 156 // Push Delta. 157 pushDelta( pMatrix.getPosition(), rotationQuat ); 158 }; 159 160 /// Push Delta (Vector) 161 void pushDelta( const Point3F &pPosition, const VectorF &pForwardVector ) 162 { 163 // Assert. 164 AssertFatal( pForwardVector.isUnitLength(), "VInterpController::pushDelta() - Forward Vector hasn't been Normalized." ); 165 166 // Static Up Vector. 167 static const VectorF sUpVector( 0.f, 0.f, 1.f ); 168 169 // X-Axis. 170 VectorF xVec = mCross( pForwardVector, sUpVector ); 171 xVec.normalize(); 172 // Z-Axis. 173 VectorF zVec = mCross( xVec, pForwardVector ); 174 zVec.normalize(); 175 176 // Setup Object Transform. 177 MatrixF transform; 178 transform.setColumn( 0, xVec ); 179 transform.setColumn( 1, pForwardVector ); 180 transform.setColumn( 2, zVec ); 181 transform.setColumn( 3, pPosition ); 182 183 // Push Delta. 184 pushDelta( transform ); 185 }; 186 187 /// Push Delta (AngAxis) 188 void pushDelta( const Point3F &pPosition, const AngAxisF &pAngAxis ) 189 { 190 // Setup Matrix. 191 MatrixF transform; 192 pAngAxis.setMatrix( &transform ); 193 // Set Position. 194 transform.setPosition( pPosition ); 195 196 // Push Delta. 197 pushDelta( transform ); 198 }; 199 200 /// Pop Delta. 201 void popDelta( void ) 202 { 203 mPosition[0] = mPosition[1]; 204 mRotation[0] = mRotation[1]; 205 }; 206}; 207 208#endif // _VT_VINTERPCONTROLLER_H_ 209