source: flair-src/trunk/lib/FlairSimulator/src/FixedCamera.cpp@ 118

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

m

File size: 3.5 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: 2016/09/01
6// filename: FixedCamera.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: class for a fixed camera in the gui
14//
15/*********************************************************************/
16#ifdef GL
17
18#include "FixedCamera.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#include <Euler.h>
28
29using namespace irr;
30using namespace gui;
31using namespace core;
32using namespace scene;
33
34namespace flair {
35namespace simulator {
36
37FixedCamera::FixedCamera(std::string name,core::Vector3D position,core::Vector3D lookat,float inRotateSpeed,float inZoomSpeed):VisualizationCamera(name) {
38 Rotating = false;
39 rotateSpeed=inRotateSpeed;
40 zoomSpeed=inZoomSpeed;
41
42 camera->bindTargetAndRotation(true);
43 camera->setPosition(vector3df(ToIrrlichtCoordinates(position)));
44 camera->setTarget(vector3df(ToIrrlichtCoordinates(lookat)));
45 target=vector3df(ToIrrlichtCoordinates(lookat));
46 init=false;
47 rotation=camera->getRotation();
48 printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);
49 fov=camera->getFOV();
50}
51
52FixedCamera::~FixedCamera() {}
53
54float FixedCamera::sat(float value) {
55 if (value >= -1)
56 value = -1;
57 if (value <= -179)
58 value = -179;
59 return value;
60}
61
62void FixedCamera::animateNode(ISceneNode *node, u32 timeMs) {
63 ICameraSceneNode *camera = static_cast<ICameraSceneNode *>(node);
64 vector3df newRotation=rotation;
65 vector3df newTarget=target;
66
67if(init==false) {
68 rotation=camera->getRotation();
69 printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);
70 init=true;
71}
72 float nRotY = 0;//rotation.Y;
73 float nRotZ = rotation.Z;
74
75 if (LMouseKey == true) {
76 if (!Rotating) {
77 RotateStart = MousePos;
78 Rotating = true;
79 //nRotY = rotation.Y;
80 //nRotZ =0;// rotation.Z;
81 } else {
82 nRotY = (RotateStart.Y - MousePos.Y) * rotateSpeed;
83 nRotZ = (RotateStart.X - MousePos.X) * rotateSpeed;
84 newRotation.rotateXZBy(-nRotY);
85 //nRotY = sat(nRotY);
86
87 //newTarget.rotateXZBy(-nRotY,camera->getPosition());
88 newTarget.rotateXYBy( nRotZ,camera->getPosition());
89 camera->setTarget(newTarget);
90 }
91 } else if (Rotating) {
92 //rotation.Y += (RotateStart.Y - MousePos.Y) * rotateSpeed;
93 //rotation.Z += (RotateStart.X - MousePos.X) * rotateSpeed;
94 //rotation.Y = sat(rotation.Y);
95 //nRotY = rotation.Y;
96 //nRotZ = rotation.Z;
97 Rotating = false;
98 target=camera->getTarget();
99 rotation=camera->getRotation();
100 printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);
101 }
102
103 float newFov=fov+currentZoom*zoomSpeed;
104 if(newFov>fov) {
105 newFov=fov;
106 currentZoom=0;
107 }
108 if(newFov<0) {
109 newFov=zoomSpeed;
110 currentZoom=1-fov/zoomSpeed;
111 }
112
113//newTarget.rotateXZBy(-nRotY,camera->getPosition());
114// newTarget.rotateXYBy( nRotZ,camera->getPosition());
115
116 //camera->setRotation(vector3df(rotation.X,-180-nRotY,nRotZ));
117 //camera->setRotation(vector3df(rotation.X,nRotY,0));
118 //camera->bindTargetAndRotation(true);
119 // camera->setRotation(rotation);
120 // camera->setTarget(newTarget);
121 //rotation=camera->getRotation();
122 //printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);
123
124 camera->setFOV(newFov);
125}
126
127
128} // end namespace simulator
129} // end namespace flair
130
131#endif // GL
Note: See TracBrowser for help on using the repository browser.