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

RotationTimeTrack.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 "RotationTimeTrack.h" 00013 #include <OpenCAL/KeyFrameSystem.h> 00014 using namespace OpenCAL; 00015 00016 using namespace std; 00017 00018 00019 /****************************** 00020 * Constructors and destructor * 00021 ******************************/ 00022 00023 RotationTimeTrack::RotationTimeTrack(KeyFrameSystem *keyFrameSystem, Quaternion *rotation) 00024 : TimeTrack(keyFrameSystem), m_rotation(rotation) 00025 { 00026 } 00027 00028 RotationTimeTrack::~RotationTimeTrack() 00029 { 00030 } 00031 00032 00033 /****************** 00034 * Other functions * 00035 ******************/ 00036 00037 void RotationTimeTrack::addKeyFrame(float time, const Quaternion &value) 00038 { 00039 m_keyFrames[time] = value; 00040 00041 if(time > m_length) 00042 m_length = time; 00043 } 00044 00045 void RotationTimeTrack::deleteKeyFrame(float time) 00046 { 00047 KeyFrameMap::iterator it; 00048 for(it = m_keyFrames.begin(); it != m_keyFrames.end(); ++it) 00049 if(it->first == time) 00050 { 00051 m_keyFrames.erase(it); 00052 if(time == m_length) 00053 if(m_keyFrames.size() == 0) 00054 m_length = 0.0f; 00055 else 00056 m_length = m_keyFrames.rbegin()->first; 00057 return; 00058 } 00059 } 00060 00061 void RotationTimeTrack::apply() 00062 { 00063 float time = applySpeed(); 00064 00065 KeyFrameMap::iterator it = m_keyFrames.begin(); 00066 while(it != m_keyFrames.end() && it->first < time) 00067 ++it; 00068 00069 if(it == m_keyFrames.end()) return; 00070 00071 00072 float time2 = it->first; 00073 const Quaternion &value2 = it->second; 00074 --it; 00075 float time1 = it->first; 00076 const Quaternion &value1 = it->second; 00077 00078 float u = (time - time1) / (time2 - time1); 00079 00080 *m_rotation = value1.slerped(u, value2); 00081 }

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