This animation works, but it has a potential problem. We're basing the
animation entirely off of the number of frames rendered. Each frame rotated the
bird half a degree. However, what if your machine runs this demo at 60 frames
per second, and mine runs it at 30 frames per second? This means your drinking
bird is rotating 30 degrees a second. Mine is rotating only 15. This might be
fine for drinking birds but say we had a facial animation play and it was
supposed to be synced with the sound file of the character's voice. This would
be a disaster. What we really want to do is use the real world time to know how
far to rotate before rendering the next frame. For example, say our target rate
is 60 frames per second, meaning that the bird should rotate 30 degrees per
second. We'd like to know how much time has gone by since the last frame. In a
moment, I'll show you how this is done. As you can see from demo, once we
switch to the timed version of the code, the rate of the drinking birds motion
is unaffected by the frames per second shown. Give this demo a try yourself.
このアニメーションには潜在的な問題があります
レンダリングするフレーム数を
まったく考慮していません
水飲み鳥は1フレーム0.5度で回転しています
ではあなたの環境において
このデモを1秒60フレームで実行すると
私の環境では1秒30フレームで実行するのでしょうか
これは皆さんの環境では1秒あたり30度回転し
私のでは15度回転するということを意味します
水飲み鳥では問題ないでしょうが
もし顔のアニメーションを実行して
キャラクターの声の音声ファイルと同期させるなら
悲惨な結果になるでしょう
私たちが本当にやりたいのは実世界の時間を使って
次のレンダリングまでに
どれだけ回転するかを知ることです
例えば毎秒60フレームに設定したなら
水飲み鳥は毎秒30度回転することになるでしょう
最後のフレームからどれだけ回転するかを
知る必要があります
早速お見せしましょう
このデモから分かるように
コードを定時バージョンに切り替えることで
水飲み鳥が動く速度は
フレームに影響されることはありません
自分で試してみてください