Shard Posted May 28, 2010 Share Posted May 28, 2010 For our reloading animation, I need it to reload once per call, which means that it needs to play from its start frame of 0 to its end frame of 100 and then stop until the reload animation is called again. So far, I haven't managed to figure out how to properly do the reload animation so that it starts and stops at the correct times. The code I have below usually stops the animation at the right time, but sometimes it does it three or four times over before it stops. The animation also generally starts in the middle, around 30 or 40 and sometimes near the end like 95. //Animation Code - Reloading Case case reload: aniStart = weapon->reloadStart; aniEnd = weapon->reloadEnd; //DOF frameWork->GetRenderer().SetFarDOFRange(Vec2(0,50)); frameWork->GetRenderer().SetFarDOFStrength(200); frameWork->GetRenderer().SetFarDOF( true ); frame=AppTime()/30.0; frame=fmodf(frame,aniEnd-aniStart)+aniStart; if(frame <= aniEnd-1) { (bodyMesh,frame,1.0,0,true); } else wepState = idleUp; break; } Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
ArBuZ Posted May 28, 2010 Share Posted May 28, 2010 Hi Shard! I think that in case of none loop animation you should calculate frame the other way: frame=StartFrame switch(state){ case reload: frame+=ANIM_SPEED*Engine::GetSpeed(); Animate(); if (frame>=EndFrame) state=anotherState; break; } Quote Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64 3ds max / photoshop CS3 / C++ http://www.arbuznikov.com Link to comment Share on other sites More sharing options...
Shard Posted May 28, 2010 Author Share Posted May 28, 2010 Hi Shard! I think that in case of none loop animation you should calculate frame the other way: frame=StartFrame switch(state){ case reload: frame+=ANIM_SPEED*Engine::GetSpeed(); Animate(); if (frame>=EndFrame) state=anotherState; break; } What is ANIM_SPEED? And is GetSpeed the same as AppSpeed()? Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
ArBuZ Posted May 28, 2010 Share Posted May 28, 2010 What is ANIM_SPEED? Its a constant. any number you wish. And is GetSpeed the same as AppSpeed()? Yep. Quote Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64 3ds max / photoshop CS3 / C++ http://www.arbuznikov.com Link to comment Share on other sites More sharing options...
ArBuZ Posted May 28, 2010 Share Posted May 28, 2010 one more way to calculate frame is calculate it based on animation speed in fps. For example you have animation that is made as 30 fps animation. Then frame will be: frame+=30*(Engine::GetTime()-prevAnimTime)/1000.0; Animate(frame); prevAnimTime=Engine::GetTime(); Then your animation will always be played 30 frames per second. Quote Q6600@2.4GHz - 9600GT - 4GB DDR2@800MHz - Windows7 x64 3ds max / photoshop CS3 / C++ http://www.arbuznikov.com Link to comment Share on other sites More sharing options...
Shard Posted May 31, 2010 Author Share Posted May 31, 2010 one more way to calculate frame is calculate it based on animation speed in fps. For example you have animation that is made as 30 fps animation. Then frame will be: frame+=30*(Engine::GetTime()-prevAnimTime)/1000.0; Animate(frame); prevAnimTime=Engine::GetTime(); Then your animation will always be played 30 frames per second. Thank you very much. Your suggestions worked marvelously. Quote Programmer/Engineer/Student www.reikumar.com 2.6 GHz Intel Core Duo - nVidia GeForce 8600 GT - Windows 7 64-bit - 4 Gigs RAM C++ - Visual Studio Express - Dark GDK - Leadwerks SDK Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.