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: 2013/03/25
|
---|
6 | // filename: GenericObject.cpp
|
---|
7 | //
|
---|
8 | // author: Cesar Richard
|
---|
9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
10 | //
|
---|
11 | // version: $Id: $
|
---|
12 | //
|
---|
13 | // purpose: classe definissant un modele a simuler
|
---|
14 | //
|
---|
15 | /*********************************************************************/
|
---|
16 |
|
---|
17 | #ifdef GL
|
---|
18 | #include "GenericObject.h"
|
---|
19 | #include "Simulator_impl.h"
|
---|
20 |
|
---|
21 | #include "Quaternion.h"
|
---|
22 | #include <ISceneManager.h>
|
---|
23 |
|
---|
24 | using namespace irr;
|
---|
25 | using namespace video;
|
---|
26 | using namespace scene;
|
---|
27 | using namespace core;
|
---|
28 |
|
---|
29 | using namespace flair::core;
|
---|
30 | using namespace flair::simulator;
|
---|
31 |
|
---|
32 | namespace flair {
|
---|
33 | namespace simulator {
|
---|
34 |
|
---|
35 | GenericObject::GenericObject(Simulator *parent, std::string name,
|
---|
36 | ISceneManager *sceneManager)
|
---|
37 | : IMeshSceneNode(sceneManager->getRootSceneNode(), sceneManager,
|
---|
38 | -1) //, IODevice(parent,name)
|
---|
39 | {
|
---|
40 | setMaterialFlag(EMF_LIGHTING, false);
|
---|
41 | Material = getMaterial(0);
|
---|
42 | // setMaterialTexture(0,sceneManager->getVideoDriver()->getTexture("/home/cesar/igep/uav_dev_svn/trunk/media/nskinbl.jpg"));
|
---|
43 | Material.NormalizeNormals = true;
|
---|
44 | Material.Wireframe = false;
|
---|
45 | Material.Lighting = false;
|
---|
46 |
|
---|
47 | parent->pimpl_->objects.push_back(this);
|
---|
48 | }
|
---|
49 |
|
---|
50 | GenericObject::~GenericObject() {}
|
---|
51 |
|
---|
52 | void GenericObject::setScale(float value) {
|
---|
53 | ISceneNode::setScale(vector3df(value, value, value));
|
---|
54 | }
|
---|
55 |
|
---|
56 | void GenericObject::setScale(vector3df scale) { ISceneNode::setScale(scale); }
|
---|
57 |
|
---|
58 | ITriangleSelector *GenericObject::TriangleSelector(void) { return selector; }
|
---|
59 |
|
---|
60 | void GenericObject::OnRegisterSceneNode(void) {
|
---|
61 | if (IsVisible)
|
---|
62 | SceneManager->registerNodeForRendering(this);
|
---|
63 |
|
---|
64 | ISceneNode::OnRegisterSceneNode();
|
---|
65 | }
|
---|
66 |
|
---|
67 | void GenericObject::render(void) {
|
---|
68 | IVideoDriver *driver = SceneManager->getVideoDriver();
|
---|
69 |
|
---|
70 | driver->setMaterial(Material);
|
---|
71 |
|
---|
72 | driver->setTransform(ETS_WORLD, AbsoluteTransformation);
|
---|
73 | driver->drawMeshBuffer(mesh->getMeshBuffer(0));
|
---|
74 | }
|
---|
75 |
|
---|
76 | void GenericObject::setMesh(IMesh *mesh) {
|
---|
77 | this->mesh = mesh;
|
---|
78 | box = mesh->getBoundingBox();
|
---|
79 |
|
---|
80 | selector = getSceneManager()->createTriangleSelector(mesh, this);
|
---|
81 | setTriangleSelector(selector);
|
---|
82 | }
|
---|
83 |
|
---|
84 | IMesh *GenericObject::getMesh(void) { return mesh; }
|
---|
85 |
|
---|
86 | void GenericObject::setPosition(irr::core::vector3df pos) {
|
---|
87 | ISceneNode::setPosition(ToIrrlichtCoordinates(pos));
|
---|
88 | }
|
---|
89 |
|
---|
90 | void GenericObject::setRotation(irr::core::vector3df rotation) {
|
---|
91 | Euler eulerA(rotation.X, rotation.Y, rotation.Z);
|
---|
92 | Euler eulerB;
|
---|
93 | Quaternion quatA, quatB;
|
---|
94 | eulerA.ToQuaternion(quatA);
|
---|
95 | quatB = ToIrrlichtOrientation(quatA);
|
---|
96 | quatB.ToEuler(eulerB);
|
---|
97 |
|
---|
98 | ISceneNode::setRotation(Euler::ToDegree(1) *
|
---|
99 | vector3df(eulerB.roll, eulerB.pitch, eulerB.yaw));
|
---|
100 | }
|
---|
101 |
|
---|
102 | } // end namespace simulator
|
---|
103 | } // end namespace flair
|
---|
104 | #endif
|
---|