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