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

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

modifs pour template vectors

File size: 2.9 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::Vector3Df position,core::Vector3Df 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
46 fov=camera->getFOV();
47}
48
49FixedCamera::~FixedCamera() {}
50
51void FixedCamera::animateNode(ISceneNode *node, u32 timeMs) {
52 ICameraSceneNode *camera = static_cast<ICameraSceneNode *>(node);
53
54 if (LMouseKey == true) {
55 if (!Rotating) {
56 RotateStart = MousePos;
57 Rotating = true;
58 target = (camera->getTarget() - camera->getAbsolutePosition());
59 } else {
60 float nRotY = (RotateStart.Y - MousePos.Y) * rotateSpeed;
61 float nRotZ = -(RotateStart.X - MousePos.X) * rotateSpeed;
62
63 //normal between target and up vector
64 cameraAxeY=target.crossProduct(vector3df(0,0,1));
65 cameraAxeY.normalize();
66
67 //rotation around z axis
68 irr::core::quaternion q1(target.X,target.Y,target.Z,0);
69 irr::core::quaternion q2;
70 q2.fromAngleAxis(nRotZ,vector3df(0,0,1));
71 irr::core::quaternion q3=q2*q1;
72 q2.makeInverse();
73 q3=q3*q2;
74
75 //rotation around cameraAxeY
76 q1.set(q3.X,q3.Y,q3.Z,0);
77 q2.fromAngleAxis(nRotY,cameraAxeY);
78 q3=q2*q1;
79 q2.makeInverse();
80 q3=q3*q2;
81
82 //check angle
83 vector3df newTarget(q3.X,q3.Y,q3.Z);
84 float angle=acos(newTarget.dotProduct(vector3df(0,0,1))/newTarget.getLength());
85 vector3df cross = newTarget.crossProduct(vector3df(0,0,1));
86 if (cross.dotProduct(cameraAxeY) > 0) {
87 newTarget += camera->getAbsolutePosition();
88 camera->setTarget(newTarget);
89 }
90 }
91 } else if (Rotating) {
92 Rotating = false;
93 }
94
95 //handle zoom
96 float newFov=fov+currentZoom*zoomSpeed;
97 if(newFov>fov) {
98 newFov=fov;
99 currentZoom=0;
100 }
101 if(newFov<0) {
102 newFov=zoomSpeed;
103 currentZoom=1-fov/zoomSpeed;
104 }
105 camera->setFOV(newFov);
106}
107
108
109} // end namespace simulator
110} // end namespace flair
111
112#endif // GL
Note: See TracBrowser for help on using the repository browser.