社区
游戏开发
帖子详情
如何自己实现D3DXMatrixRotationAix和D3DXMatrixRotationYawPitchRoll??
lyzcom
2003-11-27 11:43:44
如何自己实现这两个函数的功能?要完全和D3DX库的这两个函数实现的功能一样。
因为我数学不太好,弄这两个函数三天了,但是总是有问题。不是有偏差就是完全不对。哪位大哥帮帮忙吧,我实在不行了。
另外,能不能推荐一本专门讲3D数学与物理学的书?我只要有一本这样的参考书就可以马上学上来,毕竟数学基本不是很差。
...全文
148
1
打赏
收藏
举报
写回复
1 条
回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
ttmmdd
2003-11-27
推荐"线性代数"和"计算机图型学"(电子工业出版社的?就是从老外的教材翻译的那个)
我手上只有轴角<->四元式 欧拉角<->四元式 矩阵(行矩阵 3列X4行 )<->四元式的转换的代码.
你可以再参考下网上3DMAX的开原部分,和网上的一些3D引擎.
附代码
void Quat::ConvertFromEulerAngle(const float fYaw,const float fPitch,const float fRoll)
{
float fSinYaw = sinf( fYaw/2.0f );
float fSinPitch = sinf( fPitch/2.0f );
float fSinRoll = sinf( fRoll/2.0f );
float fCosYaw = cosf( fYaw/2.0f );
float fCosPitch = cosf( fPitch/2.0f );
float fCosRoll = cosf( fRoll/2.0f );
x = fSinRoll * fCosPitch * fCosYaw - fCosRoll * fSinPitch * fSinYaw;
y = fCosRoll * fSinPitch * fCosYaw + fSinRoll * fCosPitch * fSinYaw;
z = fCosRoll * fCosPitch * fSinYaw - fSinRoll * fSinPitch * fCosYaw;
w = fCosRoll * fCosPitch * fCosYaw + fSinRoll * fSinPitch * fSinYaw;
}
void Quat::ConvertFromMatrix(const Matrix3 &mat)
{
float tr, su;
int i;
tr=mat.m[0][0]+mat.m[1][1]+mat.m[2][2];
if(tr>0)
{
su = sqrtf(tr + 1.0f);
w = 0.5f * su;
su =0.5f/su;
x = (mat.m[2][1] - mat.m[1][2]) * su;
y = (mat.m[0][2] - mat.m[2][0]) * su;
z = (mat.m[1][0] - mat.m[0][1]) * su;
}
else
{
i =0;
if(mat.m[1][1] > mat.m[0][0]) i = 1;
if(mat.m[2][2] > mat.m[i][i]) i = 2;
switch (i)
{
case 0:
su = sqrtf((mat.m[0][0] - (mat.m[1][1] + mat.m[2][2])) + 1);
x = 0.5f * su;
su =0.5f/su;
y = (mat.m[0][1] + mat.m[1][0]) * su;
z = (mat.m[2][0] + mat.m[0][2]) * su;
w=(mat.m[2][1] - mat.m[1][2]) * su;
break;
case 1:
su = sqrtf((mat.m[1][1] - (mat.m[2][2] + mat.m[0][0])) + 1);
y = 0.5f*su;
su = 0.5f/su;
z = (mat.m[1][2] + mat.m[2][1]) * su;
x = (mat.m[0][1] + mat.m[1][0]) * su;
w = (mat.m[0][2] - mat.m[2][0]) * su;
break;
case 2:
su = sqrtf((mat.m[2][2]-(mat.m[0][0]+mat.m[1][1]))+1);
z=0.5f*su;
su=0.5f/su;
x = (mat.m[2][0]+mat.m[0][2]) * su;
y = (mat.m[1][2]+mat.m[2][1]) * su;
w = (mat.m[1][0]-mat.m[0][1]) * su;
break;
}
}
}
void Quat::ConvertToMatrix ( Matrix3 &tm)
{
float xx = x*x; float yy = y*y; float zz = z*z;
float xy = x*y; float xz = x*z; float yz = y*z;
float wx = w*x; float wy = w*y; float wz = w*z;
tm.m[0][0] = 1 - 2 * ( yy + zz );
tm.m[0][1] = 2 * ( xy - wz );
tm.m[0][2] = 2 * ( xz + wy );
tm.m[1][0] = 2 * ( xy + wz );
tm.m[1][1] = 1 - 2 * ( xx + zz );
tm.m[1][2] = 2 * ( yz - wx );
tm.m[2][0] = 2 * ( xz - wy );
tm.m[2][1] = 2 * ( yz + wx );
tm.m[2][2] = 1 - 2 * ( xx + yy );
tm.m[3][0] = tm.m[3][1] = tm.m[3][2] = 0.0f;
}
void Quat::ConvertToAxisAngle (Point3 &vector ,float & angle )
{
float fTheta = acosf(w) * 2.0f;
vector.x = x / sinf( fTheta/2.0f );
vector.y = y / sinf( fTheta/2.0f );
vector.z = z / sinf( fTheta/2.0f );
angle=fTheta;
}
void Quat::ConvertFromAxisAngle(Point3 &vector , float & angle )
{
this->w=cosf (angle/2.0f);
this->x=sinf(angle/2.0f)*vector.x;
this->y=sinf(angle/2.0f)*vector.y;
this->z=sinf(angle/2.0f)*vector.z;
}
打赏
举报
回复
赞
相关推荐
d3
.js
实现
文字云效果 例子
d3
.js
实现
文字云效果 例子
结合
d3
.js
实现
气象数据的可视化
本文将结合
d3
.js
实现
在mapboxGL中格点气象数据的展示。 效果
实现
1.数据格式说明 需要将格点气象数据
实现
前端的展示,数据传输的方式有三种:1、json;2、二进制;3、灰度图。三种方式各有优劣,这个需要在实际的...
D3
js快速入门——用最新版
D3
js
实现
树图
怎么用
D3
.js 开发一个树图3.1 前置基础3.2
d3
开发树图流程3.3 动手
实现
一个树图3.3.1 普通tide tree3.3.2 你的树图不简单—— radio tide tree3.3.3 更多可能——更多类型的树图 引言 上周我们组新开项目,技术...
计算机缺失
d3
dcompiler43.dll,电脑
d3
dcompiler43.dll文件丢失怎么解决?
最近有很多小伙伴在使用win7系统的时候,遇到了系统提示
d3
dcompiler43.dll文件丢失的问题,那么,这个问题该怎么解决呢?这种文件的丢失一般影响到玩游戏,因为文件没有及时的更新,其实只要我们重新网上下载同一个...
vue+
d3
v6
实现
动态知识图谱可视化展示
目录一、
d3
@v6介绍 一、
d3
@v6介绍
d3
学习文档
d3
-version6版本改动 官方DEMO参考
发帖
游戏开发
微信扫一扫
点击复制链接
分享社区
8161
社区成员
2.3w+
社区内容
游戏开发相关内容讨论专区
社区管理员
加入社区
帖子事件
创建了帖子
2003-11-27 11:43
社区公告
暂无公告