Game Development Reference
In-Depth Information
[&]{ m_animating=false; } );
m_interpolator.Add(anim);
m_animating = true;
}
Forsimplicity,duringthetimeweareanimatingeitherleftorright,wedisallowanyfurther
changestothemenu.Thisisnotnecessaryifamoreadvancedsystemisdevelopedtoqueue
up, or interrupt animations. We first do a pass on the menu items, clearing any of them that
have been previously marked as selected, this is done as a simpler alternative than tracking
thecurrentlyselecteditemmoreclosely,whichwouldhavebetterperformanceresults.The
next part is to determine which the next item is, or which the target item we will animate
towardsis.Ifthenextitemgoesbeyondthescopeofthelist,wewilllooparoundtothelast
element and the target angle will be 2π. Otherwise, if we are single stepping from one item
to the next item, we can calculate the step by partitioning a circle into the number of items
inthe menu, just like slicing apizza. The target angle will bethe index ofthe item wewish
to animate to times the step angle we calculated.
This is a perfect opportunity to make use of the interpolation curves for animation we saw
in Animation with Interpolation Curves . We will animate the m_currentAngle parameter
towards m_targetAngle , over the duration specified by m_animationTime . In this example
we will use an ease in/out quadratic curve, this will give it a nice feeling of acceleration
as the animation begins and a nice smooth deceleration as the item reaches its target, and
we provide a finish function that resets the m_animating flag to false once the animation is
done. It's fun to change the selected curve to see the difference each ease curve makes and
find the one that gives the best responsiveness and fluidity to the menu.
Updating the menu is straightforward, we will update the interpolator to make sure the
animations we create are updated. We then set the root item's world transform to a ro-
tation matrix at m_currentAngle . And finally we update the root item, this will internally
propagate the transformation to all of its children items.
void menu_3d::Update(float deltaTime)
{
m_interpolator.Update(deltaTime);
m_root->SetWorld(matrix::CreateRotationY(m_currentAngle));
m_root->Update(deltaTime);
}
The parts of the system that handles the hierarchy is within the item class,
class item
{
private:
Search WWH ::




Custom Search