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 | namespace simulator {
|
---|
32 |
|
---|
33 | AnimPoursuite::AnimPoursuite(const ISceneNode *parent, float rotateSpeed,
|
---|
34 | float zoomSpeed) {
|
---|
35 | this->parent = parent;
|
---|
36 | this->zoomSpeed = zoomSpeed;
|
---|
37 | this->rotateSpeed = rotateSpeed;
|
---|
38 | currentZoom = 100;
|
---|
39 | RotY = 20;
|
---|
40 | RotZ = 0;
|
---|
41 | Rotating = false;
|
---|
42 | LMouseKey = false;
|
---|
43 | }
|
---|
44 |
|
---|
45 | AnimPoursuite::~AnimPoursuite() {}
|
---|
46 |
|
---|
47 | void AnimPoursuite::setPositionOffset(vector3df newpos) { pos_offset = newpos; }
|
---|
48 |
|
---|
49 | void AnimPoursuite::setTargetOffset(vector3df newpos) {
|
---|
50 | target_offset = newpos;
|
---|
51 | }
|
---|
52 |
|
---|
53 | float AnimPoursuite::sat(float value) {
|
---|
54 | if (value > 89)
|
---|
55 | value = 89;
|
---|
56 | if (value < -89)
|
---|
57 | value = -89;
|
---|
58 | return value;
|
---|
59 | }
|
---|
60 |
|
---|
61 | void AnimPoursuite::animateNode(ISceneNode *node, u32 timeMs) {
|
---|
62 | ICameraSceneNode *camera = static_cast<ICameraSceneNode *>(node);
|
---|
63 | vector3df pos;
|
---|
64 |
|
---|
65 | float nRotY = RotY;
|
---|
66 | float nRotZ = RotZ;
|
---|
67 |
|
---|
68 | if (LMouseKey == true) {
|
---|
69 | if (!Rotating) {
|
---|
70 | RotateStart = MousePos;
|
---|
71 | Rotating = true;
|
---|
72 | nRotY = RotY;
|
---|
73 | nRotZ = RotZ;
|
---|
74 | } else {
|
---|
75 | nRotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
|
---|
76 | nRotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
|
---|
77 | nRotY = sat(nRotY);
|
---|
78 | }
|
---|
79 | } else if (Rotating) {
|
---|
80 | RotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
|
---|
81 | RotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
|
---|
82 | RotY = sat(RotY);
|
---|
83 | nRotY = RotY;
|
---|
84 | nRotZ = RotZ;
|
---|
85 | Rotating = false;
|
---|
86 | }
|
---|
87 |
|
---|
88 | pos.X = -currentZoom;
|
---|
89 | pos.Y = 0;
|
---|
90 | pos.Z = 0;
|
---|
91 |
|
---|
92 | pos.rotateXZBy(-nRotY);
|
---|
93 | pos.rotateXYBy(getSimulator()->Yaw() + nRotZ + parent->getRotation().Z);
|
---|
94 |
|
---|
95 | camera->setPosition(parent->getPosition() + pos + pos_offset);
|
---|
96 | camera->setTarget(parent->getPosition() + target_offset);
|
---|
97 | }
|
---|
98 |
|
---|
99 | ISceneNodeAnimator *AnimPoursuite::createClone(ISceneNode *node,
|
---|
100 | ISceneManager *newManager) {
|
---|
101 | return NULL;
|
---|
102 | }
|
---|
103 |
|
---|
104 | bool AnimPoursuite::MouseMoved(const SEvent &event,
|
---|
105 | irr::core::position2df MousePos) {
|
---|
106 | if (event.EventType != EET_MOUSE_INPUT_EVENT)
|
---|
107 | return false;
|
---|
108 |
|
---|
109 | switch (event.MouseInput.Event) {
|
---|
110 |
|
---|
111 | case EMIE_MOUSE_WHEEL:
|
---|
112 | currentZoom -= event.MouseInput.Wheel * zoomSpeed;
|
---|
113 | if (currentZoom <= 0)
|
---|
114 | currentZoom = zoomSpeed;
|
---|
115 | break;
|
---|
116 | case EMIE_LMOUSE_PRESSED_DOWN:
|
---|
117 | LMouseKey = true;
|
---|
118 | break;
|
---|
119 | case EMIE_LMOUSE_LEFT_UP:
|
---|
120 | LMouseKey = false;
|
---|
121 | break;
|
---|
122 | case EMIE_MOUSE_MOVED:
|
---|
123 | this->MousePos = MousePos;
|
---|
124 | break;
|
---|
125 | default:
|
---|
126 | return false;
|
---|
127 | break;
|
---|
128 | }
|
---|
129 |
|
---|
130 | return true;
|
---|
131 | }
|
---|
132 |
|
---|
133 | } // end namespace simulator
|
---|
134 | } // end namespace flair
|
---|
135 |
|
---|
136 | #endif // GL
|
---|