source: flair-src/trunk/lib/FlairSimulator/src/FollowMeCamera.cpp@ 273

Last change on this file since 273 was 70, checked in by Sanahuja Guillaume, 8 years ago

simu cameras

File size: 2.6 KB
RevLine 
[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
28using namespace irr;
29using namespace gui;
30using namespace core;
31using namespace scene;
32
[15]33namespace flair {
34namespace simulator {
[8]35
[70]36FollowMeCamera::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]46FollowMeCamera::~FollowMeCamera() {}
[8]47
[70]48void FollowMeCamera::setPositionOffset(vector3df newpos) {
49 pos_offset = ToIrrlichtCoordinates(newpos);
50}
[8]51
[69]52void FollowMeCamera::setTargetOffset(vector3df newpos) {
[70]53 target_offset = ToIrrlichtCoordinates(newpos);
[8]54}
55
[69]56float 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]64void 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
Note: See TracBrowser for help on using the repository browser.