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