source: flair-src/trunk/lib/FlairSimulator/src/AnimPoursuite.cpp@ 8

Last change on this file since 8 was 8, checked in by Sanahuja Guillaume, 6 years ago

simulator

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