Ignore:
Timestamp:
04/08/16 15:40:57 (6 years ago)
Author:
Bayard Gildas
Message:

sources reformatted with flair-format-dir script

File:
1 edited

Legend:

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

    r10 r15  
    2828using namespace scene;
    2929
    30 namespace flair
    31 {
    32 namespace simulator
    33 {
     30namespace flair {
     31namespace simulator {
    3432
    35 AnimPoursuite::AnimPoursuite(const ISceneNode* parent,float rotateSpeed , float zoomSpeed )
    36 {
    37     this->parent=parent;
    38     this->zoomSpeed=zoomSpeed;
    39     this->rotateSpeed=rotateSpeed;
    40     currentZoom=100;
    41     RotY=20;
    42     RotZ=0;
    43     Rotating=false;
    44     LMouseKey= false;
     33AnimPoursuite::AnimPoursuite(const ISceneNode *parent, float rotateSpeed,
     34                             float zoomSpeed) {
     35  this->parent = parent;
     36  this->zoomSpeed = zoomSpeed;
     37  this->rotateSpeed = rotateSpeed;
     38  currentZoom = 100;
     39  RotY = 20;
     40  RotZ = 0;
     41  Rotating = false;
     42  LMouseKey = false;
    4543}
    4644
    47 AnimPoursuite::~AnimPoursuite()
    48 {
     45AnimPoursuite::~AnimPoursuite() {}
    4946
     47void AnimPoursuite::setPositionOffset(vector3df newpos) { pos_offset = newpos; }
     48
     49void AnimPoursuite::setTargetOffset(vector3df newpos) {
     50  target_offset = newpos;
    5051}
    5152
    52 void AnimPoursuite::setPositionOffset(vector3df newpos)
    53 {
    54     pos_offset=newpos;
     53float AnimPoursuite::sat(float value) {
     54  if (value > 89)
     55    value = 89;
     56  if (value < -89)
     57    value = -89;
     58  return value;
    5559}
    5660
    57 void AnimPoursuite::setTargetOffset(vector3df newpos)
    58 {
    59     target_offset=newpos;
     61void AnimPoursuite::animateNode(ISceneNode *node, u32 timeMs) {
     62  ICameraSceneNode *camera = static_cast<ICameraSceneNode *>(node);
     63  vector3df pos;
     64
     65  float nRotY = RotY;
     66  float nRotZ = RotZ;
     67
     68  if (LMouseKey == true) {
     69    if (!Rotating) {
     70      RotateStart = MousePos;
     71      Rotating = true;
     72      nRotY = RotY;
     73      nRotZ = RotZ;
     74    } else {
     75      nRotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
     76      nRotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
     77      nRotY = sat(nRotY);
     78    }
     79  } else if (Rotating) {
     80    RotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
     81    RotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
     82    RotY = sat(RotY);
     83    nRotY = RotY;
     84    nRotZ = RotZ;
     85    Rotating = false;
     86  }
     87
     88  pos.X = -currentZoom;
     89  pos.Y = 0;
     90  pos.Z = 0;
     91
     92  pos.rotateXZBy(-nRotY);
     93  pos.rotateXYBy(getSimulator()->Yaw() + nRotZ + parent->getRotation().Z);
     94
     95  camera->setPosition(parent->getPosition() + pos + pos_offset);
     96  camera->setTarget(parent->getPosition() + target_offset);
    6097}
    6198
    62 float AnimPoursuite::sat(float value)
    63 {
    64     if(value>89) value=89;
    65     if(value<-89) value=-89;
    66     return value;
     99ISceneNodeAnimator *AnimPoursuite::createClone(ISceneNode *node,
     100                                               ISceneManager *newManager) {
     101  return NULL;
    67102}
    68103
    69 void AnimPoursuite::animateNode(ISceneNode* node, u32 timeMs)
    70 {
    71     ICameraSceneNode* camera = static_cast<ICameraSceneNode*>(node);
    72     vector3df pos;
     104bool AnimPoursuite::MouseMoved(const SEvent &event,
     105                               irr::core::position2df MousePos) {
     106  if (event.EventType != EET_MOUSE_INPUT_EVENT)
     107    return false;
    73108
    74     float nRotY = RotY;
    75     float nRotZ = RotZ;
     109  switch (event.MouseInput.Event) {
    76110
    77     if (LMouseKey==true)
    78     {
    79         if (!Rotating)
    80         {
    81             RotateStart = MousePos;
    82             Rotating = true;
    83             nRotY = RotY;
    84             nRotZ = RotZ;
    85         }
    86         else
    87         {
    88             nRotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
    89             nRotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
    90             nRotY=sat(nRotY);
    91         }
    92     }
    93     else if (Rotating)
    94     {
    95         RotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
    96         RotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
    97         RotY=sat(RotY);
    98         nRotY = RotY;
    99         nRotZ = RotZ;
    100         Rotating = false;
    101     }
     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  }
    102129
    103     pos.X = -currentZoom;
    104     pos.Y=0;
    105     pos.Z=0;
    106 
    107     pos.rotateXZBy(-nRotY);
    108     pos.rotateXYBy(getSimulator()->Yaw()+nRotZ+parent->getRotation().Z);
    109 
    110     camera->setPosition(parent->getPosition()+pos+pos_offset);
    111     camera->setTarget(parent->getPosition()+target_offset);
    112 }
    113 
    114 ISceneNodeAnimator* AnimPoursuite::createClone(ISceneNode* node,
    115             ISceneManager* newManager)
    116 {
    117     return NULL;
    118 }
    119 
    120 bool AnimPoursuite::MouseMoved(const SEvent& event,irr::core::position2df MousePos)
    121 {
    122     if (event.EventType != EET_MOUSE_INPUT_EVENT)
    123         return false;
    124 
    125     switch(event.MouseInput.Event)
    126     {
    127 
    128     case EMIE_MOUSE_WHEEL:
    129         currentZoom -= event.MouseInput.Wheel * zoomSpeed;
    130         if(currentZoom<=0) currentZoom=zoomSpeed;
    131         break;
    132     case EMIE_LMOUSE_PRESSED_DOWN:
    133         LMouseKey = true;
    134         break;
    135     case EMIE_LMOUSE_LEFT_UP:
    136         LMouseKey= false;
    137         break;
    138     case EMIE_MOUSE_MOVED:
    139         this->MousePos = MousePos;
    140         break;
    141     default:
    142         return false;
    143         break;
    144     }
    145 
    146     return true;
     130  return true;
    147131}
    148132
     
    150134} // end namespace flair
    151135
    152 #endif //GL
     136#endif // GL
Note: See TracChangeset for help on using the changeset viewer.