[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 |
|
---|
| 29 | using namespace irr;
|
---|
| 30 | using namespace gui;
|
---|
| 31 | using namespace core;
|
---|
| 32 | using namespace scene;
|
---|
| 33 |
|
---|
| 34 | namespace flair {
|
---|
| 35 | namespace simulator {
|
---|
| 36 |
|
---|
[87] | 37 | FixedCamera::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)));
|
---|
| 45 | init=false;
|
---|
| 46 | rotation=camera->getRotation();
|
---|
| 47 | printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);
|
---|
[70] | 48 | fov=camera->getFOV();
|
---|
[69] | 49 | }
|
---|
| 50 |
|
---|
| 51 | FixedCamera::~FixedCamera() {}
|
---|
| 52 |
|
---|
[70] | 53 | float FixedCamera::sat(float value) {
|
---|
| 54 | if (value >= -1)
|
---|
| 55 | value = -1;
|
---|
| 56 | if (value <= -179)
|
---|
| 57 | value = -179;
|
---|
| 58 | return value;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[69] | 61 | void FixedCamera::animateNode(ISceneNode *node, u32 timeMs) {
|
---|
| 62 | ICameraSceneNode *camera = static_cast<ICameraSceneNode *>(node);
|
---|
[87] | 63 | vector3df newRotation=rotation;
|
---|
[69] | 64 |
|
---|
[87] | 65 | if(init==false) {
|
---|
| 66 | rotation=camera->getRotation();
|
---|
| 67 | printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);
|
---|
| 68 | init=true;
|
---|
| 69 | }
|
---|
| 70 | float nRotY = 0;//rotation.Y;
|
---|
| 71 | float nRotZ = rotation.Z;
|
---|
[69] | 72 |
|
---|
| 73 | if (LMouseKey == true) {
|
---|
| 74 | if (!Rotating) {
|
---|
| 75 | RotateStart = MousePos;
|
---|
| 76 | Rotating = true;
|
---|
[87] | 77 | //nRotY = rotation.Y;
|
---|
| 78 | nRotZ = rotation.Z;
|
---|
[69] | 79 | } else {
|
---|
[87] | 80 | nRotY = (RotateStart.Y - MousePos.Y) * rotateSpeed;
|
---|
[69] | 81 | nRotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
|
---|
[87] | 82 | newRotation.rotateXZBy(-nRotY);
|
---|
| 83 | //nRotY = sat(nRotY);
|
---|
[69] | 84 | }
|
---|
| 85 | } else if (Rotating) {
|
---|
[87] | 86 | //rotation.Y += (RotateStart.Y - MousePos.Y) * rotateSpeed;
|
---|
| 87 | //rotation.Z += (RotateStart.X - MousePos.X) * rotateSpeed;
|
---|
| 88 | //rotation.Y = sat(rotation.Y);
|
---|
| 89 | //nRotY = rotation.Y;
|
---|
| 90 | nRotZ = rotation.Z;
|
---|
[69] | 91 | Rotating = false;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[70] | 94 | float newFov=fov+currentZoom*zoomSpeed;
|
---|
| 95 | if(newFov>fov) {
|
---|
| 96 | newFov=fov;
|
---|
| 97 | currentZoom=0;
|
---|
| 98 | }
|
---|
| 99 | if(newFov<0) {
|
---|
| 100 | newFov=zoomSpeed;
|
---|
| 101 | currentZoom=1-fov/zoomSpeed;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[87] | 104 |
|
---|
| 105 |
|
---|
| 106 | //camera->setRotation(vector3df(rotation.X,-180-nRotY,nRotZ));
|
---|
| 107 | //camera->setRotation(vector3df(rotation.X,nRotY,0));
|
---|
| 108 | //camera->bindTargetAndRotation(true);
|
---|
| 109 | camera->setRotation(rotation);
|
---|
| 110 | //camera->setTarget(vector3df(ToIrrlichtCoordinates(core::Vector3D(0,0,-2))));
|
---|
| 111 | //rotation=camera->getRotation();
|
---|
| 112 | //printf("%f %f %f\n",rotation.X,rotation.Y,rotation.Z);
|
---|
| 113 |
|
---|
[70] | 114 | camera->setFOV(newFov);
|
---|
[69] | 115 | }
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | } // end namespace simulator
|
---|
| 119 | } // end namespace flair
|
---|
| 120 |
|
---|
| 121 | #endif // GL
|
---|