8. Вершинная animationLesson 8
��������� animation
Level: Beginner Version of the Xtreme3D: 3.0.x
Author: Gecko
The Object Freeform is intended mainly for inanimate objects. This is usually the elements of decoration, vehicles, various interactive objects, and so on. If we want to populate our virtual world of living creatures, we cannot do without the Actor objects. The name speaks for itself: the actor is a living character. In the Xtreme3D actors represent the animated model. And the animation, as is well known, is of two types - ���������� and skeletal. In this lesson, we look at The ���������� animation.
���������� (or ���������) Animation is characterized by the fact that for the formation of an animation sequence of the slider moves each vertex of the model from one position to another. This type of animation was first applied in the Quake, and since then the formats of the models in the Quake (MD2, MD3) have become a standard in all ��������� cursors. Xtreme3D provides full support for MD2 and MD3. The difference between them lies in the fact that the MD2 stores all model entirely in one file, and the MD3 - in three (Head, torso and legs). With the help of special matrices the torso is synchronized with the feet, and the head - with the torso. This was done in order to animate the torso and legs separately. For example, during the shooting character can both run and walk slowly, and even simply stand in place.
In this lesson, we look at The ���������� animation with the format of the MD2. The actor from the MD2 is created as follows:
Actor = ActorCreate('model.md2', matlib, matlib, global.scene);
Sometimes after loading the model is that it incorrectly rotated. This is because different editors axis direction is interpreted in different ways. Usually "swap" the Y axis and Z model peaks are recorded so that its vector of Up is directed along the Z axis (in DirectX applications, this means "up"), and, since the direction of the "up" in Xtreme3D meets the Y axis, but not Z, it turns out that the model rotated 90 degrees on the X-axis. We can fix this misunderstanding in several ways. The most simple - just turn her back:
ObjectPitch(actor, 90);
But in some cases this is not enough. Turning the model, we also turn its Local coordinate system. This means that the vector Direction now indicates along the Y-axis and Z is not as it should be. If we now move the model using ObjectMove, she will move up and not forward. You can, of course, instead of ObjectMove ObjectStrafe use, but this will make the program less neat and tangle so long. Much better than the first place the actor in the descendants of the dummy and then rotate. And, accordingly, to move to use the dummy, not the actor. The code will be as follows:
Player = DummycubeCreate(global.scene);
Actor = ActorCreate('model.md2', matlib, matlib, player);
ObjectPitch(actor, 90);
The format of the MD2 provides for the separation of all frames of animation in separate groups. This is done in order to separate the, say, the animation runs from animation jump. By default, the Xtreme3D plays all frames one after the other, not paying attention to this division. But we can at any time switch to the desired animation:
ActorSwitchToAnimation(actor, 1, false);
And then will be played only group training under number 1. The third parameter of this function is responsible for the smooth change of animation: if set to true, the change will be gradual.
Approximately the same makes the function, indicating the range of frames for playback:
ActorSetAnimationRange(actor, 10, 20);
It is not difficult to guess that will be lost only the period between the tenth and twentieth frames. However, these two functions have one important distinction. ActorSwitchToAnimation every time the call switches to play the first frame of the target group, and ActorSetAnimationRange does not do this (if the range is already playing). ActorSetAnimationRange therefore can be called repeatedly - for example, inside the loop that in some situations turns out to be very useful.
By default, the animation is reproduced cycle - that is, when it reaches the last frame, play starts again. In most cases this is what you need (for example, the animation of walking or jogging is always fixated). But we can specify and other playback mode:
ActorSetAnimationMode(actor, aam);
Instead of the AAM uses one of the following constants:
AamNone - Animation cannot be reproduced;
AamPlayOnce - Animation is reproduced once and stops when it reaches the end frame. This mode is sometimes referred to as the "one shot";
AamLoop - Animation is repeated cyclically (default);
AamBounceForward - Animation is repeated cyclically forward until the final frame, and then in the opposite direction to the initial frame, then again forward, and so on. This mode is sometimes referred to as the "ping-pong".
AamBounceBackward - the same thing, but in the opposite direction.
AamLoopBackward - animation cycle is repeated in the opposite direction.
Finally, there is also the possibility to disable the linear interpolation between frames:
ActorSetFrameInterpolation(actor,false);
The frames will be Ousting each other abruptly, without a smooth "spill". This can be useful, for example, in the races, where the vehicle bodywork can be deformed - in different frames topmost animations can store different variants of damage.