Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

TimeTrack.cpp

00001 /*************************************************************************** 00002 * This file is part of OpenCAL: Open Computer Animation Library * 00003 * I created OpenCAL as my master's thesis Computer Science (multimedia) * 00004 * at the tUL university in Diepenbeek, Belgium * 00005 * * 00006 * Copyright (C) 2003-2004 by Jeroen Dierckx * 00007 * jeroen.dierckx@student.luc.ac.be * 00008 * * 00009 ***************************************************************************/ 00010 00011 // Includes 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 * Constructors and destructor * 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 * Get and set functions * 00040 ************************/ 00041 00042 00043 /************************** 00044 * Time stepping functions * 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 * Other functions * 00093 ******************/ 00094 00095 00096 /********************** 00097 * Protected functions * 00098 **********************/ 00099 00100 float TimeTrack::applySpeed() const 00101 { 00102 // Normalize the current time between 0 and 1 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 }

Generated on Sun Aug 15 19:19:23 2004 for OpenCAL: Open Computer Animation Library by doxygen 1.3.8