# Animating Rotation

This topic is 1868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi guys,

Lets say that I have a fan and want to make the fan rotate fast and keep rotating at the same speed, I want to animate this rotation, so I used 3Ds Max to create animation and rotated the fan 360 degree so I can use this animation in the DirectX 9 program and play the animation with loop at any speed that I want.

In my DirectX 9 program I notice slight delay between the loop, so it doesn't look realistic at all, it's like the fan is rotating and stopping then rotating then stoping even the animation is looping, I'm trying to make the animation loop play at the same speed all the time.

This is a general problem that I'm having with animation looping, so the problem is not only about rotating a fan, it's about animation looping in general.

I'm loading .x file hierarchy, here is the code that I'm using for animation:
// Remember current animation m_currentAnimationSet=index; // Get the animation set from the controller LPD3DXANIMATIONSET set; m_animController->GetAnimationSet(index, &set); // Note: for a smooth transition between animation sets we can use two tracks and assign the new set to the track // not currently playing then insert Keys into the KeyTrack to do the transition between the tracks // tracks can be mixed together so we can gradually change into the new animation // Alternate tracks DWORD newTrack = ( m_currentTrack == 0 ? 1 : 0 ); // Assign to our track m_animController->SetTrackAnimationSet( newTrack, set ); set->Release(); // Clear any track events currently assigned to our two tracks m_animController->UnkeyAllTrackEvents( m_currentTrack ); m_animController->UnkeyAllTrackEvents( newTrack ); // Add an event key to disable the currently playing track kMoveTransitionTime seconds in the future m_animController->KeyTrackEnable( m_currentTrack, FALSE, m_currentTime + kMoveTransitionTime ); // Add an event key to change the speed right away so the animation completes in kMoveTransitionTime seconds m_animController->KeyTrackSpeed( m_currentTrack, 0.0f, m_currentTime, kMoveTransitionTime, D3DXTRANSITION_LINEAR ); // Add an event to change the weighting of the current track (the effect it has blended with the secon track) m_animController->KeyTrackWeight( m_currentTrack, 0.0f, m_currentTime, kMoveTransitionTime, D3DXTRANSITION_LINEAR ); // Enable the new track m_animController->SetTrackEnable( newTrack, TRUE ); // Add an event key to set the speed of the track m_animController->KeyTrackSpeed( newTrack, 1.0f, m_currentTime, kMoveTransitionTime, D3DXTRANSITION_LINEAR ); // Add an event to change the weighting of the current track (the effect it has blended with the first track) // As you can see this will go from 0 effect to total effect(1.0f) in kMoveTransitionTime seconds and the first track goes from // total to 0.0f in the same time. m_animController->KeyTrackWeight( newTrack, 1.0f, m_currentTime, kMoveTransitionTime, D3DXTRANSITION_LINEAR ); // Remember current track m_currentTrack = newTrack;

##### Share on other sites
Don't make the animation is 3dsmax, make the propeler in its own subset, place the center at the origin and use a matrix to rotate it on its axis.

 D3DXMatrixRotationZ(&matRotateZ, D3DXToRadian(varAngle)); device->SetTransform(D3DTS_WORLD, &matRotateZ); 

That being said, in 3dsmax, do you copy the first keyframe to be the last key frame?

What you should do is make a 60 frame long animation, Copy the first keyframe and place it as 61. Then export only the first 60 frames. That way your animation loops smoothly. Edited by Tispe

##### Share on other sites
The rotation is just an example to explain the problem.

I tried creating 60 frame long animation and used shift to copy the first frame to 61, from 0 to 60 it's rotating 360 degree and I still have the same problem.

Take a look at the video: