//********************************************************************************//
// //
// - "Talk to me like I'm a 3 year old!" Programming Lessons - //
// //
// $Author: DigiBen digiben@gametutorials.com //
// //
// $Program: MD3 Animation //
// //
// $Description: Demonstrates animating Quake3 characters with quaternions //
// //
// $Date: 3/28/02 //
// //
//********************************************************************************//
#include "main.h"
#include "Md3.h"
//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////
///////////////////////////////////////////////////////////////////////////////////
//
// This version of the tutorial incorporates the animation data stored in the MD3
// character files. We will be reading in the .cfg file that stores the animation
// data. The rotations and translations of the models will be done using a matrix.
// There will be no more calls to glTranslatef(). To create the rotation and
// translation matrix, quaternions will be used. This is because quaternions
// are excellent for interpolating between 2 rotations, as well as not overriding
// another translation causing "gimbal lock".
//
// So, why do we need to interpolate? Well, the animations for the character are
// stored in key frames. Instead of saving each frame of an animation, key frames
// are stored to cut down on memory and disk space. The files would be huge if every
// frame was saved for every animation, as well as creating a huge memory footprint.
// Can you imagine having 10+ models in memory with all of that animation data?
//
// The animation key frames are stored in 2 ways. The torso and legs mesh have vertices
// stored for each of the key frames, along with separate rotations and translations
// for the basic bone animation. Remember, that each .md3 represents a bone, that needs
// to be connected at a joint. For instance, the torso is connected to the legs, and the
// head is connected to the torso. So, that makes 3 bones and 2 joints. If you add the
// weapon, the weapon is connected to the hand joint, which gives us 4 bones and 3 joints.
// Unlike conventional skeletal animation systems, the main animations of the character's
// movement, such as a gesture or swimming animation, are done not with bones, but with
// vertex key frames, like in the .md2 format. Since the lower, upper, head and weapon models
// are totally different models, which aren't seamlessly connected to each other, then parent
// node needs to end a message (a translation and rotation) down to all it's child nodes to
// tell them where they need to be in order for the animation to look right. A good example
// of this is when the legs has the DEATH3 animation set, The legs might kick back into a back
// flip that lands the character on their face, dead. Well, since the main models are separate,
// if the legs didn't tell the torso where to go, then the model's torso would stay in the same
// place and the body would detach itself from the legs. The exporter calculates all this stuff
// for you of course.
//
// But getting back to the interpolation, since we use key frames, if we didn't interpolate
// between them, the animation would look very jumping and unnatural. It would also go too
// fast. By interpolating, we create a smooth transition between each key frame.
//
// As seen in the .md2 tutorials, interpolating between vertices is easy if we use the
// linear interpolation function: p(t) = p0 + t(p1 - p0). The same goes for translations,
// since it's just 2 3D points. This is not so for the rotations. The Quake3 character
// stores the rotations for each key frame in a 3x3 matrix. This isn't a simple linear
// interpolation that needs to be performed. If we convert the matrices to a quaternion,
// then use spherical linear interpolation (SLERP) between the current frame's quaternion
// and the next key frame's quaternion, we will have a new interpolated quaternion that
// can be converted into a 4x4 matrix to be applied to the current model view matrix in OpenGL.
// After finding the interpolated translation to be applied, we can slip that into the rotation
// matrix before it's applied to the current matrix, which will require only one matrix command.
//
// You'll notice that in the CreateFromMatrix() function in our quaternion class, I allow a
// row and column count to be passed in. This is just a dirty way to allow a 3x3 or 4x4 matrix
// to be passed in. Instead of creating a whole new function and copy and pasting the main
// code, it seemed fitting for a tutorial. It's obvious that the quaternion class is missing
// a tremendous amount of functions, but I chose to only keep the functions that we would use.
//
// For those of you who don't know what interpolation us, here is a section abstracted
// from the MD2 Animation tutorial:
//
// -------------------------------------------------------------------------------------
// Interpolation: Gamedev.net's Game Dictionary say interpolation is "using a ratio
// to step gradually a variable from one value to another." In our case, this
// means that we gradually move our vertices from one key frame to another key frame.
// There are many types of interpolation, but we are just going to use linear.
// The equation for linear interpolation is this:
//
// p(t) = p0 + t(p1 - p0)
//
// t - The current time with 0 being the start and 1 being the end
// p(t) - The result of the equation with time t
// p0 - The starting position
// p1 - The ending position
//
// Let's throw in an example with numbers to test this equation. If we have
// a vertex stored at 0 along the X axis and we wanted to move the point to
// 10 with 5 steps, see if you can fill in the equation without a time just yet.
//
// Finished? You should have come up with:
//
// p(t) = 0 + t(10 - 0)
// p(t) = 0 + 10t
// p(t) = 10t
//
// Now, all we need it a time from 0 to 1 to pass in, which will allow us to find any
// point from 0 to 10, depending on the time. Since we wanted to find out the distance
// we need to travel each frame if we want to reach the end point in 5 steps, we just
// divide 1 by 5: 1/5 = 0.2
//
// We can then pass this into our equation:
//
// p(0.2) = 10 * 0.2
// p(0.2) = 2
//
// What does that tell us? It tells us we need to move the vertex along the x
// axis each frame by a distance of 2 to reach 10 in 5 steps. Yah yah, this isn't
// rocket science, but it's important to know that what your mind would have done
// immediately without thinking about it, is linear interpolation.
//
// Are you starting to see how this applies to our model? If we only read in key
// frames, then we need to interpolate every vertex between the current and next
// key frame for animation. To get a perfect idea of what is going on, try
// taking out the interpolation and just render the key frames. You will notice
// that you can still see what is kinda going on, but it moves at an incredible pace!
// There is not smoothness, just a really fast jumpy animation.
// ------------------------------------------------------------------------------------
//
// Let's jump into the code (hold your breath!)
//
//
////////////////////////////// CREATE MATRIX \\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
/////
///// This function converts a quaternion to a rotation matrix
/////
////////////////////////////// CREATE MATRIX \\\\\\\\\\\\\\\\\\\\\\\\\\\\\*
void CQuaternion::CreateMatrix(float *pMatrix)
{
// Make sure the matrix has allocated memory to store the rotation data
if(!pMatrix) return;
// Fill in the rows of the 4x4 m
没有合适的资源?快使用搜索试试~ 我知道了~
图形、游戏开发OPENGL的源代码
共937个文件
jpg:198个
cpp:191个
h:136个
5星 · 超过95%的资源 需积分: 9 24 下载量 198 浏览量
2010-08-27
16:31:45
上传
评论 1
收藏 18.44MB RAR 举报
温馨提示
gametutorials教程里边有大量opengl经典实例(好像现在只能付费下载) 包括BSP OCTREE 地形 特效等等
资源推荐
资源详情
资源评论
收起资源包目录
图形、游戏开发OPENGL的源代码 (937个子文件)
Park.3ds 724KB
face.3DS 77KB
Character.3DS 47KB
statue.ASE 1.05MB
face.bmp 900KB
bone.bmp 284KB
Bottom.bmp 257KB
Terrain.bmp 257KB
Front.bmp 257KB
Left.bmp 257KB
Right.bmp 257KB
Top.bmp 257KB
Back.bmp 257KB
Back.bmp 257KB
Front.bmp 257KB
Top.bmp 257KB
Bottom.bmp 257KB
Right.bmp 257KB
Left.bmp 257KB
Back.bmp 257KB
Right.bmp 257KB
Front.bmp 257KB
Left.bmp 257KB
Terrain.bmp 257KB
Back.bmp 257KB
Top.bmp 257KB
Front.bmp 257KB
Top.bmp 257KB
Right.bmp 257KB
Left.bmp 257KB
Bottom.bmp 257KB
Terrain.bmp 257KB
Bottom.bmp 257KB
Detail.bmp 256KB
Detail.bmp 256KB
CrossHair.bmp 225KB
CrossHairMask.bmp 225KB
Sun.bmp 225KB
floor.bmp 192KB
Bitmap.bmp 192KB
Wall.bmp 192KB
Earth.bmp 192KB
Texture.bmp 192KB
Pluto.bmp 192KB
default_h.bmp 192KB
railgun2.bmp 192KB
default.bmp 192KB
railgun.bmp 192KB
Cove.bmp 192KB
default_h.bmp 192KB
railgun2.bmp 192KB
default.bmp 192KB
railgun.bmp 192KB
bitmap.bmp 192KB
Texture1.bmp 192KB
Texture4.bmp 192KB
Texture3.bmp 192KB
Texture2.bmp 192KB
Image.bmp 192KB
Brick.bmp 192KB
Brick.bmp 192KB
railgun3.bmp 96KB
railgun3.bmp 96KB
marble.bmp 68KB
fog.bmp 65KB
hobgoblin.bmp 65KB
hobgoblin.bmp 65KB
Bitmap.bmp 48KB
Lightmap.bmp 48KB
railgun4.bmp 48KB
railgun4.bmp 48KB
particle.bmp 12KB
T8dm6.bsp 2.94MB
Tutorial.bsp 2.58MB
Level.bsp 61KB
Level.bsp 61KB
Level.bsp 61KB
Level.bsp 61KB
lara_animation.cfg 842B
lara_animation.cfg 842B
Md3.cpp 71KB
Md3.cpp 57KB
3ds.cpp 55KB
Quake3Bsp.cpp 50KB
Octree.cpp 49KB
Quake3Bsp.cpp 44KB
Quake3Bsp.cpp 43KB
Ase.cpp 40KB
3ds.cpp 36KB
Octree.cpp 36KB
3ds.cpp 36KB
Octree.cpp 35KB
3DMath.cpp 33KB
Main.cpp 28KB
3DMath.cpp 27KB
Main.cpp 27KB
Quake3Bsp.cpp 26KB
Main.cpp 26KB
Obj.cpp 26KB
Main.cpp 25KB
共 937 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
资源评论
- zy_master2012-12-10好东西啊,终于找到了!!!
- Leon80862013-10-30不错,挺全的。
- emilily12252014-05-25不错挺棒的,效果好
- cakes2012-11-30还可以的 之前有看过 可以做点效果
bestcck
- 粉丝: 2
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于GPT的AI文档分析、阅读和问答工具.txt
- 《机器人控制系统的设计与Matlab仿真 》仿真程序
- AI-免费物品无损放大工具AI在线免费放大图片工具.txt
- C++基于DPLL算法的SAT的蜂窝数独游戏求解程序,程序设计综合课程设计,包括SAT求解器板块、蜂窝数独转化成cnf公式板块
- 微信小程序恐龙快跑小程序源码.zip
- 黑苹果OC引导-0.9.1
- WinSoft-ComPort-v6.5-for-Delphi-5-11-Downloadly
- Redis 服务等过期策略和内存淘汰策略解析
- debian配置FTP服务
- 基于Matlab和CPLEX的2变量机组组合调度程序(注释完全,可直接运行)(文档加Matlab源码)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功