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

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

m

File size: 3.5 KB
RevLine 
[69]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>
[70]27#include <Euler.h>
[69]28
29using namespace irr;
30using namespace gui;
31using namespace core;
32using namespace scene;
33
34namespace flair {
35namespace simulator {
36
[87]37FixedCamera::FixedCamera(std::string name,core::Vector3D position,core::Vector3D lookat,float inRotateSpeed,float inZoomSpeed):VisualizationCamera(name) {
[69]38 Rotating = false;
[70]39 rotateSpeed=inRotateSpeed;
40 zoomSpeed=inZoomSpeed;
[87]41
42 camera->bindTargetAndRotation(true);
[70]43 camera->setPosition(vector3df(ToIrrlichtCoordinates(position)));
[87]44 camera->setTarget(vector3df(ToIrrlichtCoordinates(lookat)));
[107]45 target=vector3df(ToIrrlichtCoordinates(lookat));
[87]46 init=false;
47 rotation=camera->getRotation();
48 printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);
[70]49 fov=camera->getFOV();
[69]50}
51
52FixedCamera::~FixedCamera() {}
53
[70]54float FixedCamera::sat(float value) {
55 if (value >= -1)
56 value = -1;
57 if (value <= -179)
58 value = -179;
59 return value;
60}
61
[69]62void FixedCamera::animateNode(ISceneNode *node, u32 timeMs) {
63 ICameraSceneNode *camera = static_cast<ICameraSceneNode *>(node);
[87]64 vector3df newRotation=rotation;
[107]65 vector3df newTarget=target;
[69]66
[87]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;
[69]74
75 if (LMouseKey == true) {
76 if (!Rotating) {
77 RotateStart = MousePos;
78 Rotating = true;
[87]79 //nRotY = rotation.Y;
[107]80 //nRotZ =0;// rotation.Z;
[69]81 } else {
[87]82 nRotY = (RotateStart.Y - MousePos.Y) * rotateSpeed;
[107]83 nRotZ = (RotateStart.X - MousePos.X) * rotateSpeed;
[87]84 newRotation.rotateXZBy(-nRotY);
85 //nRotY = sat(nRotY);
[107]86
87 //newTarget.rotateXZBy(-nRotY,camera->getPosition());
88 newTarget.rotateXYBy( nRotZ,camera->getPosition());
89 camera->setTarget(newTarget);
[69]90 }
91 } else if (Rotating) {
[87]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;
[107]96 //nRotZ = rotation.Z;
[69]97 Rotating = false;
[107]98 target=camera->getTarget();
99 rotation=camera->getRotation();
100 printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);
[69]101 }
102
[70]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
[107]113//newTarget.rotateXZBy(-nRotY,camera->getPosition());
114// newTarget.rotateXYBy( nRotZ,camera->getPosition());
[87]115
116 //camera->setRotation(vector3df(rotation.X,-180-nRotY,nRotZ));
117 //camera->setRotation(vector3df(rotation.X,nRotY,0));
118 //camera->bindTargetAndRotation(true);
[107]119 // camera->setRotation(rotation);
120 // camera->setTarget(newTarget);
[87]121 //rotation=camera->getRotation();
122 //printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);
123
[70]124 camera->setFOV(newFov);
[69]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.