00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
#include "TimeTrack.h"
00013
#include <OpenCAL/KeyFrameSystem.h>
00014
using namespace OpenCAL;
00015
using namespace Utils;
00016
00017
using namespace std;
00018
00019
00020
00021
00022
00023
00024 TimeTrack::TimeTrack(
KeyFrameSystem *keyFrameSystem)
00025 : m_keyFrameSystem(keyFrameSystem)
00026 , m_currentTime(0.0f), m_length(0.0f)
00027 , m_loop(true), m_stopped(false)
00028 {
00029 keyFrameSystem->
addTimeTrack(
this);
00030 }
00031
00032 TimeTrack::~TimeTrack()
00033 {
00034 m_keyFrameSystem->
deleteTimeTrack(
this);
00035 }
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
void TimeTrack::step(
float deltaSeconds)
00048 {
00049
if(m_stopped)
return;
00050
00051 m_currentTime += deltaSeconds;
00052
00053
if(m_currentTime > m_length)
00054
if(m_loop)
00055 {
00056
while(m_currentTime > m_length)
00057 m_currentTime -= m_length;
00058 }
00059
else
00060 {
00061 m_currentTime = m_length;
00062 m_stopped =
true;
00063 }
00064
00065 apply();
00066 }
00067
00068
void TimeTrack::rewind()
00069 {
00070 m_currentTime = 0.0f;
00071 apply();
00072 }
00073
00074
void TimeTrack::setTime(
float time)
00075 {
00076 m_currentTime = time;
00077
00078
if(m_currentTime > m_length)
00079
if(m_loop)
00080 {
00081
while(m_currentTime > m_length)
00082 m_currentTime -= m_length;
00083 }
00084
else
00085 m_currentTime = m_length;
00086
00087 apply();
00088 }
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
float TimeTrack::applySpeed()
const
00101
{
00102
00103
float t = m_currentTime / m_length;
00104
00105
return (sinf(t * Math::pi - Math::pi * 0.5f) + 1.0f) * 0.5f * m_length;
00106 }