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

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

lic

File size: 4.2 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 "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
36namespace flair
37{
38namespace simulator
39{
40
41Man::Man(const Simulator* parent,std::string name): Model(parent,name)
42{
43 node = getGui()->getSceneManager()->addAnimatedMeshSceneNode(getGui()->getMesh("ninja.b3d"),getSceneNode(),-1,
44 vector3df(0,0,0),vector3df(90,0,90),vector3df(10,10,10));
45
46 node->setFrameLoop(0, 13);
47 node->setAnimationSpeed(0);
48 node->getMaterial(0).NormalizeNormals = true;
49 node->getMaterial(0).Lighting = false;
50
51 getCamera()->setPositionOffset(vector3df(0,0,100));
52 getCamera()->setTargetOffset(vector3df(0,0,100));
53
54 setTriangleSelector(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):",0,5,0.1);
59 r_speed=new DoubleSpinBox(setup_tab->NewRow(),"rotational speed (deg/s):",0,180,10);
60}
61
62Man::~Man()
63{
64
65}
66
67void Man::CalcModel(void)
68{
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{
84 if (event.EventType != EET_KEY_INPUT_EVENT)
85 return false;
86
87 if(event.KeyInput.PressedDown==false)
88 {
89 state[0].Vel.x=0;
90 state[0].W.z=0;
91 node->setAnimationSpeed(0);
92 }
93 else
94 {
95 switch(event.KeyInput.Key)
96 {
97 case KEY_UP:
98 state[0].Vel.x=t_speed->Value();
99 node->setAnimationSpeed(t_speed->Value()*10.f);
100 break;
101 case KEY_DOWN:
102 state[0].Vel.x=-t_speed->Value();
103 node->setAnimationSpeed(-t_speed->Value()*10.f);
104 break;
105 case KEY_LEFT:
106 state[0].W.z=-Euler::ToRadian(r_speed->Value());
107 node->setAnimationSpeed(r_speed->Value()*.15f);
108 break;
109 case KEY_RIGHT:
110 state[0].W.z=Euler::ToRadian(r_speed->Value());
111 node->setAnimationSpeed(-r_speed->Value()*.15f);
112 break;
113 default:
114 return false;
115 break;
116 }
117 }
118
119 return true;
120}
121
122size_t Man::dbtSize(void) const
123{
124 return 6*sizeof(float);
125}
126
127void Man::WritedbtBuf(char* dbtbuf)
128{/*
129 float *buf=(float*)dbtbuf;
130 vector3df vect=node->getPosition();
131 memcpy(buf,&vect.X,sizeof(float));
132 buf++;
133 memcpy(buf,&vect.Y,sizeof(float));
134 buf++;
135 memcpy(buf,&vect.Z,sizeof(float));
136 buf++;
137 vect=node->getRotation();
138 memcpy(buf,&vect.X,sizeof(float));
139 buf++;
140 memcpy(buf,&vect.Y,sizeof(float));
141 buf++;
142 memcpy(buf,&vect.Z,sizeof(float));
143 buf++;*/
144}
145
146void Man::ReaddbtBuf(char* dbtbuf)
147{/*
148 float *buf=(float*)dbtbuf;
149 vector3df vect;
150 memcpy(&vect.X,buf,sizeof(float));
151 buf++;
152 memcpy(&vect.Y,buf,sizeof(float));
153 buf++;
154 memcpy(&vect.Z,buf,sizeof(float));
155 buf++;
156 node->setPosition(vect);
157 memcpy(&vect.X,buf,sizeof(float));
158 buf++;
159 memcpy(&vect.Y,buf,sizeof(float));
160 buf++;
161 memcpy(&vect.Z,buf,sizeof(float));
162 buf++;
163 node->setRotation(vect);
164 node->setAnimationSpeed(2.f);*/
165}
166
167} // end namespace simulator
168} // end namespace flair
169#endif //GL
Note: See TracBrowser for help on using the repository browser.