// %flair:license{ // This file is part of the Flair framework distributed under the // CECILL-C License, Version 1.0. // %flair:license} // created: 2016/09/01 // filename: FixedCamera.cpp // // author: Guillaume Sanahuja // Copyright Heudiasyc UMR UTC/CNRS 7253 // // version: $Id: $ // // purpose: class for a fixed camera in the gui // /*********************************************************************/ #ifdef GL #include "FixedCamera.h" #include "Simulator.h" #include "Model.h" #include "Model_impl.h" #include "Gui.h" #include #include #include #include #include using namespace irr; using namespace gui; using namespace core; using namespace scene; namespace flair { namespace simulator { FixedCamera::FixedCamera(std::string name,core::Vector3D position,float inRotateSpeed,float inZoomSpeed):VisualizationCamera(name) { RotY = -90; RotZ = 0; Rotating = false; rotateSpeed=inRotateSpeed; zoomSpeed=inZoomSpeed; camera->setPosition(vector3df(ToIrrlichtCoordinates(position))); fov=camera->getFOV(); } FixedCamera::~FixedCamera() {} float FixedCamera::sat(float value) { if (value >= -1) value = -1; if (value <= -179) value = -179; return value; } void FixedCamera::animateNode(ISceneNode *node, u32 timeMs) { ICameraSceneNode *camera = static_cast(node); float nRotY = RotY; float nRotZ = RotZ; if (LMouseKey == true) { if (!Rotating) { RotateStart = MousePos; Rotating = true; nRotY = RotY; nRotZ = RotZ; } else { nRotY += (RotateStart.Y - MousePos.Y) * rotateSpeed; nRotZ += (RotateStart.X - MousePos.X) * rotateSpeed; nRotY = sat(nRotY); } } else if (Rotating) { RotY += (RotateStart.Y - MousePos.Y) * rotateSpeed; RotZ += (RotateStart.X - MousePos.X) * rotateSpeed; RotY = sat(RotY); nRotY = RotY; nRotZ = RotZ; Rotating = false; } float newFov=fov+currentZoom*zoomSpeed; if(newFov>fov) { newFov=fov; currentZoom=0; } if(newFov<0) { newFov=zoomSpeed; currentZoom=1-fov/zoomSpeed; } camera->setRotation(vector3df(0,nRotY,nRotZ)); camera->bindTargetAndRotation(true); camera->setFOV(newFov); } } // end namespace simulator } // end namespace flair #endif // GL