1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "CameraAnimation.h"
21 
22 #include "Renderer/Camera.h"
23 
24 namespace TrenchBroom {
25     namespace View {
26         const Animation::Type CameraAnimation::AnimationType = Animation::freeType();
27 
CameraAnimation(Renderer::Camera & camera,const Vec3f & targetPosition,const Vec3f & targetDirection,const Vec3f & targetUp,const wxLongLong duration)28         CameraAnimation::CameraAnimation(Renderer::Camera& camera, const Vec3f& targetPosition, const Vec3f& targetDirection, const Vec3f& targetUp, const wxLongLong duration) :
29         Animation(AnimationType, Curve_EaseInEaseOut, duration),
30         m_camera(camera),
31         m_startPosition(m_camera.position()),
32         m_startDirection(m_camera.direction()),
33         m_startUp(m_camera.up()),
34         m_targetPosition(targetPosition),
35         m_targetDirection(targetDirection),
36         m_targetUp(targetUp) {}
37 
doUpdate(const double progress)38         void CameraAnimation::doUpdate(const double progress) {
39             const float fltProgress = static_cast<float>(progress);
40             const Vec3f position = m_startPosition + (m_targetPosition - m_startPosition) * fltProgress;
41             const Vec3f direction = m_startDirection + (m_targetDirection - m_startDirection) * fltProgress;
42             const Vec3f up = m_startUp + (m_targetUp - m_startUp) * fltProgress;
43 
44             m_camera.moveTo(position);
45             m_camera.setDirection(direction, up);
46         }
47     }
48 }
49