Experiment 4 role Animation
I,Lab content:
1. Create a simple game scenario and player role;
2. Define the Application class and Listener class according to the Ogre startup sequence;
3. Use the AnimationState class to implement basic role animation;
4. Implement role interaction control through the keyboard or mouse;
II,Purpose:
1. Be familiar with the Ogre startup sequence, understand the Ogre engine working process, and the implementation principle of the Ogre sample framework.
2. Measure the test taker's knowledge about the functions and usage of the frame listener interface, mouse listener interface, and keyboard listener interface.
3. Understand the basic principle of Ogre animation implementation and the usage of the AnimationState class.
4. Master the implementation and Interactive Control Methods of Ogre animation.
Iii. Experiment steps
1,Framework establishment and improvement
I. First, two minor problems have been improved:
In the new version, Ogre has deque,
Therefore, we need to make a difference in usage:
II. The second is the generated exe file. vs08 is generated under the debug directory by default, while the runtime is under the current project. If you do not pay attention to it, copying resource files several times is inevitable, which can be solved by setting the working directory:
Add the scenario control. The result is as follows:
2,Animation creation
You need to get the AnimationState from the object, set it, and activate it. Animation activity, but you must add time after each frame to make the animation work. Modify the frame listener:
Start in-situ patrol:
3,Mobile role:
Change the listener constructor of the mobile role:
Add control over the path:
Bool nextLocation ()
{
If (mshortlist. empty ())
Return false;
MDestination = mdestinlist. front (); // this gets the front of the deque
Malong list. pop_front (); // this removes the front of the deque
MDirection = mDestination-mNode-> getPosition ();
MDistance = mDirection. normalise ();
Return true;
} // NextLocation ()
Bool frameStarted (const FrameEvent & evt)
{
If (mDirection = Ogre: Vector3: ZERO)
{
If (nextLocation ())
{
// Set walking animation
MAnimationState = mEntity-> getAnimationState ("Walk ");
MAnimationState-> setLoop (true );
MAnimationState-> setEnabled (true );
} // If
}
Else
{
Ogre: Real move = m1_speed * evt. timeSinceLastFrame;
MDistance-= move;
If (mDistance <= 0.0f)
{
MNode-> setPosition (mDestination );
MDirection = Ogre: Vector3: ZERO;
// Set animation based on if the robot has another point to walk.
If (! NextLocation ())
{
// Set Idle animation
MAnimationState = mEntity-> getAnimationState ("Idle ");
MAnimationState-> setLoop (true );
MAnimationState-> setEnabled (true );
}
Else
{
// Rotation Code will go here later
Ogre: Vector3 src = mNode-> getOrientation () * Ogre: Vector3: UNIT_X;
If (1.0f + src. dotProduct (mDirection) <0.0001f)
{
MNode-> yaw (Ogre: Degree (180 ));
}
Else
{
Ogre: Quaternion quat = src. getRotationTo (mDirection );
MNode-> rotate (quat );
} // Else
} // Else
} Else {
MNode-> translate (mDirection * move );
} // Else
} // If
MAnimationState-> addTime (evt. timeSinceLastFrame );
Return ExampleFrameListener: frameStarted (evt );
}
Robots walk based on the input walk vector:
4,Enhanced animation,Smooth turning:
The rotation of the official textbooks is directly directed by the four element numbers (!), which is not realistic in the case of a large angle. After some improvement, the smooth rotation is achieved:
First, find the steering angle:
In the update of each frame, first check whether the redirection is completed:
But I don't know whether it is a floating point Precision problem. The steering angle is quite different. It is still to be solved:
In addition, nextLocation is improved to make the walking loop:
Iv. experiment data and processing results
The results are all given, the code is included with the project...
5. Think about the question or experience or suggestions for improving the experiment
The animation and particle combination in Ogre can be further explored. Don't stop!