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