source: flair-src/trunk/lib/FlairSimulator/src/Man.cpp@ 157

Last change on this file since 157 was 157, checked in by Sanahuja Guillaume, 7 years ago

iadded isready to iodevice:
avoid problem of imu not ready in ardrone2

File size: 5.4 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: 2013/04/15
6// filename: Man.cpp
7//
8// author: Guillaume Sanahuja
9// Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11// version: $Id: $
12//
13// purpose: classe chargeant un personnage
14//
15/*********************************************************************/
16#ifdef GL
17
18#include "Man.h"
19#include "Gui.h"
20#include "Simulator.h"
21#include "Simulator_impl.h"
22#include "Euler.h"
23#include <ISceneManager.h>
24#include <IAnimatedMeshSceneNode.h>
25#include <Tab.h>
26#include <DoubleSpinBox.h>
27#include "FollowMeCamera.h"
28
29class addAnimatedMeshSceneNode;
30using namespace irr;
31using namespace irr::core;
32using namespace irr::scene;
33using namespace irr::video;
34using namespace flair::core;
35using namespace flair::gui;
36
37namespace flair {
38namespace simulator {
39
40Man::Man(const Simulator *parent, std::string name) : Model(parent, name) {
41 node = getGui()->getSceneManager()->addAnimatedMeshSceneNode(
42 getGui()->getMesh("ninja.b3d"), getSceneNode(), -1, vector3df(0, 0, 0),
43 vector3df(90, 0, 90), vector3df(10, 10, 10));
44
45 node->setFrameLoop(0, 13);
46 node->setAnimationSpeed(0);
47 node->getMaterial(0).NormalizeNormals = true;
48 node->getMaterial(0).Lighting = false;
49
50 getFollowMeCamera()->setPositionOffset(vector3df(0, 0, -1));
51 getFollowMeCamera()->setTargetOffset(vector3df(0, 0, -1));
52
53 setTriangleSelector(
54 getGui()->getSceneManager()->createTriangleSelector(node));
55 Box()->addInternalBox(node->getTransformedBoundingBox());
56
57 Tab *setup_tab = new Tab(GetTabWidget(), "model");
58 t_speed = new DoubleSpinBox(setup_tab->NewRow(), "translational speed (m/s):",
59 0, 5, 0.1);
60 r_speed = new DoubleSpinBox(setup_tab->NewRow(), "rotational speed (deg/s):",
61 0, 180, 10);
62
63 SetIsReady(true);
64}
65
66Man::~Man() {}
67
68void Man::CalcModel(void) {
69 // compute quaternion from W
70 // Quaternion derivative: dQ = 0.5*(Q*Qw)
71 Quaternion dQ = state[-1].Quat.GetDerivative(state[0].W);
72
73 // Quaternion integration
74 state[0].Quat = state[-1].Quat + dQ * dT();
75 state[0].Quat.Normalize();
76
77 Vector3D dir = state[0].Vel;
78 dir.Rotate(state[0].Quat);
79 state[0].Pos = state[-1].Pos + dT() * dir;
80}
81
82bool Man::OnEvent(const SEvent &event) {
83 if (event.EventType != EET_KEY_INPUT_EVENT)
84 return false;
85
86 if (event.KeyInput.PressedDown == false) {
87 state[0].Vel.x = 0;
88 state[0].W.z = 0;
89 node->setAnimationSpeed(0);
90 } else {
91 switch (event.KeyInput.Key) {
92 case KEY_UP:
93 state[0].Vel.x = t_speed->Value();
94 node->setAnimationSpeed(t_speed->Value() * 10.f);
95 break;
96 case KEY_DOWN:
97 state[0].Vel.x = -t_speed->Value();
98 node->setAnimationSpeed(-t_speed->Value() * 10.f);
99 break;
100 case KEY_LEFT:
101 state[0].W.z = -Euler::ToRadian(r_speed->Value());
102 node->setAnimationSpeed(r_speed->Value() * .15f);
103 break;
104 case KEY_RIGHT:
105 state[0].W.z = Euler::ToRadian(r_speed->Value());
106 node->setAnimationSpeed(-r_speed->Value() * .15f);
107 break;
108 default:
109 return false;
110 break;
111 }
112 }
113
114 return true;
115}
116
117size_t Man::dbtSize(void) const { return 6 * sizeof(float); }
118
119void Man::WritedbtBuf(char *dbtbuf) { /*
120 float *buf=(float*)dbtbuf;
121 vector3df vect=node->getPosition();
122 memcpy(buf,&vect.X,sizeof(float));
123 buf++;
124 memcpy(buf,&vect.Y,sizeof(float));
125 buf++;
126 memcpy(buf,&vect.Z,sizeof(float));
127 buf++;
128 vect=node->getRotation();
129 memcpy(buf,&vect.X,sizeof(float));
130 buf++;
131 memcpy(buf,&vect.Y,sizeof(float));
132 buf++;
133 memcpy(buf,&vect.Z,sizeof(float));
134 buf++;*/
135}
136
137void Man::ReaddbtBuf(char *dbtbuf) { /*
138 float *buf=(float*)dbtbuf;
139 vector3df vect;
140 memcpy(&vect.X,buf,sizeof(float));
141 buf++;
142 memcpy(&vect.Y,buf,sizeof(float));
143 buf++;
144 memcpy(&vect.Z,buf,sizeof(float));
145 buf++;
146 node->setPosition(vect);
147 memcpy(&vect.X,buf,sizeof(float));
148 buf++;
149 memcpy(&vect.Y,buf,sizeof(float));
150 buf++;
151 memcpy(&vect.Z,buf,sizeof(float));
152 buf++;
153 node->setRotation(vect);
154 node->setAnimationSpeed(2.f);*/
155}
156
157} // end namespace simulator
158} // end namespace flair
159#endif // GL
Note: See TracBrowser for help on using the repository browser.