source: flair-src/trunk/lib/FlairSimulator/src/FollowMeCamera.cpp@ 178

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

simu cameras

File size: 2.6 KB
Line 
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: FollowMeCamera.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 "FollowMeCamera.h"
19#include "Simulator.h"
20#include "Model.h"
21#include "Model_impl.h"
22#include "Gui.h"
23#include <ICursorControl.h>
24#include <ICameraSceneNode.h>
25#include <IrrlichtDevice.h>
26#include <ISceneManager.h>
27
28using namespace irr;
29using namespace gui;
30using namespace core;
31using namespace scene;
32
33namespace flair {
34namespace simulator {
35
36FollowMeCamera::FollowMeCamera(const ISceneNode *parent, std::string name,float inRotateSpeed,
37 float inZoomSpeed):VisualizationCamera(name) {
38 this->parent = parent;
39 rotateSpeed=inRotateSpeed;
40 zoomSpeed=inZoomSpeed;
41 RotY = 20;
42 RotZ = 0;
43 Rotating = false;
44}
45
46FollowMeCamera::~FollowMeCamera() {}
47
48void FollowMeCamera::setPositionOffset(vector3df newpos) {
49 pos_offset = ToIrrlichtCoordinates(newpos);
50}
51
52void FollowMeCamera::setTargetOffset(vector3df newpos) {
53 target_offset = ToIrrlichtCoordinates(newpos);
54}
55
56float FollowMeCamera::sat(float value) {
57 if (value > 89)
58 value = 89;
59 if (value < -89)
60 value = -89;
61 return value;
62}
63
64void FollowMeCamera::animateNode(ISceneNode *node, u32 timeMs) {
65
66 float nRotY = RotY;
67 float nRotZ = RotZ;
68
69 if (LMouseKey == true) {
70 if (!Rotating) {
71 RotateStart = MousePos;
72 Rotating = true;
73 nRotY = RotY;
74 nRotZ = RotZ;
75 } else {
76 nRotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
77 nRotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
78 nRotY = sat(nRotY);
79 }
80 } else if (Rotating) {
81 RotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
82 RotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
83 RotY = sat(RotY);
84 nRotY = RotY;
85 nRotZ = RotZ;
86 Rotating = false;
87 }
88
89 float newCurrentZoom= 100+currentZoom * zoomSpeed;
90 if (newCurrentZoom <= 0) {
91 newCurrentZoom =zoomSpeed;
92 currentZoom =1-100/zoomSpeed;
93 }
94
95 vector3df pos;
96 pos.X = -newCurrentZoom;
97 pos.Y = 0;
98 pos.Z = 0;
99
100 pos.rotateXZBy(-nRotY);
101 pos.rotateXYBy(getSimulator()->Yaw() + nRotZ + parent->getRotation().Z);
102
103 camera->setPosition(parent->getPosition() + pos + pos_offset);
104 camera->setTarget(parent->getPosition() + target_offset);
105}
106
107
108} // end namespace simulator
109} // end namespace flair
110
111#endif // GL
Note: See TracBrowser for help on using the repository browser.