Changeset 69 in flair-src


Ignore:
Timestamp:
Sep 2, 2016, 5:48:40 PM (4 years ago)
Author:
Sanahuja Guillaume
Message:

refonte camera simu

Location:
trunk/lib/FlairSimulator/src
Files:
4 added
14 edited
2 moved

Legend:

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

    r51 r69  
    44// %flair:license}
    55//  created:    2012/08/21
    6 //  filename:   AnimPoursuite.cpp
     6//  filename:   FollowMeCamera.cpp
    77//
    88//  author:     Guillaume Sanahuja
     
    1616#ifdef GL
    1717
    18 #include "AnimPoursuite.h"
     18#include "FollowMeCamera.h"
    1919#include "Simulator.h"
    2020#include "Model.h"
    2121#include "Model_impl.h"
     22#include "Gui.h"
    2223#include <ICursorControl.h>
    2324#include <ICameraSceneNode.h>
     25#include <IrrlichtDevice.h>
     26#include <ISceneManager.h>
    2427
    2528using namespace irr;
     
    3134namespace simulator {
    3235
    33 AnimPoursuite::AnimPoursuite(const ISceneNode *parent, float rotateSpeed,
    34                              float zoomSpeed) {
     36FollowMeCamera::FollowMeCamera(const ISceneNode *parent, float rotateSpeed,
     37                             float zoomSpeed):VisualizationCamera(rotateSpeed,zoomSpeed) {
    3538  this->parent = parent;
    36   this->zoomSpeed = zoomSpeed;
    37   this->rotateSpeed = rotateSpeed;
    38   currentZoom = 100;
    3939  RotY = 20;
    4040  RotZ = 0;
    4141  Rotating = false;
    42   LMouseKey = false;
    4342}
    4443
    45 AnimPoursuite::~AnimPoursuite() {}
     44FollowMeCamera::~FollowMeCamera() {}
    4645
    47 void AnimPoursuite::setPositionOffset(vector3df newpos) { pos_offset = newpos; }
     46void FollowMeCamera::setPositionOffset(vector3df newpos) { pos_offset = newpos; }
    4847
    49 void AnimPoursuite::setTargetOffset(vector3df newpos) {
     48void FollowMeCamera::setTargetOffset(vector3df newpos) {
    5049  target_offset = newpos;
    5150}
    5251
    53 float AnimPoursuite::sat(float value) {
     52float FollowMeCamera::sat(float value) {
    5453  if (value > 89)
    5554    value = 89;
     
    5958}
    6059
    61 void AnimPoursuite::animateNode(ISceneNode *node, u32 timeMs) {
    62   ICameraSceneNode *camera = static_cast<ICameraSceneNode *>(node);
     60void FollowMeCamera::animateNode(ISceneNode *node, u32 timeMs) {
    6361  vector3df pos;
    6462
     
    9795}
    9896
    99 ISceneNodeAnimator *AnimPoursuite::createClone(ISceneNode *node,
    100                                                ISceneManager *newManager) {
    101   return NULL;
    102 }
    103 
    104 bool AnimPoursuite::MouseMoved(const SEvent &event,
    105                                irr::core::position2df MousePos) {
    106   if (event.EventType != EET_MOUSE_INPUT_EVENT)
    107     return false;
    108 
    109   switch (event.MouseInput.Event) {
    110 
    111   case EMIE_MOUSE_WHEEL:
    112     currentZoom -= event.MouseInput.Wheel * zoomSpeed;
    113     if (currentZoom <= 0)
    114       currentZoom = zoomSpeed;
    115     break;
    116   case EMIE_LMOUSE_PRESSED_DOWN:
    117     LMouseKey = true;
    118     break;
    119   case EMIE_LMOUSE_LEFT_UP:
    120     LMouseKey = false;
    121     break;
    122   case EMIE_MOUSE_MOVED:
    123     this->MousePos = MousePos;
    124     break;
    125   default:
    126     return false;
    127     break;
    128   }
    129 
    130   return true;
    131 }
    13297
    13398} // end namespace simulator
  • trunk/lib/FlairSimulator/src/GenericObject.cpp

    r15 r69  
    1919#include "Simulator_impl.h"
    2020
    21 #include "ConditionVariable.h"
    2221#include "Quaternion.h"
    23 #include "Gui.h"
    24 #include "Gui_impl.h"
    25 #include <IMesh.h>
    2622#include <ISceneManager.h>
    27 #include <IMetaTriangleSelector.h>
    28 #include <IVideoDriver.h>
    29 #include "AnimPoursuite.h"
     23
    3024using namespace irr;
    3125using namespace video;
    3226using namespace scene;
    3327using namespace core;
    34 using namespace io;
    3528
    3629using namespace flair::core;
  • trunk/lib/FlairSimulator/src/Gui.cpp

    r45 r69  
    1919#include "Gui_impl.h"
    2020#include "Simulator.h"
    21 #include "Simulator_impl.h"
    2221#include "Model.h"
    23 #include "Model_impl.h"
    24 #include "AnimPoursuite.h"
    25 #include <Euler.h>
    26 #include <Object.h>
    2722#include <IMeshSceneNode.h>
    2823#include <IVideoDriver.h>
    2924#include <ISceneManager.h>
    30 #include <unistd.h>
    3125#include <algorithm>
    3226#include <GL/gl.h>
     
    3731
    3832void constructor() {
    39   compile_info("FlairSensorActuator");
     33  compile_info("FlairSimulator");
    4034}
    4135
  • trunk/lib/FlairSimulator/src/Gui.h

    r15 r69  
    6262  irr::scene::IAnimatedMesh *getMesh(std::string filename) const;
    6363  irr::scene::ISceneManager *getSceneManager(void) const;
     64  irr::IrrlichtDevice *getDevice(void) const;
    6465  float getAspectRatio(void) const;
    6566
    6667protected:
    67   irr::IrrlichtDevice *getDevice(void) const;
    6868  void setMesh(std::string file,
    6969               irr::core::vector3df position = irr::core::vector3df(0, 0, 0),
  • trunk/lib/FlairSimulator/src/Gui_impl.cpp

    r15 r69  
    2222#include "Model.h"
    2323#include "Model_impl.h"
    24 #include "AnimPoursuite.h"
    2524#include <Object.h>
    2625#include <Euler.h>
     
    4039public:
    4140  // This is the one method that we have to implement
    42   virtual bool OnEvent(const SEvent &event) {
     41  bool OnEvent(const SEvent &event) {
    4342    // Remember whether each key is down or up
    4443    if (event.EventType == EET_KEY_INPUT_EVENT)
    4544      KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
    4645
    47     // Send all other events to camera
    48     if (event.EventType == EET_MOUSE_INPUT_EVENT && camera)
    49       // return camera->OnEvent(event);
    50       return camera->MouseMoved(event, cursorControl->getRelativePosition());
    51 
    5246    if (model)
    5347      return model->OnEvent(event);
     
    5751
    5852  // This is used to check whether a key is being held down
    59   virtual bool IsKeyDown(EKEY_CODE keyCode) {
     53  bool IsKeyDown(EKEY_CODE keyCode) {
    6054    if (KeyIsDown[keyCode] == true) {
    6155      KeyIsDown[keyCode] = false;
     
    6660  }
    6761
    68   MyEventReceiver(ICursorControl *cursorControl) {
    69     this->cursorControl = cursorControl;
    70     camera = NULL;
     62  MyEventReceiver(void) {
    7163    model = NULL;
    7264    for (u32 i = 0; i < KEY_KEY_CODES_COUNT; ++i)
    7365      KeyIsDown[i] = false;
    7466  }
    75   void SetCamera(AnimPoursuite *camera) { this->camera = camera; }
    7667  void SetModel(Model *model) { this->model = model; }
    7768
     
    7970  // We use this array to store the current state of each key
    8071  bool KeyIsDown[KEY_KEY_CODES_COUNT];
    81   AnimPoursuite *camera;
    8272  Model *model;
    83   ICursorControl *cursorControl;
    8473};
    8574
     
    9685  device = createDevice(driver_type, dimension2d<u32>(app_width, app_height),
    9786                        16, false, false, false);
    98   receiver = new MyEventReceiver(device->getCursorControl());
     87  receiver = new MyEventReceiver();
    9988  device->setEventReceiver(receiver);
    10089  device->getLogger()->setLogLevel(ELL_NONE);
     
    10998  smgr->setAmbientLight(video::SColorf(1, 1, 1));
    11099
     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);*/
    111113  /*
    112114env = device->getGUIEnvironment();
     
    185187  int cam_id = 0;
    186188
    187   receiver->SetCamera(models.at(cam_id)->pimpl_->animator);
    188189  receiver->SetModel(models.at(cam_id));
    189190
     
    199200    }
    200201    for (size_t j = 0; j < models.size(); j++) {
    201       if (i == j)
    202         continue;
     202      if (i == j) continue;
    203203      models.at(i)->pimpl_->MetaTriangleSelector()->addTriangleSelector(
    204204          models.at(j)->pimpl_->TriangleSelector());
     
    247247
    248248    // vue poursuite
    249     smgr->setActiveCamera(models.at(cam_id)->pimpl_->camera);
     249    smgr->setActiveCamera(models.at(cam_id)->getFollowMeCamera()->getCameraSceneNode());
    250250    driver->setViewPort(core::rect<s32>(0, 0, scene_width, scene_height));
    251251    smgr->drawAll(); // commente voir plus bas
     
    279279    // mais a priori souci avec models.at(i)->pimpl_->CheckCollision();
    280280    // (setelipsoid?)
    281     smgr->setActiveCamera(models.at(cam_id)->pimpl_->camera);
     281    smgr->setActiveCamera(models.at(cam_id)->getFollowMeCamera()->getCameraSceneNode());
    282282    driver->setViewPort(core::rect<s32>(0, 0, scene_width, scene_height));
    283283    smgr->drawAll();
     
    294294    if (receiver->IsKeyDown(KEY_PRIOR)) {
    295295      cam_id++;
    296       if (cam_id >= (int)models.size())
    297         cam_id = 0;
    298       receiver->SetCamera(models.at(cam_id)->pimpl_->animator);
     296      if (cam_id >= (int)models.size()) cam_id = 0;
    299297      receiver->SetModel(models.at(cam_id));
    300298      setWindowCaption(models.at(cam_id), fps);
     
    302300    if (receiver->IsKeyDown(KEY_NEXT)) {
    303301      cam_id--;
    304       if (cam_id < 0)
    305         cam_id = models.size() - 1;
    306       receiver->SetCamera(models.at(cam_id)->pimpl_->animator);
     302      if (cam_id < 0) cam_id = models.size() - 1;
    307303      receiver->SetModel(models.at(cam_id));
    308304      setWindowCaption(models.at(cam_id), fps);
     
    355351  }
    356352
    357   receiver->SetCamera(NULL);
    358353  receiver->SetModel(NULL);
    359354}
  • trunk/lib/FlairSimulator/src/Man.cpp

    r15 r69  
    2525#include <Tab.h>
    2626#include <DoubleSpinBox.h>
    27 #include "AnimPoursuite.h"
     27#include "FollowMeCamera.h"
    2828
    2929using namespace irr;
     
    4747  node->getMaterial(0).Lighting = false;
    4848
    49   getCamera()->setPositionOffset(vector3df(0, 0, 100));
    50   getCamera()->setTargetOffset(vector3df(0, 0, 100));
     49  getFollowMeCamera()->setPositionOffset(vector3df(0, 0, 100));
     50  getFollowMeCamera()->setTargetOffset(vector3df(0, 0, 100));
    5151
    5252  setTriangleSelector(
  • trunk/lib/FlairSimulator/src/Model.cpp

    r15 r69  
    1919#include "Simulator.h"
    2020#include "Simulator_impl.h"
     21#include "FollowMeCamera.h"
    2122#include <DoubleSpinBox.h>
    2223
     
    6364aabbox3d<f32> *Model::Box() const { return &(pimpl_->box); }
    6465
    65 AnimPoursuite *Model::getCamera(void) const { return pimpl_->animator; }
     66FollowMeCamera *Model::getFollowMeCamera(void) const { return pimpl_->camera; }
    6667
    6768void Model::setTriangleSelector(ITriangleSelector *selector) {
     
    7172}
    7273
    73 void Model::setCameraFarValue(float zf) { pimpl_->camera->setFarValue(zf); }
     74void Model::setCameraFarValue(float zf) { pimpl_->camera->getCameraSceneNode()->setFarValue(zf); }
    7475#endif
    7576
  • trunk/lib/FlairSimulator/src/Model.h

    r15 r69  
    2525#ifdef GL
    2626#include <aabbox3d.h>
     27#include <IEventReceiver.h>
    2728namespace irr {
    2829class SEvent;
     
    5152namespace simulator {
    5253class Simulator;
    53 class AnimPoursuite;
     54class FollowMeCamera;
    5455
    55 class Model : public core::IODevice {
     56class Model : public core::IODevice
     57#ifdef GL
     58, public irr::IEventReceiver
     59#endif
     60 {
    5661  friend class ::Gui_impl;
    5762  friend class ::Simulator_impl;
    5863  friend class ::Model_impl;
    59   friend class AnimPoursuite;
    6064  friend class sensor::SensorGL;
    6165
     
    8084  virtual void WritedbtBuf(char *dbtbuf) = 0;
    8185  virtual void ReaddbtBuf(char *dbtbuf) = 0;
    82   virtual bool OnEvent(const irr::SEvent &event) = 0;
     86
     87  //default event handling
     88  bool OnEvent(const irr::SEvent &event) { return false;};
    8389
    8490  //! Sets the value of the camera's far clipping plane (default: 2000.0f)
     
    9399  virtual void CalcModel(void) = 0;
    94100#ifdef GL
    95   AnimPoursuite *getCamera(void) const;
     101  FollowMeCamera *getFollowMeCamera(void) const;
    96102  virtual void AnimateModel(void) = 0;
    97103  // void setPosition(core::Vector3D pos);
  • trunk/lib/FlairSimulator/src/Model_impl.cpp

    r15 r69  
    3737#include <IVideoDriver.h>
    3838#include <ICameraSceneNode.h>
    39 #include "AnimPoursuite.h"
     39#include "FollowMeCamera.h"
     40
    4041using namespace irr;
    4142using namespace video;
     
    8283
    8384  // camera
    84   camera = getSceneManager()->addCameraSceneNode();
    85   camera->setAspectRatio(
    86       getGui()->getAspectRatio()); // on force a cause du view port
    87   camera->setUpVector(vector3df(0, 0, 1));
    88 
    89   animator = new AnimPoursuite(this);
    90   camera->addAnimator(animator);
    91   camera->setFarValue(8000);
     85  camera = new FollowMeCamera(this);
    9286
    9387  position_init = false;
  • trunk/lib/FlairSimulator/src/Parser.cpp

    r15 r69  
    2020#include "GenericObject.h"
    2121#include <vector3d.h>
    22 #include <irrlicht.h>
     22#include <IrrlichtDevice.h>
     23#include <IFileSystem.h>
    2324#include "GenericObject.h"
    2425
  • trunk/lib/FlairSimulator/src/X4.h

    r15 r69  
    6666  void CalcModel(void);
    6767#ifdef GL
    68   bool OnEvent(const irr::SEvent &event){};
    6968  void AnimateModel(void);
    7069  size_t dbtSize(void) const;
  • trunk/lib/FlairSimulator/src/X8.h

    r15 r69  
    6666  void CalcModel(void);
    6767#ifdef GL
    68   bool OnEvent(const irr::SEvent &event){};
    6968  void AnimateModel(void);
    7069  size_t dbtSize(void) const;
  • trunk/lib/FlairSimulator/src/unexported/FollowMeCamera.h

    r51 r69  
    44// %flair:license}
    55//  created:    2012/08/21
    6 //  filename:   AnimPoursuite.h
     6//  filename:   FollowMeCamera.h
    77//
    88//  author:     Guillaume Sanahuja
     
    1515/*********************************************************************/
    1616
    17 #ifndef ANIMPOURSUITE_H
    18 #define ANIMPOURSUITE_H
     17#ifndef FOLLOWMECAMERA_H
     18#define FOLLOWMECAMERA_H
    1919
    20 #include <ISceneNodeAnimator.h>
    21 #include <position2d.h>
    22 #include <vector3d.h>
     20#include "VisualizationCamera.h"
     21
    2322
    2423namespace flair {
    2524namespace simulator {
    2625
    27 class AnimPoursuite : public irr::scene::ISceneNodeAnimator {
     26class FollowMeCamera : public VisualizationCamera {
    2827public:
    29   AnimPoursuite(const irr::scene::ISceneNode *parent,
     28  FollowMeCamera(const irr::scene::ISceneNode *parent,
    3029                float rotateSpeed = -500.0f, float zoomSpeed = 4.0f);
    31   ~AnimPoursuite();
     30  ~FollowMeCamera();
    3231
    3332  void animateNode(irr::scene::ISceneNode *node, irr::u32 timeMs);
    34   ISceneNodeAnimator *createClone(irr::scene::ISceneNode *node,
    35                                   irr::scene::ISceneManager *newManager = 0);
    36   bool MouseMoved(const irr::SEvent &event, irr::core::position2df MousePos);
    3733  void setPositionOffset(irr::core::vector3df newpos);
    3834  void setTargetOffset(irr::core::vector3df newpos);
    3935
    4036private:
    41   virtual bool isEventReceiverEnabled(void) const { return true; }
    42 
    4337  irr::core::vector3df pos_offset, target_offset;
    44   bool LMouseKey;
    4538  irr::core::position2df RotateStart;
    46   irr::core::position2df MousePos;
    4739  const irr::scene::ISceneNode *parent;
    4840  bool Rotating;
    4941  float RotY, RotZ;
    50   float rotateSpeed;
    51   float zoomSpeed;
    52   float currentZoom;
    5342  float sat(float value);
    5443};
     
    5746} // end namespace flair
    5847
    59 #endif // ANIMPOURSUITE_H
     48#endif // FOLLOWMECAMERA_H
  • trunk/lib/FlairSimulator/src/unexported/GenericObject.h

    r15 r69  
    2929#include <IVideoDriver.h>
    3030#include <ICameraSceneNode.h>
    31 #include "AnimPoursuite.h"
     31#include "FollowMeCamera.h"
    3232
    3333#include <IODevice.h>
  • trunk/lib/FlairSimulator/src/unexported/Gui_impl.h

    r15 r69  
    3030class IMeshSceneNode;
    3131class ITriangleSelector;
     32//class ICameraSceneNode;
    3233}
    3334namespace video {
     
    4849class GenericObject;
    4950class Gui;
     51class FixedCamera;
    5052}
    5153}
     
    8385  size_t dbtSize(std::vector<flair::simulator::Model *> modeles);
    8486  char *dbtbuf;
     87  flair::simulator::FixedCamera *fixedCamera;
    8588  flair::simulator::Gui *self;
     89  //irr::scene::ICameraSceneNode * camera;
    8690};
    8791
  • trunk/lib/FlairSimulator/src/unexported/Model_impl.h

    r15 r69  
    3838namespace simulator {
    3939class Simulator;
    40 class AnimPoursuite;
     40class FollowMeCamera;
    4141}
    4242}
     
    5252class IMetaTriangleSelector;
    5353class ISceneNodeAnimatorCollisionResponse;
    54 class ICameraSceneNode;
    5554}
    5655}
     
    9493  irr::core::aabbox3d<irr::f32> box;
    9594  void SynchronizationPoint();
    96   irr::scene::ICameraSceneNode *camera;
    97   flair::simulator::AnimPoursuite *animator;
     95  flair::simulator::FollowMeCamera *camera;
    9896  irr::scene::ITriangleSelector *selector;
    9997#endif
Note: See TracChangeset for help on using the changeset viewer.