source: flair-src/trunk/lib/FlairSimulator/src/Blade.cpp@ 362

Last change on this file since 362 was 339, checked in by Sanahuja Guillaume, 4 years ago

allow all blade rotations

File size: 3.3 KB
Line 
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: 2012/08/22
6// filename: Blade.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: classe definissant une helice
14//
15/*********************************************************************/
16#ifdef GL
17
18#include "Blade.h"
19#include "MeshSceneNode.h"
20#include "Model.h"
21#include "Gui.h"
22#include "Simulator.h"
23#include <IGeometryCreator.h>
24#include <ISceneManager.h>
25#include <IFileSystem.h>
26#include <IVideoDriver.h>
27
28using namespace irr;
29using namespace irr::video;
30using namespace irr::scene;
31using namespace irr::core;
32using namespace irr::io;
33using namespace flair::core;
34
35namespace flair {
36namespace simulator {
37
38Blade::Blade(Model *parent, const vector3df &position,const vector3df &rotation, bool inverted, s32 id)
39 : ISceneNode(parent->getSceneNode(), getGui()->getSceneManager(), id,
40 position,rotation) {
41 ISceneManager *mgr = getGui()->getSceneManager();
42
43 const IGeometryCreator *geo;
44 geo = mgr->getGeometryCreator();
45 pale = geo->createCubeMesh(vector3df(63.5, 0.5, 5));
46
47 float angle;
48 if (inverted == false) {
49 angle = 20;
50 } else {
51 angle = -20;
52 }
53
54 ITexture *texture = getGui()->getTexture("carbone.jpg");
55 pale_1 = new MeshSceneNode(parent, pale, vector3df(-30, 0, 0),
56 vector3df(-angle + 90, 0, 0), texture);
57 pale_1->setParent(this);
58 pale_2 = new MeshSceneNode(parent, pale, vector3df(30, 0, 0),
59 vector3df(angle + 90, 0, 0), texture);
60 pale_2->setParent(this);
61
62 anim = mgr->createRotationAnimator(vector3df(0.f, 0.f, 0.f));
63 addAnimator(anim);
64}
65
66Blade::Blade(ISceneNode *parent, const vector3df &position,const vector3df &rotation, bool inverted, s32 id)
67 : ISceneNode(parent, getGui()->getSceneManager(), id,
68 position,rotation) {
69 ISceneManager *mgr = getGui()->getSceneManager();
70
71 const IGeometryCreator *geo;
72 geo = mgr->getGeometryCreator();
73 pale = geo->createCubeMesh(vector3df(63.5, 0.5, 5));
74
75 float angle;
76 if (inverted == false) {
77 angle = 20;
78 } else {
79 angle = -20;
80 }
81
82 ITexture *texture = getGui()->getTexture("carbone.jpg");
83 pale_1 = new MeshSceneNode(parent, pale, vector3df(-30, 0, 0),
84 vector3df(-angle + 90, 0, 0), texture);
85 pale_1->setParent(this);
86 pale_2 = new MeshSceneNode(parent, pale, vector3df(30, 0, 0),
87 vector3df(angle + 90, 0, 0), texture);
88 pale_2->setParent(this);
89
90 anim = mgr->createRotationAnimator(vector3df(0.f, 0.f, 0.f));
91 addAnimator(anim);
92}
93
94void Blade::OnRegisterSceneNode() {
95 if (IsVisible)
96 SceneManager->registerNodeForRendering(this);
97
98 ISceneNode::OnRegisterSceneNode();
99}
100
101void Blade::SetRotationSpeed(const vector3df &value) {
102 IAttributes *attribs =
103 getSceneManager()->getFileSystem()->createEmptyAttributes();
104
105 attribs->setAttribute("Type", "rotation");
106 attribs->setAttribute("Rotation", value);
107 anim->deserializeAttributes(attribs);
108
109 attribs->drop();
110}
111
112void Blade::render() {
113 IVideoDriver *driver = SceneManager->getVideoDriver();
114 driver->setTransform(ETS_WORLD, AbsoluteTransformation);
115}
116
117} // end namespace simulator
118} // end namespace flair
119#endif // GL
Note: See TracBrowser for help on using the repository browser.