Rev | Line | |
---|
[2951] | 1 | #include "MotionPath.h"
|
---|
[3078] | 2 | #include "Matrix4x4.h"
|
---|
[2951] | 3 |
|
---|
| 4 |
|
---|
| 5 | namespace CHCDemoEngine
|
---|
| 6 | {
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | MotionPath::MotionPath(const VertexArray &vertices):
|
---|
[3078] | 10 | mVertices(vertices), mCurrentVertexIdx(0), mT(.0f)
|
---|
[2951] | 11 | {
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | void MotionPath::Move(float velocity)
|
---|
| 16 | {
|
---|
[3078] | 17 | mT += velocity;
|
---|
| 18 |
|
---|
| 19 | if (mT >= 1.0f)
|
---|
| 20 | {
|
---|
| 21 | mCurrentVertexIdx = (mCurrentVertexIdx + 1) % (int)mVertices.size();
|
---|
| 22 | mT -= 1.0f;
|
---|
| 23 | }
|
---|
[2951] | 24 | }
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | Vector3 MotionPath::GetCurrentPosition() const
|
---|
| 28 | {
|
---|
[3078] | 29 | return (1.0f - mT) * mVertices[mCurrentVertexIdx] + mT * mVertices[(mCurrentVertexIdx + 1) % mVertices.size()];
|
---|
[2951] | 30 | }
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | Vector3 MotionPath::GetCurrentDirection() const
|
---|
| 34 | {
|
---|
[2953] | 35 | return Vector3(1, 0, 0);
|
---|
[2951] | 36 | }
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | void MotionPath::Reset()
|
---|
| 40 | {
|
---|
| 41 | mCurrentVertexIdx = 0;
|
---|
[3078] | 42 | mT = 0;
|
---|
[2951] | 43 | }
|
---|
| 44 |
|
---|
| 45 |
|
---|
[3078] | 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;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
[2951] | 62 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.