[10] | 1 | // %flair:license{
|
---|
[15] | 2 | // This file is part of the Flair framework distributed under the
|
---|
| 3 | // CECILL-C License, Version 1.0.
|
---|
[10] | 4 | // %flair:license}
|
---|
[8] | 5 | // created: 2012/08/21
|
---|
| 6 | // filename: AnimPoursuite.cpp
|
---|
| 7 | //
|
---|
| 8 | // author: Guillaume Sanahuja
|
---|
| 9 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
| 10 | //
|
---|
| 11 | // version: $Id: $
|
---|
| 12 | //
|
---|
| 13 | // purpose: classe definissant une animation poursuite pour camera
|
---|
| 14 | //
|
---|
| 15 | /*********************************************************************/
|
---|
| 16 | #ifdef GL
|
---|
| 17 |
|
---|
| 18 | #include "AnimPoursuite.h"
|
---|
| 19 | #include "Simulator.h"
|
---|
| 20 | #include "Model.h"
|
---|
| 21 | #include "Model_impl.h"
|
---|
| 22 | #include <ICursorControl.h>
|
---|
| 23 | #include <ICameraSceneNode.h>
|
---|
| 24 |
|
---|
| 25 | using namespace irr;
|
---|
| 26 | using namespace gui;
|
---|
| 27 | using namespace core;
|
---|
| 28 | using namespace scene;
|
---|
| 29 |
|
---|
[15] | 30 | namespace flair {
|
---|
| 31 | namespace simulator {
|
---|
[8] | 32 |
|
---|
[15] | 33 | AnimPoursuite::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;
|
---|
[8] | 43 | }
|
---|
| 44 |
|
---|
[15] | 45 | AnimPoursuite::~AnimPoursuite() {}
|
---|
[8] | 46 |
|
---|
[15] | 47 | void AnimPoursuite::setPositionOffset(vector3df newpos) { pos_offset = newpos; }
|
---|
[8] | 48 |
|
---|
[15] | 49 | void AnimPoursuite::setTargetOffset(vector3df newpos) {
|
---|
| 50 | target_offset = newpos;
|
---|
[8] | 51 | }
|
---|
| 52 |
|
---|
[15] | 53 | float AnimPoursuite::sat(float value) {
|
---|
| 54 | if (value > 89)
|
---|
| 55 | value = 89;
|
---|
| 56 | if (value < -89)
|
---|
| 57 | value = -89;
|
---|
| 58 | return value;
|
---|
[8] | 59 | }
|
---|
| 60 |
|
---|
[15] | 61 | void AnimPoursuite::animateNode(ISceneNode *node, u32 timeMs) {
|
---|
| 62 | ICameraSceneNode *camera = static_cast<ICameraSceneNode *>(node);
|
---|
| 63 | vector3df pos;
|
---|
[8] | 64 |
|
---|
[15] | 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);
|
---|
[8] | 78 | }
|
---|
[15] | 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 | }
|
---|
[8] | 87 |
|
---|
[15] | 88 | pos.X = -currentZoom;
|
---|
| 89 | pos.Y = 0;
|
---|
| 90 | pos.Z = 0;
|
---|
[8] | 91 |
|
---|
[15] | 92 | pos.rotateXZBy(-nRotY);
|
---|
| 93 | pos.rotateXYBy(getSimulator()->Yaw() + nRotZ + parent->getRotation().Z);
|
---|
[8] | 94 |
|
---|
[15] | 95 | camera->setPosition(parent->getPosition() + pos + pos_offset);
|
---|
| 96 | camera->setTarget(parent->getPosition() + target_offset);
|
---|
[8] | 97 | }
|
---|
| 98 |
|
---|
[15] | 99 | ISceneNodeAnimator *AnimPoursuite::createClone(ISceneNode *node,
|
---|
| 100 | ISceneManager *newManager) {
|
---|
| 101 | return NULL;
|
---|
[8] | 102 | }
|
---|
| 103 |
|
---|
[15] | 104 | bool AnimPoursuite::MouseMoved(const SEvent &event,
|
---|
| 105 | irr::core::position2df MousePos) {
|
---|
| 106 | if (event.EventType != EET_MOUSE_INPUT_EVENT)
|
---|
| 107 | return false;
|
---|
[8] | 108 |
|
---|
[15] | 109 | switch (event.MouseInput.Event) {
|
---|
[8] | 110 |
|
---|
[15] | 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 | }
|
---|
[8] | 129 |
|
---|
[15] | 130 | return true;
|
---|
[8] | 131 | }
|
---|
| 132 |
|
---|
| 133 | } // end namespace simulator
|
---|
| 134 | } // end namespace flair
|
---|
| 135 |
|
---|
[15] | 136 | #endif // GL
|
---|