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 | using namespace irr;
|
---|
30 | using namespace gui;
|
---|
31 | using namespace core;
|
---|
32 | using namespace scene;
|
---|
33 |
|
---|
34 | namespace flair {
|
---|
35 | namespace simulator {
|
---|
36 |
|
---|
37 | FixedCamera::FixedCamera(std::string name,core::Vector3D position,float inRotateSpeed,float inZoomSpeed):VisualizationCamera(name) {
|
---|
38 | RotY = -90;
|
---|
39 | RotZ = 0;
|
---|
40 | Rotating = false;
|
---|
41 | rotateSpeed=inRotateSpeed;
|
---|
42 | zoomSpeed=inZoomSpeed;
|
---|
43 | camera->setPosition(vector3df(ToIrrlichtCoordinates(position)));
|
---|
44 | fov=camera->getFOV();
|
---|
45 | }
|
---|
46 |
|
---|
47 | FixedCamera::~FixedCamera() {}
|
---|
48 |
|
---|
49 | float FixedCamera::sat(float value) {
|
---|
50 | if (value >= -1)
|
---|
51 | value = -1;
|
---|
52 | if (value <= -179)
|
---|
53 | value = -179;
|
---|
54 | return value;
|
---|
55 | }
|
---|
56 |
|
---|
57 | void FixedCamera::animateNode(ISceneNode *node, u32 timeMs) {
|
---|
58 | ICameraSceneNode *camera = static_cast<ICameraSceneNode *>(node);
|
---|
59 |
|
---|
60 | float nRotY = RotY;
|
---|
61 | float nRotZ = RotZ;
|
---|
62 |
|
---|
63 | if (LMouseKey == true) {
|
---|
64 | if (!Rotating) {
|
---|
65 | RotateStart = MousePos;
|
---|
66 | Rotating = true;
|
---|
67 | nRotY = RotY;
|
---|
68 | nRotZ = RotZ;
|
---|
69 | } else {
|
---|
70 | nRotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
|
---|
71 | nRotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
|
---|
72 | nRotY = sat(nRotY);
|
---|
73 | }
|
---|
74 | } else if (Rotating) {
|
---|
75 | RotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
|
---|
76 | RotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
|
---|
77 | RotY = sat(RotY);
|
---|
78 | nRotY = RotY;
|
---|
79 | nRotZ = RotZ;
|
---|
80 | Rotating = false;
|
---|
81 | }
|
---|
82 |
|
---|
83 | float newFov=fov+currentZoom*zoomSpeed;
|
---|
84 | if(newFov>fov) {
|
---|
85 | newFov=fov;
|
---|
86 | currentZoom=0;
|
---|
87 | }
|
---|
88 | if(newFov<0) {
|
---|
89 | newFov=zoomSpeed;
|
---|
90 | currentZoom=1-fov/zoomSpeed;
|
---|
91 | }
|
---|
92 |
|
---|
93 | camera->setRotation(vector3df(0,nRotY,nRotZ));
|
---|
94 | camera->bindTargetAndRotation(true);
|
---|
95 | camera->setFOV(newFov);
|
---|
96 | }
|
---|
97 |
|
---|
98 |
|
---|
99 | } // end namespace simulator
|
---|
100 | } // end namespace flair
|
---|
101 |
|
---|
102 | #endif // GL
|
---|