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

Last change on this file since 26 was 15, checked in by Bayard Gildas, 9 years ago

sources reformatted with flair-format-dir script

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