Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Having Trouble Detecting The End Of A Animation


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 ankhd   Members   -  Reputation: 1356

Like
0Likes
Like

Posted 02 August 2014 - 03:03 AM

Hi All.
I would like to have my update Animation function return true when the animation is at the end.
I have in my animation update function where it detects the last frame time, It was working on a larger animation
but I am trying it on a animation that has 30 frames and its max time is 4800(last frame time).

I steped through the code and my frame delta time value passed into this function is like 3200000 thats a big number

if I loop the animation it runs fine. even with this larg time value, Another thing if I break the code before the update animation function
the frame delta is 103.1 so some where in passing and entering the function funky stuff is happening. I thought it came from passing a float to a windows FLOAT
So I changed the FLOATS to float but the same thing.????

Maybe its because my animation time is a DWORD and my timer class is a double casted to a float for time deleta. What should I do here????

Ok heres some code the first is the UpDateAnimation function and the next is the timer class I'm using.


void AnimationCollection::Update(char *AnimationSetName,     
                                  DWORD Time, BOOL Loop, BOOL *atend)
{
  cAnimationSet *AnimSet = m_AnimationSets;

  //set atend to false;
  if(atend)//if its being used
*atend = false;

  // Look for matching animation set name if used
  if(AnimationSetName) 
 {

   // Find matching animation set name
   while(AnimSet != NULL) 
   {

    // Break when match found
    if(!_stricmp(AnimSet->m_Name.c_str(), AnimationSetName))
       break;

   // Go to next animation set object
   AnimSet = AnimSet->m_Next;
  }
}

  // Return no set found
  if(AnimSet == NULL)
    return;

  // Bounds time to animation length
  if(Time >= AnimSet->m_Length)
  {
//if atend is not null we can see if we are looping if we are then we dont get to the end
//but if loop = false we set it to true
 if(atend)
 {
   if(Loop)
     *atend = FALSE;
   else
     *atend = TRUE;
}
Time = (Loop==TRUE)?Time%(AnimSet->m_Length+1):AnimSet->m_Length;
  }

timer class

class GameTimer
{
public:
	GameTimer(void);

	float getGameTime(void)const;  // in seconds
	float getDeltaTime(void)const; // in seconds

	void reset(void); // Call before message loop.
	void start(void); // Call when unpaused.
	void stop(void);  // Call when paused.
	void tick(void);  // Call every frame.

private:
	double mSecondsPerCount;
	double mDeltaTime;

	__int64 mBaseTime;
	__int64 mPausedTime;
	__int64 mStopTime;
	__int64 mPrevTime;
	__int64 mCurrTime;

	bool mStopped;
};



float GameTimer::getDeltaTime(void)const
{
	return (float)mDeltaTime;
}




void GameTimer::tick(void)
{
	if( mStopped )
	{
		mDeltaTime = 0.0;
		return;
	}

	__int64 currTime;
	QueryPerformanceCounter((LARGE_INTEGER*)&currTime);
	mCurrTime = currTime;

	// Time difference between this frame and the previous.
	mDeltaTime = (mCurrTime - mPrevTime)*mSecondsPerCount;

	// Prepare for next frame.
	mPrevTime = mCurrTime;

	// Force nonnegative.  The DXSDK's CDXUTTimer mentions that if the 
	// processor goes into a power save mode or we get shuffled to another
	// processor, then mDeltaTime can be negative.
	if(mDeltaTime < 0.0)
	{
		mDeltaTime = 0.0;
	}
}


Sponsor:

#2 Buckeye   Crossbones+   -  Reputation: 6198

Like
1Likes
Like

Posted 02 August 2014 - 09:02 AM

First: unless you intentionally want very large delta-times after you pause/un-pause the app, always update the current and previous times. Just set mDeltaTime = 0 when your app is paused after you've calculated mDeltaTime. Your code as posted will result in large deltas after a pause.

 

Second: when you're debugging (i.e., setting breakpoints), the clock will continue to run while you're staring at your code. While you're debugging, set mDeltaTime to a fixed value (something like 0.01667 - 60th of second). Then, when you want to run "live" (with the First suggestion above implemented), try things out with a "live" delta time.

 

EDIT: That is, your comment

// Time difference between this frame and the previous.

should read:

// Time difference since the last time the app was not in a stopped condition. May be 100s of seconds.

Edited by Buckeye, 02 August 2014 - 09:11 AM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#3 ankhd   Members   -  Reputation: 1356

Like
0Likes
Like

Posted 02 August 2014 - 11:05 PM

Hey thanks.

 

What I have worked out is the elapsed time is ok for a looping animation as the time gets lapped to start frame.

But for a animation that you want to run once I need to keep the start time and use this time to calculate the frame like this.

I'm also now using timeGetTime() it should be more then enough for animation hey.??? as my Animation class uses DWORD for time anyway.

 

after 8 years this is the firts time i've wanted or needed a animation to play once lol hehehe.

I noraly just not animate them and only animate them when needed.

 

static DWORD StartTime = timeGetTime();//this was my test. StartTime is now part of the object

DWORD elapsed = (timeGetTime() - StartTime) *10;//the 10 speeds it up some

 

then when I want to play the animation again I set StartTime = timeGetTime(); and a flag that triggers the render to render the animation or its not called.

 

What I'm using it for is my SpearOfObjectPlacement it allows the user to place objects from the menu to the terrain with a left click.

this is where I play the the animation on the leftclick, then the spear raises a bit and slams into the terrain with some effects(next part) when the last frame is played.

 

Thanks Again All.



#4 Buckeye   Crossbones+   -  Reputation: 6198

Like
0Likes
Like

Posted 03 August 2014 - 07:52 AM

Glad you got it worked out.


Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS