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

Last change on this file since 409 was 167, checked in by Sanahuja Guillaume, 8 years ago

modifs pour template vectors

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