您现在的位置: 中国IT实验室 >> 游戏开发 >> 开发文档 >> 文章正文
向量几何在游戏编程中的使用(六)
来源:中国IT实验室 作者:佚名 时间:2007-5-10

 

  最后,我们把p‘’再次变换回xyz坐标系,得到最终的p‘’‘

  |a  b  c| * p‘’ = |x  y  z| * p‘’‘

  p‘’‘ = |x  y  z|^-1 * |a  b  c| * p’‘

  p‘’‘ = |a  b  c| * p’‘

  最后

  p‘’‘ = |a  b  c| * RotMatrix * |a   b   c|^T * p = M * p

  这样就得到了xyz坐标系中点p围绕a旋转60度后的点。

  最后,我用Quake3引擎的相应函数(来自idSoftware ——quake3-1[1].32b-source——mathlib.c)来完成对这个算法的说明:

/*
===============
RotatePointAroundVector
dst是一个float[3],也就是p’’’
dir相当于a,point就是p,degrees是旋转度数
===============
*/
void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point,
float degrees ) {
float m[3][3];
float im[3][3];
float zrot[3][3];
float tmpmat[3][3];
float rot[3][3];
int i;
vec3_t vr, vup, vf;
float rad;

vf[0] = dir[0];
vf[1] = dir[1];
vf[2] = dir[2];
// 首先通过dir得到一个和它垂直的vr
// PERPendicularVector()函数用于构造和dir垂直的向量
// 也就是我们上面的第1步
PERPendicularVector( vr, dir );
// 通过cross multiply得到vup
// 现在已经构造出坐标轴向量vr, vup, vf
CrossProduct( vr, vf, vup );
// 把这三个单位向量放入矩阵中
m[0][0] = vr[0];
m[1][0] = vr[1];
m[2][0] = vr[2];

m[0][1] = vup[0];
m[1][1] = vup[1];
m[2][1] = vup[2];

m[0][2] = vf[0];
m[1][2] = vf[1];
m[2][2] = vf[2];
// 产生转置矩阵im
memcpy( im, m, sizeof( im ) );

im[0][1] = m[1][0];
im[0][2] = m[2][0];
im[1][0] = m[0][1];
im[1][2] = m[2][1];
im[2][0] = m[0][2];
im[2][1] = m[1][2];
// 构造旋转矩阵zrot
memset( zrot, 0, sizeof( zrot ) );
zrot[0][0] = zrot[1][1] = zrot[2][2] = 1.0F;

rad = DEG2RAD( degrees );
zrot[0][0] = cos( rad );
zrot[0][1] = sin( rad );
zrot[1][0] = -sin( rad );
zrot[1][1] = cos( rad );
// 开始构造变换矩阵M
// tmpmat = m * zrot
MatrixMultiply( m, zrot, tmpmat );
// rot = m * zrot * im
MatrixMultiply( tmpmat, im, rot );
// 则 rot = m * zrot * im 和我们上面推出的
// M = |a b c| * RotMatrix * |a b c|^T 一致

// 变换point这个点
// p’’’ = M * p
for ( i = 0; i < 3; i++ ) {
dst[i] = rot[i][0] * point[0] + rot[i][1] * point[1] + rot[i][2] * point[2];
}
}

上一页  [1] [2] [3] [4] [5] [6] 下一页  

收藏本文 责编:Kittoy 


相关文章
网络游戏的数据传输处理和防火墙穿透
新网游设计—(四)补充
新网游设计—(三)游戏概况
游戏开发工程实现方法理念
通过游戏策划阶段防治游戏外挂
推荐文章


 精彩友情推荐
·神州数码交换机
·神州数码交换机价格
·神州数码网络交换机
·netgear交换机
·网件交换机
·IDC资讯大全
·机房品质万里行
·IDC托管必备知识
·全国IDC报价
·网站推广优化
 基础入门  开发文档
 最新推荐
  多数的Windows程序都需要Windows.h和Windowsx.h这两个头文件,要确保使用它们。当然,你还需要其它......
游戏引擎演化史
在Windows上安装OGRE的方法
关于滤镜遮罩概念,Sobel 遮罩
游戏开发新手入门之Windows编程
游戏开发新手入门之位图化图形
教你实现卡通渲染的另类勾边方法
游戏设计大师谈如何成为一名游戏设
Visual C#编写 3D游戏框架示例
真正的 Java 学习从入门到精通
游戏开发经验——游戏开发的基本常
  针对于移动新出台的政策,需要尽快地把我们公司的游戏对应到不同的手机平台,这是针对市场策略的有利调整............
Quake-III代码里神奇的浮点开方函数
基于Dialogue的MFC程序调用DirectX
关于Kjava手机平台移植可行性报告
网络游戏的数据传输处理和防火墙穿
浅谈网游的数据传输处理和防火墙穿
向量几何在游戏编程中的使用(六)
向量几何在游戏编程中的使用(五)
向量几何在游戏编程中的使用(四)
向量几何在游戏编程中的使用(三)
向量几何在游戏编程中的使用(二)
  培训中心