[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
|
---|
[69] | 6 | // filename: FollowMeCamera.cpp
|
---|
[8] | 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 |
|
---|
[69] | 18 | #include "FollowMeCamera.h"
|
---|
[8] | 19 | #include "Simulator.h"
|
---|
| 20 | #include "Model.h"
|
---|
| 21 | #include "Model_impl.h"
|
---|
[69] | 22 | #include "Gui.h"
|
---|
[8] | 23 | #include <ICursorControl.h>
|
---|
| 24 | #include <ICameraSceneNode.h>
|
---|
[69] | 25 | #include <IrrlichtDevice.h>
|
---|
| 26 | #include <ISceneManager.h>
|
---|
[8] | 27 |
|
---|
| 28 | using namespace irr;
|
---|
| 29 | using namespace gui;
|
---|
| 30 | using namespace core;
|
---|
| 31 | using namespace scene;
|
---|
| 32 |
|
---|
[15] | 33 | namespace flair {
|
---|
| 34 | namespace simulator {
|
---|
[8] | 35 |
|
---|
[70] | 36 | FollowMeCamera::FollowMeCamera(const ISceneNode *parent, std::string name,float inRotateSpeed,
|
---|
| 37 | float inZoomSpeed):VisualizationCamera(name) {
|
---|
[15] | 38 | this->parent = parent;
|
---|
[70] | 39 | rotateSpeed=inRotateSpeed;
|
---|
| 40 | zoomSpeed=inZoomSpeed;
|
---|
[15] | 41 | RotY = 20;
|
---|
| 42 | RotZ = 0;
|
---|
| 43 | Rotating = false;
|
---|
[8] | 44 | }
|
---|
| 45 |
|
---|
[69] | 46 | FollowMeCamera::~FollowMeCamera() {}
|
---|
[8] | 47 |
|
---|
[70] | 48 | void FollowMeCamera::setPositionOffset(vector3df newpos) {
|
---|
| 49 | pos_offset = ToIrrlichtCoordinates(newpos);
|
---|
| 50 | }
|
---|
[8] | 51 |
|
---|
[69] | 52 | void FollowMeCamera::setTargetOffset(vector3df newpos) {
|
---|
[70] | 53 | target_offset = ToIrrlichtCoordinates(newpos);
|
---|
[8] | 54 | }
|
---|
| 55 |
|
---|
[69] | 56 | float FollowMeCamera::sat(float value) {
|
---|
[15] | 57 | if (value > 89)
|
---|
| 58 | value = 89;
|
---|
| 59 | if (value < -89)
|
---|
| 60 | value = -89;
|
---|
| 61 | return value;
|
---|
[8] | 62 | }
|
---|
| 63 |
|
---|
[69] | 64 | void FollowMeCamera::animateNode(ISceneNode *node, u32 timeMs) {
|
---|
[8] | 65 |
|
---|
[15] | 66 | float nRotY = RotY;
|
---|
| 67 | float nRotZ = RotZ;
|
---|
| 68 |
|
---|
| 69 | if (LMouseKey == true) {
|
---|
| 70 | if (!Rotating) {
|
---|
| 71 | RotateStart = MousePos;
|
---|
| 72 | Rotating = true;
|
---|
| 73 | nRotY = RotY;
|
---|
| 74 | nRotZ = RotZ;
|
---|
| 75 | } else {
|
---|
| 76 | nRotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
|
---|
| 77 | nRotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
|
---|
| 78 | nRotY = sat(nRotY);
|
---|
[8] | 79 | }
|
---|
[15] | 80 | } else if (Rotating) {
|
---|
| 81 | RotY += (RotateStart.Y - MousePos.Y) * rotateSpeed;
|
---|
| 82 | RotZ += (RotateStart.X - MousePos.X) * rotateSpeed;
|
---|
| 83 | RotY = sat(RotY);
|
---|
| 84 | nRotY = RotY;
|
---|
| 85 | nRotZ = RotZ;
|
---|
| 86 | Rotating = false;
|
---|
| 87 | }
|
---|
[8] | 88 |
|
---|
[70] | 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;
|
---|
[15] | 97 | pos.Y = 0;
|
---|
| 98 | pos.Z = 0;
|
---|
[8] | 99 |
|
---|
[15] | 100 | pos.rotateXZBy(-nRotY);
|
---|
| 101 | pos.rotateXYBy(getSimulator()->Yaw() + nRotZ + parent->getRotation().Z);
|
---|
[8] | 102 |
|
---|
[15] | 103 | camera->setPosition(parent->getPosition() + pos + pos_offset);
|
---|
| 104 | camera->setTarget(parent->getPosition() + target_offset);
|
---|
[8] | 105 | }
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | } // end namespace simulator
|
---|
| 109 | } // end namespace flair
|
---|
| 110 |
|
---|
[15] | 111 | #endif // GL
|
---|