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

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

correction bugs parser

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>
[69]27#include "FollowMeCamera.h"
[8]28
[134]29class addAnimatedMeshSceneNode;
[8]30using namespace irr;
31using namespace irr::core;
32using namespace irr::scene;
33using namespace irr::video;
34using namespace flair::core;
35using namespace flair::gui;
36
[15]37namespace flair {
38namespace simulator {
[8]39
[15]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));
[8]44
[15]45 node->setFrameLoop(0, 13);
46 node->setAnimationSpeed(0);
47 node->getMaterial(0).NormalizeNormals = true;
48 node->getMaterial(0).Lighting = false;
[8]49
[70]50 getFollowMeCamera()->setPositionOffset(vector3df(0, 0, -1));
51 getFollowMeCamera()->setTargetOffset(vector3df(0, 0, -1));
[8]52
[15]53 setTriangleSelector(
54 getGui()->getSceneManager()->createTriangleSelector(node));
55 Box()->addInternalBox(node->getTransformedBoundingBox());
[8]56
[15]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);
[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
[15]75 Vector3D dir = state[0].Vel;
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.