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

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

working fixed cameras

File size: 3.0 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)));
[120]45
[70]46 fov=camera->getFOV();
[69]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;
[120]58 target = (camera->getTarget() - camera->getAbsolutePosition());
[69]59 } else {
[120]60 float nRotY = (RotateStart.Y - MousePos.Y) * rotateSpeed;
61 float nRotZ = -(RotateStart.X - MousePos.X) * rotateSpeed;
[107]62
[120]63 //normal between target and up vector
64 cameraAxeY=target.crossProduct(irr::core::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 irr::core::vector3df newTarget(q3.X,q3.Y,q3.Z);
84 float angle=acos(newTarget.dotProduct(irr::core::vector3df(0,0,1))/newTarget.getLength());
85 irr::core::vector3df cross = newTarget.crossProduct(irr::core::vector3df(0,0,1));
86 if (cross.dotProduct(cameraAxeY) > 0) {
87 newTarget += camera->getAbsolutePosition();
88 camera->setTarget(newTarget);
89 }
[69]90 }
91 } else if (Rotating) {
92 Rotating = false;
93 }
94
[120]95 //handle zoom
[70]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);
[69]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.