1 //****************************************************************************// 2 // coreanimation.cpp // 3 // Copyright (C) 2001, 2002 Bruno 'Beosil' Heidelberger // 4 //****************************************************************************// 5 // This library is free software; you can redistribute it and/or modify it // 6 // under the terms of the GNU Lesser General Public License as published by // 7 // the Free Software Foundation; either version 2.1 of the License, or (at // 8 // your option) any later version. // 9 //****************************************************************************// 10 11 #ifdef HAVE_CONFIG_H 12 #include "config.h" 13 #endif 14 15 #include "cal3d/coreanimation.h" 16 #include "cal3d/coretrack.h" 17 CalCoreAnimation()18CalCoreAnimation::CalCoreAnimation() 19 { 20 } 21 22 ~CalCoreAnimation()23CalCoreAnimation::~CalCoreAnimation() 24 { 25 } 26 27 /*****************************************************************************/ 28 /** Adds a core track. 29 * 30 * This function adds a core track to the core animation instance. 31 * 32 * @param pCoreTrack A pointer to the core track that should be added. 33 * 34 * @return One of the following values: 35 * \li \b true if successful 36 * \li \b false if an error happend 37 *****************************************************************************/ 38 addCoreTrack(CalCoreTrack * pCoreTrack)39bool CalCoreAnimation::addCoreTrack(CalCoreTrack *pCoreTrack) 40 { 41 m_listCoreTrack.push_back(pCoreTrack); 42 43 return true; 44 } 45 46 /*****************************************************************************/ 47 /** Provides access to a core track. 48 * 49 * This function returns the core track for a given bone ID. 50 * 51 * @param coreBoneId The core bone ID of the core track that should be 52 * returned. 53 * 54 * @return One of the following values: 55 * \li a pointer to the core track 56 * \li \b 0 if an error happend 57 *****************************************************************************/ 58 getCoreTrack(int coreBoneId)59CalCoreTrack *CalCoreAnimation::getCoreTrack(int coreBoneId) 60 { 61 // loop through all core track 62 std::list<CalCoreTrack *>::iterator iteratorCoreTrack; 63 for(iteratorCoreTrack = m_listCoreTrack.begin(); iteratorCoreTrack != m_listCoreTrack.end(); ++iteratorCoreTrack) 64 { 65 // get the core bone 66 CalCoreTrack *pCoreTrack; 67 pCoreTrack = *iteratorCoreTrack; 68 69 // check if we found the matching core bone 70 if(pCoreTrack->getCoreBoneId() == coreBoneId) return pCoreTrack; 71 } 72 73 // no match found 74 return 0; 75 } 76 77 /*****************************************************************************/ 78 /** Gets the number of core tracks for this core animation. 79 * 80 * This function returns the number of core tracks used for this core animation. 81 * 82 * @return The number of core tracks 83 *****************************************************************************/ 84 getTrackCount() const85unsigned int CalCoreAnimation::getTrackCount() const 86 { 87 return m_listCoreTrack.size(); 88 } 89 90 /*****************************************************************************/ 91 /** Returns the duration. 92 * 93 * This function returns the duration of the core animation instance. 94 * 95 * @return The duration in seconds. 96 *****************************************************************************/ 97 getDuration() const98float CalCoreAnimation::getDuration() const 99 { 100 return m_duration; 101 } 102 103 /*****************************************************************************/ 104 /** Sets the duration. 105 * 106 * This function sets the duration of the core animation instance. 107 * 108 * @param duration The duration in seconds that should be set. 109 *****************************************************************************/ 110 setDuration(float duration)111void CalCoreAnimation::setDuration(float duration) 112 { 113 m_duration = duration; 114 } 115 116 /*****************************************************************************/ 117 /** Scale the core animation. 118 * 119 * This function rescale all the skeleton data that are in the core animation instance 120 * 121 * @param factor A float with the scale factor 122 * 123 *****************************************************************************/ 124 scale(float factor)125void CalCoreAnimation::scale(float factor) 126 { 127 // loop through all core track 128 std::list<CalCoreTrack *>::iterator iteratorCoreTrack; 129 for(iteratorCoreTrack = m_listCoreTrack.begin(); iteratorCoreTrack != m_listCoreTrack.end(); ++iteratorCoreTrack) 130 { 131 (*iteratorCoreTrack)->scale(factor); 132 } 133 } 134 135 /*****************************************************************************/ 136 /** 137 * Set the name of the file in which the core animation is stored, if any. 138 * 139 * @param filename The path of the file. 140 *****************************************************************************/ 141 setFilename(const std::string & filename)142void CalCoreAnimation::setFilename(const std::string& filename) 143 { 144 m_filename = filename; 145 } 146 147 /*****************************************************************************/ 148 /** 149 * Get the name of the file in which the core animation is stored, if any. 150 * 151 * @return One of the following values: 152 * \li \b empty string if the animation was not stored in a file 153 * \li \b the path of the file 154 * 155 *****************************************************************************/ 156 getFilename(void) const157const std::string& CalCoreAnimation::getFilename(void) const 158 { 159 return m_filename; 160 } 161 162 /*****************************************************************************/ 163 /** 164 * Set the symbolic name of the core animation. 165 * 166 * @param name A symbolic name. 167 *****************************************************************************/ 168 setName(const std::string & name)169void CalCoreAnimation::setName(const std::string& name) 170 { 171 m_name = name; 172 } 173 174 /*****************************************************************************/ 175 /** 176 * Get the symbolic name the core animation. 177 * 178 * @return One of the following values: 179 * \li \b empty string if the animation was no associated to a symbolic name 180 * \li \b the symbolic name 181 * 182 *****************************************************************************/ 183 getName(void) const184const std::string& CalCoreAnimation::getName(void) const 185 { 186 return m_name; 187 } 188 189 /*****************************************************************************/ 190 /** 191 * Add a callback to the current list of callbacks for this CoreAnim. 192 * 193 * @param callback Ptr to a subclass of this abstract class implementing the callback function. 194 * @param min_interval Minimum interval (in seconds) between callbacks. Specifying 0 means call every update(). 195 * 196 *****************************************************************************/ 197 registerCallback(CalAnimationCallback * callback,float min_interval)198void CalCoreAnimation::registerCallback(CalAnimationCallback *callback,float min_interval) 199 { 200 CallbackRecord record; 201 record.callback = callback; 202 record.min_interval = min_interval; 203 204 m_listCallbacks.push_back(record); 205 } 206 207 /*****************************************************************************/ 208 /** 209 * Remove a callback from the current list of callbacks for this Anim. 210 * Callback objects not removed this way will be deleted in the dtor of the Anim. 211 * 212 * @param callback Ptr to a subclass of this abstract class implementing the callback function to remove. 213 * 214 *****************************************************************************/ 215 removeCallback(CalAnimationCallback * callback)216void CalCoreAnimation::removeCallback(CalAnimationCallback *callback) 217 { 218 for (std::vector<CallbackRecord>::iterator i = m_listCallbacks.begin(); i != m_listCallbacks.end(); i++) 219 { 220 if ((*i).callback == callback) 221 { 222 m_listCallbacks.erase(i); 223 return; 224 } 225 } 226 } 227 228 /*****************************************************************************/ 229 /** Returns the core track list. 230 * 231 * This function returns the list that contains all core tracks of the core 232 * animation instance. 233 * 234 * @return A reference to the core track list. 235 *****************************************************************************/ 236 getListCoreTrack()237std::list<CalCoreTrack *>& CalCoreAnimation::getListCoreTrack() 238 { 239 return m_listCoreTrack; 240 } 241 242 /*****************************************************************************/ 243 /** Returns the total number of core keyframes used for this animation. 244 * 245 * This function returns the total number of core keyframes used for this 246 * animation instance (i.e.: the sum of all core keyframes of all core tracks). 247 * 248 * @return A reference to the core track list. 249 *****************************************************************************/ 250 getTotalNumberOfKeyframes() const251unsigned int CalCoreAnimation::getTotalNumberOfKeyframes() const 252 { 253 unsigned int nbKeys = 0; 254 for (std::list<CalCoreTrack*>::const_iterator it = m_listCoreTrack.begin(); it != m_listCoreTrack.end(); ++it) 255 { 256 CalCoreTrack *track = *it; 257 nbKeys += track->getCoreKeyframeCount(); 258 } 259 return nbKeys; 260 } 261 262