Changeset 70 in flair-src for trunk/lib/FlairSimulator


Ignore:
Timestamp:
Sep 6, 2016, 5:49:32 PM (8 years ago)
Author:
Sanahuja Guillaume
Message:

simu cameras

Location:
trunk/lib/FlairSimulator/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairSimulator/src/FixedCamera.cpp

    r69 r70  
    2525#include <IrrlichtDevice.h>
    2626#include <ISceneManager.h>
     27#include <Euler.h>
    2728
    2829using namespace irr;
     
    3435namespace simulator {
    3536
    36 FixedCamera::FixedCamera(core::Vector3D position,float rotateSpeed,float zoomSpeed):VisualizationCamera(rotateSpeed,zoomSpeed)  {
    37   RotY = 020;
     37FixedCamera::FixedCamera(std::string name,core::Vector3D position,float inRotateSpeed,float inZoomSpeed):VisualizationCamera(name)  {
     38  RotY = -90;
    3839  RotZ = 0;
    3940  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();
    4345}
    4446
    4547FixedCamera::~FixedCamera() {}
     48
     49float FixedCamera::sat(float value) {
     50  if (value >= -1)
     51    value = -1;
     52  if (value <= -179)
     53    value = -179;
     54  return value;
     55}
    4656
    4757void FixedCamera::animateNode(ISceneNode *node, u32 timeMs) {
     
    6070      nRotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
    6171      nRotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
     72      nRotY = sat(nRotY);
    6273    }
    6374  } else if (Rotating) {
    6475    RotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
    6576    RotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
     77    RotY = sat(RotY);
    6678    nRotY = RotY;
    6779    nRotZ = RotZ;
     
    6981  }
    7082
     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
    7193  camera->setRotation(vector3df(0,nRotY,nRotZ));
    7294  camera->bindTargetAndRotation(true);
     95  camera->setFOV(newFov);
    7396}
    7497
  • trunk/lib/FlairSimulator/src/FixedCamera.h

    r69 r70  
    2626class FixedCamera : public VisualizationCamera {
    2727public:
    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);
    2929  ~FixedCamera();
    3030
     
    3232
    3333private:
     34  float sat(float value);
    3435  irr::core::position2df RotateStart;
    3536  bool Rotating;
     37  float rotateSpeed;
     38  float zoomSpeed;
    3639  float RotY, RotZ;
     40  float fov;
    3741};
    3842
  • trunk/lib/FlairSimulator/src/FollowMeCamera.cpp

    r69 r70  
    3434namespace simulator {
    3535
    36 FollowMeCamera::FollowMeCamera(const ISceneNode *parent, float rotateSpeed,
    37                              float zoomSpeed):VisualizationCamera(rotateSpeed,zoomSpeed)  {
     36FollowMeCamera::FollowMeCamera(const ISceneNode *parent, std::string name,float inRotateSpeed,
     37                             float inZoomSpeed):VisualizationCamera(name)  {
    3838  this->parent = parent;
     39  rotateSpeed=inRotateSpeed;
     40  zoomSpeed=inZoomSpeed;
    3941  RotY = 20;
    4042  RotZ = 0;
     
    4446FollowMeCamera::~FollowMeCamera() {}
    4547
    46 void FollowMeCamera::setPositionOffset(vector3df newpos) { pos_offset = newpos; }
     48void FollowMeCamera::setPositionOffset(vector3df newpos) {
     49  pos_offset = ToIrrlichtCoordinates(newpos);
     50}
    4751
    4852void FollowMeCamera::setTargetOffset(vector3df newpos) {
    49   target_offset = newpos;
     53  target_offset = ToIrrlichtCoordinates(newpos);
    5054}
    5155
     
    5963
    6064void FollowMeCamera::animateNode(ISceneNode *node, u32 timeMs) {
    61   vector3df pos;
    6265
    6366  float nRotY = RotY;
     
    8487  }
    8588
    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;
    8797  pos.Y = 0;
    8898  pos.Z = 0;
  • trunk/lib/FlairSimulator/src/Gui.h

    r69 r70  
    5252class Gui : public core::Object {
    5353  friend class ::Simulator_impl;
     54  friend class VisualizationCamera;
    5455
    5556public:
  • trunk/lib/FlairSimulator/src/Gui_impl.cpp

    r69 r70  
    9898  smgr->setAmbientLight(video::SColorf(1, 1, 1));
    9999
    100 /*
    101    // camera
    102   camera = smgr->addCameraSceneNode();
    103 
    104   camera->setAspectRatio(
    105       (float)scene_width / (float)scene_height); // on force a cause du view port
    106 
    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);*/
    113100  /*
    114101env = device->getGUIEnvironment();
     
    146133  delete receiver;
    147134  // printf("del Gui_impl ok\n");
     135}
     136
     137void Gui_impl::AddVisualizationCamera(VisualizationCamera* camera) {
     138  cameras.push_back(camera);
    148139}
    149140
     
    187178  int cam_id = 0;
    188179
    189   receiver->SetModel(models.at(cam_id));
     180  receiver->SetModel(models.at(0));
    190181
    191182  for (size_t i = 0; i < models.size(); i++) {
     
    213204  }
    214205
    215   setWindowCaption(models.at(0), 0);
     206  setWindowCaption(0, 0);
    216207
    217208  while (device->run()) {
     
    247238
    248239    // 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());
    250242    driver->setViewPort(core::rect<s32>(0, 0, scene_width, scene_height));
    251243    smgr->drawAll(); // commente voir plus bas
     
    279271    // mais a priori souci avec models.at(i)->pimpl_->CheckCollision();
    280272    // (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());
    282275    driver->setViewPort(core::rect<s32>(0, 0, scene_width, scene_height));
    283276    smgr->drawAll();
     
    286279
    287280    int fps = driver->getFPS();
    288     // printf("fps %i\n",fps);
     281
    289282    if (lastFPS != fps) {
    290       setWindowCaption(models.at(cam_id), fps);
     283      setWindowCaption(cam_id, fps);
    291284      lastFPS = fps;
    292285    }
     
    294287    if (receiver->IsKeyDown(KEY_PRIOR)) {
    295288      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);
    299292    }
    300293    if (receiver->IsKeyDown(KEY_NEXT)) {
    301294      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);
    305298    }
    306299
     
    354347}
    355348
    356 void Gui_impl::setWindowCaption(Object *object, int fps) {
     349Model *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
     356void Gui_impl::setWindowCaption(int cam_id, int fps) {
    357357  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;
    360361
    361362  device->setWindowCaption(stringw(text.str().c_str()).c_str());
  • trunk/lib/FlairSimulator/src/Man.cpp

    r69 r70  
    4747  node->getMaterial(0).Lighting = false;
    4848
    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));
    5151
    5252  setTriangleSelector(
  • trunk/lib/FlairSimulator/src/Model.cpp

    r69 r70  
    1919#include "Simulator.h"
    2020#include "Simulator_impl.h"
    21 #include "FollowMeCamera.h"
    2221#include <DoubleSpinBox.h>
    2322
    2423#ifdef GL
     24#include "FollowMeCamera.h"
    2525#include "Gui.h"
    2626#include <ICameraSceneNode.h>
  • trunk/lib/FlairSimulator/src/Model_impl.cpp

    r69 r70  
    8383
    8484  // camera
    85   camera = new FollowMeCamera(this);
     85  camera = new FollowMeCamera(this,name);
    8686
    8787  position_init = false;
  • trunk/lib/FlairSimulator/src/VisualizationCamera.cpp

    r69 r70  
    2121#include "Model_impl.h"
    2222#include "Gui.h"
     23#include "Gui_impl.h"
    2324#include <ICursorControl.h>
    2425#include <ICameraSceneNode.h>
     
    3435namespace simulator {
    3536
    36 VisualizationCamera::VisualizationCamera(float inRotateSpeed,float inZoomSpeed) {
    37   zoomSpeed = inZoomSpeed;
    38   rotateSpeed = inRotateSpeed;
    39   currentZoom = 100;
     37VisualizationCamera::VisualizationCamera(std::string inName) {
     38  name=inName;
     39  currentZoom = 0;
    4040  LMouseKey = false;
    4141
     
    4646  camera->addAnimator(this);
    4747  camera->setFarValue(8000);
     48
     49  getGui()->pimpl_->AddVisualizationCamera(this);
    4850}
    4951
    5052VisualizationCamera::~VisualizationCamera() {}
     53
     54std::string VisualizationCamera::getName(void) {
     55  return name;
     56}
    5157
    5258ICameraSceneNode *VisualizationCamera::getCameraSceneNode(void) {
     
    6672
    6773  case EMIE_MOUSE_WHEEL:
    68     currentZoom -= event.MouseInput.Wheel * zoomSpeed;
    69     if (currentZoom <= 0)
    70       currentZoom = zoomSpeed;
     74    currentZoom -= event.MouseInput.Wheel;
    7175    break;
    7276  case EMIE_LMOUSE_PRESSED_DOWN:
  • trunk/lib/FlairSimulator/src/VisualizationCamera.h

    r69 r70  
    2121#include <position2d.h>
    2222#include <Vector3D.h>
     23#include <string>
    2324
    2425namespace irr {
     
    3334class VisualizationCamera : private irr::scene::ISceneNodeAnimator {
    3435public:
    35   VisualizationCamera(float rotateSpeed = -500.0f, float zoomSpeed = 4.0f);
     36  VisualizationCamera(std::string name);
    3637  ~VisualizationCamera();
    3738
     
    4041  virtual bool OnEvent(const irr::SEvent& event);
    4142  irr::scene::ICameraSceneNode *getCameraSceneNode(void);
     43  std::string getName(void);
    4244
    4345private:
     
    4850  irr::scene::ICameraSceneNode *camera;
    4951  irr::core::position2df MousePos;
    50   float rotateSpeed;
    51   float zoomSpeed;
    5252  float currentZoom;
     53  std::string name;
    5354};
    5455
  • trunk/lib/FlairSimulator/src/unexported/FollowMeCamera.h

    r69 r70  
    2626class FollowMeCamera : public VisualizationCamera {
    2727public:
    28   FollowMeCamera(const irr::scene::ISceneNode *parent,
     28  FollowMeCamera(const irr::scene::ISceneNode *parent,std::string name,
    2929                float rotateSpeed = -500.0f, float zoomSpeed = 4.0f);
    3030  ~FollowMeCamera();
     
    4141  float RotY, RotZ;
    4242  float sat(float value);
     43  float rotateSpeed;
     44  float zoomSpeed;
    4345};
    4446
  • trunk/lib/FlairSimulator/src/unexported/Gui_impl.h

    r69 r70  
    3030class IMeshSceneNode;
    3131class ITriangleSelector;
    32 //class ICameraSceneNode;
    3332}
    3433namespace video {
     
    4948class GenericObject;
    5049class Gui;
    51 class FixedCamera;
     50class VisualizationCamera;
    5251}
    5352}
     
    6160           irr::video::E_DRIVER_TYPE driver_type = irr::video::EDT_OPENGL);
    6261  ~Gui_impl();
    63   void RunGui(std::vector<flair::simulator::Model *> modeles,
     62  void RunGui(std::vector<flair::simulator::Model *> models,
    6463              std::vector<flair::simulator::GenericObject *> objects);
    6564  void setMesh(std::string file,
     
    7473  irr::scene::ISceneManager *smgr;
    7574  int scene_width, scene_height;
     75  void AddVisualizationCamera(flair::simulator::VisualizationCamera* camera);
    7676
    7777private:
     
    8080  irr::gui::IGUIFont *font;
    8181  irr::gui::IGUIEnvironment *env;
    82   void setWindowCaption(flair::core::Object *object, int fps);
     82  void setWindowCaption(int cam_id, int fps);
    8383  void takeScreenshot(void);
    8484  hdfile_t *dbtFile_r, *dbtFile_w;
    8585  size_t dbtSize(std::vector<flair::simulator::Model *> modeles);
    8686  char *dbtbuf;
    87   flair::simulator::FixedCamera *fixedCamera;
    8887  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);
    9090};
    9191
Note: See TracChangeset for help on using the changeset viewer.