[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: VisualizationCamera.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: class for a visualization camera in the gui
|
---|
| 14 | //
|
---|
| 15 | /*********************************************************************/
|
---|
| 16 | #ifdef GL
|
---|
| 17 |
|
---|
| 18 | #include "VisualizationCamera.h"
|
---|
| 19 | #include "Simulator.h"
|
---|
| 20 | #include "Model.h"
|
---|
| 21 | #include "Model_impl.h"
|
---|
| 22 | #include "Gui.h"
|
---|
[70] | 23 | #include "Gui_impl.h"
|
---|
[69] | 24 | #include <ICursorControl.h>
|
---|
| 25 | #include <ICameraSceneNode.h>
|
---|
| 26 | #include <IrrlichtDevice.h>
|
---|
| 27 | #include <ISceneManager.h>
|
---|
| 28 |
|
---|
| 29 | using namespace irr;
|
---|
| 30 | using namespace gui;
|
---|
| 31 | using namespace core;
|
---|
| 32 | using namespace scene;
|
---|
[286] | 33 | using namespace video;
|
---|
[69] | 34 |
|
---|
| 35 | namespace flair {
|
---|
| 36 | namespace simulator {
|
---|
| 37 |
|
---|
[70] | 38 | VisualizationCamera::VisualizationCamera(std::string inName) {
|
---|
| 39 | name=inName;
|
---|
| 40 | currentZoom = 0;
|
---|
[69] | 41 | LMouseKey = false;
|
---|
| 42 |
|
---|
[286] | 43 | // camera for visualization
|
---|
[69] | 44 | camera = getGui()->getSceneManager()->addCameraSceneNode();
|
---|
| 45 | camera->setAspectRatio(getGui()->getAspectRatio()); // on force a cause du view port
|
---|
| 46 | camera->setUpVector(vector3df(0, 0, 1));
|
---|
| 47 | camera->addAnimator(this);
|
---|
| 48 | camera->setFarValue(8000);
|
---|
[70] | 49 |
|
---|
| 50 | getGui()->pimpl_->AddVisualizationCamera(this);
|
---|
[286] | 51 |
|
---|
| 52 | // camera to draw axis, in a new dedicated scene manager
|
---|
| 53 | axis_scenemanager=getGui()->getSceneManager()->createNewSceneManager();
|
---|
| 54 | axis_camera = axis_scenemanager->addCameraSceneNode();
|
---|
| 55 | axis_camera->setAspectRatio(1); // same as texture ratio, TODO: get it from texture in renderAxisToTexture
|
---|
| 56 | axis_camera->setUpVector(vector3df(0, 0, 1));
|
---|
| 57 | axis_camera->setFOV(PI / 2.5f);
|
---|
| 58 | axis_scenemanager->setActiveCamera(axis_camera);
|
---|
| 59 | prendre en compte le yaw monde/optitrack (rotation de axis_scenemanager?)
|
---|
| 60 | IAnimatedMesh* arrowMeshRed = axis_scenemanager->addArrowMesh( "x_axisArrow",video::SColor(255, 255, 0, 0),video::SColor(255, 255, 0, 0));
|
---|
| 61 | nodeX = axis_scenemanager->addMeshSceneNode(arrowMeshRed);
|
---|
| 62 | nodeX->setMaterialFlag(video::EMF_LIGHTING, false);
|
---|
| 63 | nodeX->setRotation(vector3df(0,0,-90));
|
---|
| 64 | nodeX->setScale(vector3df(1,3,1));
|
---|
| 65 |
|
---|
| 66 | IAnimatedMesh* arrowMeshGreen = axis_scenemanager->addArrowMesh( "y_axisArrow",video::SColor(255, 0, 255, 0),video::SColor(255, 0, 255, 0));
|
---|
| 67 | nodeY = axis_scenemanager->addMeshSceneNode(arrowMeshGreen);
|
---|
| 68 | nodeY->setMaterialFlag(video::EMF_LIGHTING, false);
|
---|
| 69 | nodeY->setScale(vector3df(1,3,1));
|
---|
| 70 |
|
---|
| 71 | IAnimatedMesh* arrowMeshBlue = axis_scenemanager->addArrowMesh( "z_axisArrow",video::SColor(255, 0, 0, 255),video::SColor(255, 0, 0, 255));
|
---|
| 72 | nodeZ = axis_scenemanager->addMeshSceneNode(arrowMeshBlue);
|
---|
| 73 | nodeZ->setMaterialFlag(video::EMF_LIGHTING, false);
|
---|
| 74 | nodeZ->setRotation(vector3df(-90,0,0));//irrlicht is left handed, draw a right handed axis
|
---|
| 75 | nodeZ->setScale(vector3df(1,3,1));
|
---|
[69] | 76 | }
|
---|
| 77 |
|
---|
| 78 | VisualizationCamera::~VisualizationCamera() {}
|
---|
| 79 |
|
---|
[286] | 80 | void VisualizationCamera::renderAxisToTexture(ITexture* texture) {
|
---|
| 81 | //put axis at a "normalized" distance
|
---|
| 82 | vector3df direction=camera->getTarget()-camera->getPosition();
|
---|
| 83 | direction.normalize();
|
---|
| 84 | nodeX->setPosition(camera->getPosition()+direction*6);
|
---|
| 85 | nodeY->setPosition(camera->getPosition()+direction*6);
|
---|
| 86 | nodeZ->setPosition(camera->getPosition()+direction*6);
|
---|
| 87 |
|
---|
| 88 | axis_camera->setPosition(camera->getPosition());
|
---|
| 89 | axis_camera->setRotation(camera->getRotation());
|
---|
| 90 | axis_camera->setTarget(camera->getTarget());
|
---|
| 91 |
|
---|
| 92 | axis_scenemanager->getVideoDriver()->setRenderTarget(texture, true, true, SColor(0,0,0,0));
|
---|
| 93 | axis_scenemanager->drawAll();
|
---|
| 94 | axis_scenemanager->getVideoDriver()->setRenderTarget(0, true, true, 0);
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[70] | 97 | std::string VisualizationCamera::getName(void) {
|
---|
| 98 | return name;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
[69] | 101 | ICameraSceneNode *VisualizationCamera::getCameraSceneNode(void) {
|
---|
| 102 | return camera;
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | ISceneNodeAnimator *VisualizationCamera::createClone(ISceneNode *node,
|
---|
| 106 | ISceneManager *newManager) {
|
---|
| 107 | return NULL;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | bool VisualizationCamera::OnEvent(const irr::SEvent& event) {
|
---|
| 111 | if (event.EventType != EET_MOUSE_INPUT_EVENT)
|
---|
| 112 | return false;
|
---|
| 113 |
|
---|
| 114 | switch (event.MouseInput.Event) {
|
---|
| 115 |
|
---|
| 116 | case EMIE_MOUSE_WHEEL:
|
---|
[70] | 117 | currentZoom -= event.MouseInput.Wheel;
|
---|
[69] | 118 | break;
|
---|
| 119 | case EMIE_LMOUSE_PRESSED_DOWN:
|
---|
| 120 | LMouseKey = true;
|
---|
| 121 | break;
|
---|
| 122 | case EMIE_LMOUSE_LEFT_UP:
|
---|
| 123 | LMouseKey = false;
|
---|
| 124 | break;
|
---|
| 125 | case EMIE_MOUSE_MOVED:
|
---|
| 126 | MousePos = getGui()->getDevice()->getCursorControl()->getRelativePosition();
|
---|
| 127 | break;
|
---|
| 128 | default:
|
---|
| 129 | return false;
|
---|
| 130 | break;
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | return true;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | } // end namespace simulator
|
---|
| 137 | } // end namespace flair
|
---|
| 138 |
|
---|
| 139 | #endif // GL
|
---|