{"id":74,"date":"2013-11-08T15:46:23","date_gmt":"2013-11-08T15:46:23","guid":{"rendered":"\/\/3dbym.ru\/2013\/11\/making-it-move-animation\/"},"modified":"2013-11-08T15:46:23","modified_gmt":"2013-11-08T15:46:23","slug":"making-it-move-animation","status":"publish","type":"post","link":"https:\/\/3dbym.ru\/2013\/11\/making-it-move-animation\/","title":{"rendered":"Making It Move: Animation"},"content":{"rendered":"
Now that you have a nice, textured model, you can start writing the code to animate it onscreen. Animation of a keyframed model such as an MD2 essentially involves drawing the frames one after another.<\/p>\n
You can take the approach of simply drawing the next frame in the series, but this will produce less than satisfactory results. This method will result in jerky animation, and will run at different speeds on different computers; something you definitely do not want.<\/p>\n
The solution to this issue is to interpolate between the frames with respect to time. In order to have smooth animations, you will automati\u00adcally create new frames that represent the model\u2019s position at any given time. This approach has many advantages. It provides smooth transitions between frames. You can control the speed of the anima\u00adtion, and the frames will pass at the same rate on all machines. Last of all, it is predictable. You can count on it being at frame x during time y; even if the system gets hung up, the program will skip to wherever it should be at the time it starts again.<\/p>\n
To do anything with time, you need a timer. The CTimer class is pro\u00advided just for that, you can find out how it works by examining timer. h. The function you are most interested in here is CTimer::GetMS(). This function returns the number of milliseconds that have elapsed since the function was called.<\/p>\n
If you know how many milliseconds have passed since the last frame, and how long each frame should last in milliseconds, you can \u201ccreate\u201d a new frame that is partway between two frames of the MD2 model.<\/p>\n
First, you need the time it should take between frames (in ms). The Animate() function of CMd2 takes care of that. A parameter is passed to the function that tells the function how fast to animate, in frames per second. Using this it is a simple matter of obtaining the number of milliseconds for each frame. The timer takes care of the time elapsed between frames.<\/p>\n
Using these values, you can calculate an interpolation value. This will let you calculate the vertices to display. Use the following formula:<\/p>\n