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