1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | // created: 2012/08/21
|
---|
6 | // filename: AnimPoursuite.cpp
|
---|
7 | //
|
---|
8 | // author: Guillaume Sanahuja
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: classe definissant une animation poursuite pour camera
|
---|
14 | //
|
---|
15 | /*********************************************************************/
|
---|
16 | #ifdef GL
|
---|
17 |
|
---|
18 | #include "AnimPoursuite.h"
|
---|
19 | #include "Simulator.h"
|
---|
20 | #include "Model.h"
|
---|
21 | #include "Model_impl.h"
|
---|
22 | #include <ICursorControl.h>
|
---|
23 | #include <ICameraSceneNode.h>
|
---|
24 |
|
---|
25 | using namespace irr;
|
---|
26 | using namespace gui;
|
---|
27 | using namespace core;
|
---|
28 | using namespace scene;
|
---|
29 |
|
---|
30 | namespace flair
|
---|
31 | {
|
---|
32 | namespace simulator
|
---|
33 | {
|
---|
34 |
|
---|
35 | AnimPoursuite::AnimPoursuite(const ISceneNode* parent,float rotateSpeed , float zoomSpeed )
|
---|
36 | {
|
---|
37 | this->parent=parent;
|
---|
38 | this->zoomSpeed=zoomSpeed;
|
---|
39 | this->rotateSpeed=rotateSpeed;
|
---|
40 | currentZoom=100;
|
---|
41 | RotY=20;
|
---|
42 | RotZ=0;
|
---|
43 | Rotating=false;
|
---|
44 | LMouseKey= false;
|
---|
45 | }
|
---|
46 |
|
---|
47 | AnimPoursuite::~AnimPoursuite()
|
---|
48 | {
|
---|
49 |
|
---|
50 | }
|
---|
51 |
|
---|
52 | void AnimPoursuite::setPositionOffset(vector3df newpos)
|
---|
53 | {
|
---|
54 | pos_offset=newpos;
|
---|
55 | }
|
---|
56 |
|
---|
57 | void AnimPoursuite::setTargetOffset(vector3df newpos)
|
---|
58 | {
|
---|
59 | target_offset=newpos;
|
---|
60 | }
|
---|
61 |
|
---|
62 | float AnimPoursuite::sat(float value)
|
---|
63 | {
|
---|
64 | if(value>89) value=89;
|
---|
65 | if(value<-89) value=-89;
|
---|
66 | return value;
|
---|
67 | }
|
---|
68 |
|
---|
69 | void AnimPoursuite::animateNode(ISceneNode* node, u32 timeMs)
|
---|
70 | {
|
---|
71 | ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node);
|
---|
72 | vector3df pos;
|
---|
73 |
|
---|
74 | float nRotY = RotY;
|
---|
75 | float nRotZ = RotZ;
|
---|
76 |
|
---|
77 | if (LMouseKey==true)
|
---|
78 | {
|
---|
79 | if (!Rotating)
|
---|
80 | {
|
---|
81 | RotateStart = MousePos;
|
---|
82 | Rotating = true;
|
---|
83 | nRotY = RotY;
|
---|
84 | nRotZ = RotZ;
|
---|
85 | }
|
---|
86 | else
|
---|
87 | {
|
---|
88 | nRotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
|
---|
89 | nRotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
|
---|
90 | nRotY=sat(nRotY);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | else if (Rotating)
|
---|
94 | {
|
---|
95 | RotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
|
---|
96 | RotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
|
---|
97 | RotY=sat(RotY);
|
---|
98 | nRotY = RotY;
|
---|
99 | nRotZ = RotZ;
|
---|
100 | Rotating = false;
|
---|
101 | }
|
---|
102 |
|
---|
103 | pos.X = -currentZoom;
|
---|
104 | pos.Y=0;
|
---|
105 | pos.Z=0;
|
---|
106 |
|
---|
107 | pos.rotateXZBy(-nRotY);
|
---|
108 | pos.rotateXYBy(getSimulator()->Yaw()+nRotZ+parent->getRotation().Z);
|
---|
109 |
|
---|
110 | camera->setPosition(parent->getPosition()+pos+pos_offset);
|
---|
111 | camera->setTarget(parent->getPosition()+target_offset);
|
---|
112 | }
|
---|
113 |
|
---|
114 | ISceneNodeAnimator* AnimPoursuite::createClone(ISceneNode* node,
|
---|
115 | ISceneManager* newManager)
|
---|
116 | {
|
---|
117 | return NULL;
|
---|
118 | }
|
---|
119 |
|
---|
120 | bool AnimPoursuite::MouseMoved(const SEvent& event,irr::core::position2df MousePos)
|
---|
121 | {
|
---|
122 | if (event.EventType != EET_MOUSE_INPUT_EVENT)
|
---|
123 | return false;
|
---|
124 |
|
---|
125 | switch(event.MouseInput.Event)
|
---|
126 | {
|
---|
127 |
|
---|
128 | case EMIE_MOUSE_WHEEL:
|
---|
129 | currentZoom -= event.MouseInput.Wheel * zoomSpeed;
|
---|
130 | if(currentZoom<=0) currentZoom=zoomSpeed;
|
---|
131 | break;
|
---|
132 | case EMIE_LMOUSE_PRESSED_DOWN:
|
---|
133 | LMouseKey = true;
|
---|
134 | break;
|
---|
135 | case EMIE_LMOUSE_LEFT_UP:
|
---|
136 | LMouseKey= false;
|
---|
137 | break;
|
---|
138 | case EMIE_MOUSE_MOVED:
|
---|
139 | this->MousePos = MousePos;
|
---|
140 | break;
|
---|
141 | default:
|
---|
142 | return false;
|
---|
143 | break;
|
---|
144 | }
|
---|
145 |
|
---|
146 | return true;
|
---|
147 | }
|
---|
148 |
|
---|
149 | } // end namespace simulator
|
---|
150 | } // end namespace flair
|
---|
151 |
|
---|
152 | #endif //GL
|
---|