diff options
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorFlyCircle.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorFlyCircle.cpp | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorFlyCircle.cpp b/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorFlyCircle.cpp new file mode 100644 index 0000000..dc887fa --- /dev/null +++ b/libraries/irrlicht-1.8/source/Irrlicht/CSceneNodeAnimatorFlyCircle.cpp | |||
@@ -0,0 +1,100 @@ | |||
1 | // Copyright (C) 2002-2012 Nikolaus Gebhardt | ||
2 | // This file is part of the "Irrlicht Engine". | ||
3 | // For conditions of distribution and use, see copyright notice in irrlicht.h | ||
4 | |||
5 | #include "CSceneNodeAnimatorFlyCircle.h" | ||
6 | |||
7 | namespace irr | ||
8 | { | ||
9 | namespace scene | ||
10 | { | ||
11 | |||
12 | |||
13 | //! constructor | ||
14 | CSceneNodeAnimatorFlyCircle::CSceneNodeAnimatorFlyCircle(u32 time, | ||
15 | const core::vector3df& center, f32 radius, f32 speed, | ||
16 | const core::vector3df& direction, f32 radiusEllipsoid) | ||
17 | : Center(center), Direction(direction), Radius(radius), | ||
18 | RadiusEllipsoid(radiusEllipsoid), Speed(speed), StartTime(time) | ||
19 | { | ||
20 | #ifdef _DEBUG | ||
21 | setDebugName("CSceneNodeAnimatorFlyCircle"); | ||
22 | #endif | ||
23 | init(); | ||
24 | } | ||
25 | |||
26 | |||
27 | void CSceneNodeAnimatorFlyCircle::init() | ||
28 | { | ||
29 | Direction.normalize(); | ||
30 | |||
31 | if (Direction.Y != 0) | ||
32 | VecV = core::vector3df(50,0,0).crossProduct(Direction).normalize(); | ||
33 | else | ||
34 | VecV = core::vector3df(0,50,0).crossProduct(Direction).normalize(); | ||
35 | VecU = VecV.crossProduct(Direction).normalize(); | ||
36 | } | ||
37 | |||
38 | |||
39 | //! animates a scene node | ||
40 | void CSceneNodeAnimatorFlyCircle::animateNode(ISceneNode* node, u32 timeMs) | ||
41 | { | ||
42 | if ( 0 == node ) | ||
43 | return; | ||
44 | |||
45 | f32 time; | ||
46 | |||
47 | // Check for the condition where the StartTime is in the future. | ||
48 | if(StartTime > timeMs) | ||
49 | time = ((s32)timeMs - (s32)StartTime) * Speed; | ||
50 | else | ||
51 | time = (timeMs-StartTime) * Speed; | ||
52 | |||
53 | // node->setPosition(Center + Radius * ((VecU*cosf(time)) + (VecV*sinf(time)))); | ||
54 | f32 r2 = RadiusEllipsoid == 0.f ? Radius : RadiusEllipsoid; | ||
55 | node->setPosition(Center + (Radius*cosf(time)*VecU) + (r2*sinf(time)*VecV ) ); | ||
56 | } | ||
57 | |||
58 | |||
59 | //! Writes attributes of the scene node animator. | ||
60 | void CSceneNodeAnimatorFlyCircle::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const | ||
61 | { | ||
62 | out->addVector3d("Center", Center); | ||
63 | out->addFloat("Radius", Radius); | ||
64 | out->addFloat("Speed", Speed); | ||
65 | out->addVector3d("Direction", Direction); | ||
66 | out->addFloat("RadiusEllipsoid", RadiusEllipsoid); | ||
67 | } | ||
68 | |||
69 | |||
70 | //! Reads attributes of the scene node animator. | ||
71 | void CSceneNodeAnimatorFlyCircle::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) | ||
72 | { | ||
73 | Center = in->getAttributeAsVector3d("Center"); | ||
74 | Radius = in->getAttributeAsFloat("Radius"); | ||
75 | Speed = in->getAttributeAsFloat("Speed"); | ||
76 | Direction = in->getAttributeAsVector3d("Direction"); | ||
77 | StartTime = 0; | ||
78 | |||
79 | if (Direction.equals(core::vector3df(0,0,0))) | ||
80 | Direction.set(0,1,0); // irrlicht 1.1 backwards compatibility | ||
81 | else | ||
82 | Direction.normalize(); | ||
83 | |||
84 | RadiusEllipsoid = in->getAttributeAsFloat("RadiusEllipsoid"); | ||
85 | init(); | ||
86 | } | ||
87 | |||
88 | |||
89 | ISceneNodeAnimator* CSceneNodeAnimatorFlyCircle::createClone(ISceneNode* node, ISceneManager* newManager) | ||
90 | { | ||
91 | CSceneNodeAnimatorFlyCircle * newAnimator = | ||
92 | new CSceneNodeAnimatorFlyCircle(StartTime, Center, Radius, Speed, Direction, RadiusEllipsoid); | ||
93 | |||
94 | return newAnimator; | ||
95 | } | ||
96 | |||
97 | |||
98 | } // end namespace scene | ||
99 | } // end namespace irr | ||
100 | |||