[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 |
|
---|
[286] | 29 |
|
---|
[69] | 30 | using namespace irr;
|
---|
| 31 | using namespace gui;
|
---|
| 32 | using namespace core;
|
---|
| 33 | using namespace scene;
|
---|
| 34 |
|
---|
| 35 | namespace flair {
|
---|
| 36 | namespace simulator {
|
---|
| 37 |
|
---|
[167] | 38 | FixedCamera::FixedCamera(std::string name,core::Vector3Df position,core::Vector3Df lookat,float inRotateSpeed,float inZoomSpeed):VisualizationCamera(name) {
|
---|
[69] | 39 | Rotating = false;
|
---|
[70] | 40 | rotateSpeed=inRotateSpeed;
|
---|
| 41 | zoomSpeed=inZoomSpeed;
|
---|
[87] | 42 |
|
---|
| 43 | camera->bindTargetAndRotation(true);
|
---|
[70] | 44 | camera->setPosition(vector3df(ToIrrlichtCoordinates(position)));
|
---|
[87] | 45 | camera->setTarget(vector3df(ToIrrlichtCoordinates(lookat)));
|
---|
[120] | 46 |
|
---|
[70] | 47 | fov=camera->getFOV();
|
---|
[69] | 48 | }
|
---|
| 49 |
|
---|
| 50 | FixedCamera::~FixedCamera() {}
|
---|
| 51 |
|
---|
| 52 | void FixedCamera::animateNode(ISceneNode *node, u32 timeMs) {
|
---|
| 53 | ICameraSceneNode *camera = static_cast<ICameraSceneNode *>(node);
|
---|
[286] | 54 |
|
---|
[69] | 55 | if (LMouseKey == true) {
|
---|
| 56 | if (!Rotating) {
|
---|
| 57 | RotateStart = MousePos;
|
---|
| 58 | Rotating = true;
|
---|
[120] | 59 | target = (camera->getTarget() - camera->getAbsolutePosition());
|
---|
[69] | 60 | } else {
|
---|
[120] | 61 | float nRotY = (RotateStart.Y - MousePos.Y) * rotateSpeed;
|
---|
| 62 | float nRotZ = -(RotateStart.X - MousePos.X) * rotateSpeed;
|
---|
[107] | 63 |
|
---|
[120] | 64 | //normal between target and up vector
|
---|
[167] | 65 | cameraAxeY=target.crossProduct(vector3df(0,0,1));
|
---|
[120] | 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
|
---|
[167] | 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));
|
---|
[120] | 87 | if (cross.dotProduct(cameraAxeY) > 0) {
|
---|
| 88 | newTarget += camera->getAbsolutePosition();
|
---|
| 89 | camera->setTarget(newTarget);
|
---|
| 90 | }
|
---|
[69] | 91 | }
|
---|
| 92 | } else if (Rotating) {
|
---|
| 93 | Rotating = false;
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[120] | 96 | //handle zoom
|
---|
[70] | 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);
|
---|
[69] | 107 | }
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 | } // end namespace simulator
|
---|
| 111 | } // end namespace flair
|
---|
| 112 |
|
---|
| 113 | #endif // GL
|
---|