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 |
|
---|
29 | class addAnimatedMeshSceneNode;
|
---|
30 | using namespace irr;
|
---|
31 | using namespace irr::core;
|
---|
32 | using namespace irr::scene;
|
---|
33 | using namespace irr::video;
|
---|
34 | using namespace flair::core;
|
---|
35 | using namespace flair::gui;
|
---|
36 |
|
---|
37 | namespace flair {
|
---|
38 | namespace simulator {
|
---|
39 |
|
---|
40 | Man::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 |
|
---|
64 | Man::~Man() {}
|
---|
65 |
|
---|
66 | void 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);
|
---|
70 |
|
---|
71 | // Quaternion integration
|
---|
72 | state[0].Quat = state[-1].Quat + dQ * dT();
|
---|
73 | state[0].Quat.Normalize();
|
---|
74 |
|
---|
75 | Vector3D dir = state[0].Vel;
|
---|
76 | dir.Rotate(state[0].Quat);
|
---|
77 | state[0].Pos = state[-1].Pos + dT() * dir;
|
---|
78 | }
|
---|
79 |
|
---|
80 | bool Man::OnEvent(const SEvent &event) {
|
---|
81 | if (event.EventType != EET_KEY_INPUT_EVENT)
|
---|
82 | return false;
|
---|
83 |
|
---|
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;
|
---|
109 | }
|
---|
110 | }
|
---|
111 |
|
---|
112 | return true;
|
---|
113 | }
|
---|
114 |
|
---|
115 | size_t Man::dbtSize(void) const { return 6 * sizeof(float); }
|
---|
116 |
|
---|
117 | void 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++;*/
|
---|
133 | }
|
---|
134 |
|
---|
135 | void 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);*/
|
---|
153 | }
|
---|
154 |
|
---|
155 | } // end namespace simulator
|
---|
156 | } // end namespace flair
|
---|
157 | #endif // GL
|
---|