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 | using namespace irr;
|
---|
30 | using namespace irr::core;
|
---|
31 | using namespace irr::scene;
|
---|
32 | using namespace irr::video;
|
---|
33 | using namespace flair::core;
|
---|
34 | using namespace flair::gui;
|
---|
35 |
|
---|
36 | namespace flair {
|
---|
37 | namespace simulator {
|
---|
38 |
|
---|
39 | Man::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));
|
---|
43 |
|
---|
44 | node->setFrameLoop(0, 13);
|
---|
45 | node->setAnimationSpeed(0);
|
---|
46 | node->getMaterial(0).NormalizeNormals = true;
|
---|
47 | node->getMaterial(0).Lighting = false;
|
---|
48 |
|
---|
49 | getFollowMeCamera()->setPositionOffset(vector3df(0, 0, -1));
|
---|
50 | getFollowMeCamera()->setTargetOffset(vector3df(0, 0, -1));
|
---|
51 |
|
---|
52 | setTriangleSelector(
|
---|
53 | getGui()->getSceneManager()->createTriangleSelector(node));
|
---|
54 | Box()->addInternalBox(node->getTransformedBoundingBox());
|
---|
55 |
|
---|
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);
|
---|
61 | }
|
---|
62 |
|
---|
63 | Man::~Man() {}
|
---|
64 |
|
---|
65 | void 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);
|
---|
69 |
|
---|
70 | // Quaternion integration
|
---|
71 | state[0].Quat = state[-1].Quat + dQ * dT();
|
---|
72 | state[0].Quat.Normalize();
|
---|
73 |
|
---|
74 | Vector3D dir = state[0].Vel;
|
---|
75 | dir.Rotate(state[0].Quat);
|
---|
76 | state[0].Pos = state[-1].Pos + dT() * dir;
|
---|
77 | }
|
---|
78 |
|
---|
79 | bool Man::OnEvent(const SEvent &event) {
|
---|
80 | if (event.EventType != EET_KEY_INPUT_EVENT)
|
---|
81 | return false;
|
---|
82 |
|
---|
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;
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | return true;
|
---|
112 | }
|
---|
113 |
|
---|
114 | size_t Man::dbtSize(void) const { return 6 * sizeof(float); }
|
---|
115 |
|
---|
116 | void 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++;*/
|
---|
132 | }
|
---|
133 |
|
---|
134 | void 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);*/
|
---|
152 | }
|
---|
153 |
|
---|
154 | } // end namespace simulator
|
---|
155 | } // end namespace flair
|
---|
156 | #endif // GL
|
---|