Changeset 70 in flair-src for trunk/lib/FlairSimulator
- Timestamp:
- Sep 6, 2016, 5:49:32 PM (8 years ago)
- Location:
- trunk/lib/FlairSimulator/src
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/FlairSimulator/src/FixedCamera.cpp
r69 r70 25 25 #include <IrrlichtDevice.h> 26 26 #include <ISceneManager.h> 27 #include <Euler.h> 27 28 28 29 using namespace irr; … … 34 35 namespace simulator { 35 36 36 FixedCamera::FixedCamera( core::Vector3D position,float rotateSpeed,float zoomSpeed):VisualizationCamera(rotateSpeed,zoomSpeed) {37 RotY = 020;37 FixedCamera::FixedCamera(std::string name,core::Vector3D position,float inRotateSpeed,float inZoomSpeed):VisualizationCamera(name) { 38 RotY = -90; 38 39 RotZ = 0; 39 40 Rotating = false; 40 41 // camera 42 camera->setPosition(vector3df(position.x,position.y,position.z)); 41 rotateSpeed=inRotateSpeed; 42 zoomSpeed=inZoomSpeed; 43 camera->setPosition(vector3df(ToIrrlichtCoordinates(position))); 44 fov=camera->getFOV(); 43 45 } 44 46 45 47 FixedCamera::~FixedCamera() {} 48 49 float FixedCamera::sat(float value) { 50 if (value >= -1) 51 value = -1; 52 if (value <= -179) 53 value = -179; 54 return value; 55 } 46 56 47 57 void FixedCamera::animateNode(ISceneNode *node, u32 timeMs) { … … 60 70 nRotY += (RotateStart.Y - MousePos.Y) * rotateSpeed; 61 71 nRotZ += (RotateStart.X - MousePos.X) * rotateSpeed; 72 nRotY = sat(nRotY); 62 73 } 63 74 } else if (Rotating) { 64 75 RotY += (RotateStart.Y - MousePos.Y) * rotateSpeed; 65 76 RotZ += (RotateStart.X - MousePos.X) * rotateSpeed; 77 RotY = sat(RotY); 66 78 nRotY = RotY; 67 79 nRotZ = RotZ; … … 69 81 } 70 82 83 float newFov=fov+currentZoom*zoomSpeed; 84 if(newFov>fov) { 85 newFov=fov; 86 currentZoom=0; 87 } 88 if(newFov<0) { 89 newFov=zoomSpeed; 90 currentZoom=1-fov/zoomSpeed; 91 } 92 71 93 camera->setRotation(vector3df(0,nRotY,nRotZ)); 72 94 camera->bindTargetAndRotation(true); 95 camera->setFOV(newFov); 73 96 } 74 97 -
trunk/lib/FlairSimulator/src/FixedCamera.h
r69 r70 26 26 class FixedCamera : public VisualizationCamera { 27 27 public: 28 FixedCamera( core::Vector3D position,float rotateSpeed = -500.0f, float zoomSpeed = 4.0f);28 FixedCamera(std::string name,core::Vector3D position,float rotateSpeed = -500.0f, float zoomSpeed = .1f); 29 29 ~FixedCamera(); 30 30 … … 32 32 33 33 private: 34 float sat(float value); 34 35 irr::core::position2df RotateStart; 35 36 bool Rotating; 37 float rotateSpeed; 38 float zoomSpeed; 36 39 float RotY, RotZ; 40 float fov; 37 41 }; 38 42 -
trunk/lib/FlairSimulator/src/FollowMeCamera.cpp
r69 r70 34 34 namespace simulator { 35 35 36 FollowMeCamera::FollowMeCamera(const ISceneNode *parent, float rotateSpeed,37 float zoomSpeed):VisualizationCamera(rotateSpeed,zoomSpeed) {36 FollowMeCamera::FollowMeCamera(const ISceneNode *parent, std::string name,float inRotateSpeed, 37 float inZoomSpeed):VisualizationCamera(name) { 38 38 this->parent = parent; 39 rotateSpeed=inRotateSpeed; 40 zoomSpeed=inZoomSpeed; 39 41 RotY = 20; 40 42 RotZ = 0; … … 44 46 FollowMeCamera::~FollowMeCamera() {} 45 47 46 void FollowMeCamera::setPositionOffset(vector3df newpos) { pos_offset = newpos; } 48 void FollowMeCamera::setPositionOffset(vector3df newpos) { 49 pos_offset = ToIrrlichtCoordinates(newpos); 50 } 47 51 48 52 void FollowMeCamera::setTargetOffset(vector3df newpos) { 49 target_offset = newpos;53 target_offset = ToIrrlichtCoordinates(newpos); 50 54 } 51 55 … … 59 63 60 64 void FollowMeCamera::animateNode(ISceneNode *node, u32 timeMs) { 61 vector3df pos;62 65 63 66 float nRotY = RotY; … … 84 87 } 85 88 86 pos.X = -currentZoom; 89 float newCurrentZoom= 100+currentZoom * zoomSpeed; 90 if (newCurrentZoom <= 0) { 91 newCurrentZoom =zoomSpeed; 92 currentZoom =1-100/zoomSpeed; 93 } 94 95 vector3df pos; 96 pos.X = -newCurrentZoom; 87 97 pos.Y = 0; 88 98 pos.Z = 0; -
trunk/lib/FlairSimulator/src/Gui.h
r69 r70 52 52 class Gui : public core::Object { 53 53 friend class ::Simulator_impl; 54 friend class VisualizationCamera; 54 55 55 56 public: -
trunk/lib/FlairSimulator/src/Gui_impl.cpp
r69 r70 98 98 smgr->setAmbientLight(video::SColorf(1, 1, 1)); 99 99 100 /*101 // camera102 camera = smgr->addCameraSceneNode();103 104 camera->setAspectRatio(105 (float)scene_width / (float)scene_height); // on force a cause du view port106 107 camera->setUpVector(vector3df(0, 0, 1));108 109 FixedCamera* animator = new FixedCamera(vector3df(1,1,1));110 camera->addAnimator(animator);111 112 camera->setFarValue(8000);*/113 100 /* 114 101 env = device->getGUIEnvironment(); … … 146 133 delete receiver; 147 134 // printf("del Gui_impl ok\n"); 135 } 136 137 void Gui_impl::AddVisualizationCamera(VisualizationCamera* camera) { 138 cameras.push_back(camera); 148 139 } 149 140 … … 187 178 int cam_id = 0; 188 179 189 receiver->SetModel(models.at( cam_id));180 receiver->SetModel(models.at(0)); 190 181 191 182 for (size_t i = 0; i < models.size(); i++) { … … 213 204 } 214 205 215 setWindowCaption( models.at(0), 0);206 setWindowCaption(0, 0); 216 207 217 208 while (device->run()) { … … 247 238 248 239 // vue poursuite 249 smgr->setActiveCamera(models.at(cam_id)->getFollowMeCamera()->getCameraSceneNode()); 240 //smgr->setActiveCamera(models.at(cam_id)->getFollowMeCamera()->getCameraSceneNode()); 241 smgr->setActiveCamera(cameras.at(cam_id)->getCameraSceneNode()); 250 242 driver->setViewPort(core::rect<s32>(0, 0, scene_width, scene_height)); 251 243 smgr->drawAll(); // commente voir plus bas … … 279 271 // mais a priori souci avec models.at(i)->pimpl_->CheckCollision(); 280 272 // (setelipsoid?) 281 smgr->setActiveCamera(models.at(cam_id)->getFollowMeCamera()->getCameraSceneNode()); 273 //smgr->setActiveCamera(models.at(cam_id)->getFollowMeCamera()->getCameraSceneNode()); 274 smgr->setActiveCamera(cameras.at(cam_id)->getCameraSceneNode()); 282 275 driver->setViewPort(core::rect<s32>(0, 0, scene_width, scene_height)); 283 276 smgr->drawAll(); … … 286 279 287 280 int fps = driver->getFPS(); 288 // printf("fps %i\n",fps); 281 289 282 if (lastFPS != fps) { 290 setWindowCaption( models.at(cam_id), fps);283 setWindowCaption(cam_id, fps); 291 284 lastFPS = fps; 292 285 } … … 294 287 if (receiver->IsKeyDown(KEY_PRIOR)) { 295 288 cam_id++; 296 if (cam_id >= (int) models.size()) cam_id = 0;297 receiver->SetModel( models.at(cam_id));298 setWindowCaption( models.at(cam_id), fps);289 if (cam_id >= (int)cameras.size()) cam_id = 0; 290 receiver->SetModel(getModelFromVisualizationCamera(models,cameras.at(cam_id))); 291 setWindowCaption(cam_id, fps); 299 292 } 300 293 if (receiver->IsKeyDown(KEY_NEXT)) { 301 294 cam_id--; 302 if (cam_id < 0) cam_id = models.size() - 1;303 receiver->SetModel( models.at(cam_id));304 setWindowCaption( models.at(cam_id), fps);295 if (cam_id < 0) cam_id = cameras.size() - 1; 296 receiver->SetModel(getModelFromVisualizationCamera(models,cameras.at(cam_id))); 297 setWindowCaption(cam_id, fps); 305 298 } 306 299 … … 354 347 } 355 348 356 void Gui_impl::setWindowCaption(Object *object, int fps) { 349 Model *Gui_impl::getModelFromVisualizationCamera(std::vector<Model *> models,VisualizationCamera *camera) { 350 for (size_t i = 0; i < models.size(); i++) { 351 if(models.at(i)->getFollowMeCamera()==camera) return models.at(i); 352 } 353 return NULL; 354 } 355 356 void Gui_impl::setWindowCaption(int cam_id, int fps) { 357 357 std::ostringstream text; 358 text << "Cam: " << object->ObjectName().c_str() 359 << ", Kbd: " << object->ObjectName().c_str() << ", FPS: " << fps; 358 359 text << "Cam: " << cameras.at(cam_id)->getName().c_str() 360 << ", FPS: " << fps; 360 361 361 362 device->setWindowCaption(stringw(text.str().c_str()).c_str()); -
trunk/lib/FlairSimulator/src/Man.cpp
r69 r70 47 47 node->getMaterial(0).Lighting = false; 48 48 49 getFollowMeCamera()->setPositionOffset(vector3df(0, 0, 100));50 getFollowMeCamera()->setTargetOffset(vector3df(0, 0, 100));49 getFollowMeCamera()->setPositionOffset(vector3df(0, 0, -1)); 50 getFollowMeCamera()->setTargetOffset(vector3df(0, 0, -1)); 51 51 52 52 setTriangleSelector( -
trunk/lib/FlairSimulator/src/Model.cpp
r69 r70 19 19 #include "Simulator.h" 20 20 #include "Simulator_impl.h" 21 #include "FollowMeCamera.h"22 21 #include <DoubleSpinBox.h> 23 22 24 23 #ifdef GL 24 #include "FollowMeCamera.h" 25 25 #include "Gui.h" 26 26 #include <ICameraSceneNode.h> -
trunk/lib/FlairSimulator/src/Model_impl.cpp
r69 r70 83 83 84 84 // camera 85 camera = new FollowMeCamera(this );85 camera = new FollowMeCamera(this,name); 86 86 87 87 position_init = false; -
trunk/lib/FlairSimulator/src/VisualizationCamera.cpp
r69 r70 21 21 #include "Model_impl.h" 22 22 #include "Gui.h" 23 #include "Gui_impl.h" 23 24 #include <ICursorControl.h> 24 25 #include <ICameraSceneNode.h> … … 34 35 namespace simulator { 35 36 36 VisualizationCamera::VisualizationCamera(float inRotateSpeed,float inZoomSpeed) { 37 zoomSpeed = inZoomSpeed; 38 rotateSpeed = inRotateSpeed; 39 currentZoom = 100; 37 VisualizationCamera::VisualizationCamera(std::string inName) { 38 name=inName; 39 currentZoom = 0; 40 40 LMouseKey = false; 41 41 … … 46 46 camera->addAnimator(this); 47 47 camera->setFarValue(8000); 48 49 getGui()->pimpl_->AddVisualizationCamera(this); 48 50 } 49 51 50 52 VisualizationCamera::~VisualizationCamera() {} 53 54 std::string VisualizationCamera::getName(void) { 55 return name; 56 } 51 57 52 58 ICameraSceneNode *VisualizationCamera::getCameraSceneNode(void) { … … 66 72 67 73 case EMIE_MOUSE_WHEEL: 68 currentZoom -= event.MouseInput.Wheel * zoomSpeed; 69 if (currentZoom <= 0) 70 currentZoom = zoomSpeed; 74 currentZoom -= event.MouseInput.Wheel; 71 75 break; 72 76 case EMIE_LMOUSE_PRESSED_DOWN: -
trunk/lib/FlairSimulator/src/VisualizationCamera.h
r69 r70 21 21 #include <position2d.h> 22 22 #include <Vector3D.h> 23 #include <string> 23 24 24 25 namespace irr { … … 33 34 class VisualizationCamera : private irr::scene::ISceneNodeAnimator { 34 35 public: 35 VisualizationCamera( float rotateSpeed = -500.0f, float zoomSpeed = 4.0f);36 VisualizationCamera(std::string name); 36 37 ~VisualizationCamera(); 37 38 … … 40 41 virtual bool OnEvent(const irr::SEvent& event); 41 42 irr::scene::ICameraSceneNode *getCameraSceneNode(void); 43 std::string getName(void); 42 44 43 45 private: … … 48 50 irr::scene::ICameraSceneNode *camera; 49 51 irr::core::position2df MousePos; 50 float rotateSpeed;51 float zoomSpeed;52 52 float currentZoom; 53 std::string name; 53 54 }; 54 55 -
trunk/lib/FlairSimulator/src/unexported/FollowMeCamera.h
r69 r70 26 26 class FollowMeCamera : public VisualizationCamera { 27 27 public: 28 FollowMeCamera(const irr::scene::ISceneNode *parent, 28 FollowMeCamera(const irr::scene::ISceneNode *parent,std::string name, 29 29 float rotateSpeed = -500.0f, float zoomSpeed = 4.0f); 30 30 ~FollowMeCamera(); … … 41 41 float RotY, RotZ; 42 42 float sat(float value); 43 float rotateSpeed; 44 float zoomSpeed; 43 45 }; 44 46 -
trunk/lib/FlairSimulator/src/unexported/Gui_impl.h
r69 r70 30 30 class IMeshSceneNode; 31 31 class ITriangleSelector; 32 //class ICameraSceneNode;33 32 } 34 33 namespace video { … … 49 48 class GenericObject; 50 49 class Gui; 51 class FixedCamera;50 class VisualizationCamera; 52 51 } 53 52 } … … 61 60 irr::video::E_DRIVER_TYPE driver_type = irr::video::EDT_OPENGL); 62 61 ~Gui_impl(); 63 void RunGui(std::vector<flair::simulator::Model *> model es,62 void RunGui(std::vector<flair::simulator::Model *> models, 64 63 std::vector<flair::simulator::GenericObject *> objects); 65 64 void setMesh(std::string file, … … 74 73 irr::scene::ISceneManager *smgr; 75 74 int scene_width, scene_height; 75 void AddVisualizationCamera(flair::simulator::VisualizationCamera* camera); 76 76 77 77 private: … … 80 80 irr::gui::IGUIFont *font; 81 81 irr::gui::IGUIEnvironment *env; 82 void setWindowCaption( flair::core::Object *object, int fps);82 void setWindowCaption(int cam_id, int fps); 83 83 void takeScreenshot(void); 84 84 hdfile_t *dbtFile_r, *dbtFile_w; 85 85 size_t dbtSize(std::vector<flair::simulator::Model *> modeles); 86 86 char *dbtbuf; 87 flair::simulator::FixedCamera *fixedCamera;88 87 flair::simulator::Gui *self; 89 //irr::scene::ICameraSceneNode * camera; 88 std::vector<flair::simulator::VisualizationCamera *> cameras; 89 flair::simulator::Model *getModelFromVisualizationCamera(std::vector<flair::simulator::Model *> models,flair::simulator::VisualizationCamera *camera); 90 90 }; 91 91
Note:
See TracChangeset
for help on using the changeset viewer.