- Timestamp:
- 10/29/08 10:19:11 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/MotionPath.cpp
r2953 r3078 1 1 #include "MotionPath.h" 2 #include "Matrix4x4.h" 2 3 3 4 … … 7 8 8 9 MotionPath::MotionPath(const VertexArray &vertices): 9 mVertices(vertices), mCurrentVertexIdx(0) 10 mVertices(vertices), mCurrentVertexIdx(0), mT(.0f) 10 11 { 11 12 } … … 14 15 void MotionPath::Move(float velocity) 15 16 { 17 mT += velocity; 18 19 if (mT >= 1.0f) 20 { 21 mCurrentVertexIdx = (mCurrentVertexIdx + 1) % (int)mVertices.size(); 22 mT -= 1.0f; 23 } 16 24 } 17 25 … … 19 27 Vector3 MotionPath::GetCurrentPosition() const 20 28 { 21 return mT * mVertices[mCurrentVertexIdx] + (1.0f - mT)* mVertices[(mCurrentVertexIdx + 1) % mVertices.size()];29 return (1.0f - mT) * mVertices[mCurrentVertexIdx] + mT * mVertices[(mCurrentVertexIdx + 1) % mVertices.size()]; 22 30 } 23 31 … … 32 40 { 33 41 mCurrentVertexIdx = 0; 42 mT = 0; 43 } 44 45 46 Matrix4x4 MotionPath::GetOrientation() 47 { 48 Vector3 dir = mVertices[(mCurrentVertexIdx + 1) % mVertices.size()] - mVertices[mCurrentVertexIdx]; 49 Vector3 ndir = -Normalize(dir); 50 51 float pitch = -atan2(ndir.x, ndir.y); 52 float yaw = atan2(ndir.z, sqrt((ndir.x * ndir.x) + (ndir.y * ndir.y))); 53 54 55 Matrix4x4 roty = RotationYMatrix(pitch); 56 Matrix4x4 rotx = RotationXMatrix(yaw); 57 58 return roty * rotx; 34 59 } 35 60
Note: See TracChangeset
for help on using the changeset viewer.