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

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

draw vrpn axis in simulator

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 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 float newCurrentZoom= 100+currentZoom * zoomSpeed;
89 if (newCurrentZoom <= 0) {
90 newCurrentZoom =zoomSpeed;
91 currentZoom =1-100/zoomSpeed;
92 }
93
94 vector3df pos;
95 pos.X = -newCurrentZoom;
96 pos.Y = 0;
97 pos.Z = 0;
98
99 pos.rotateXZBy(-nRotY);
100 pos.rotateXYBy(getSimulator()->Yaw() + nRotZ + parent->getRotation().Z);
101
102 camera->setPosition(parent->getPosition() + pos + pos_offset);
103 camera->setTarget(parent->getPosition() + target_offset);
104}
105
106
107} // end namespace simulator
108} // end namespace flair
109
110#endif // GL
Note: See TracBrowser for help on using the repository browser.