这是正确计算 Vector3 Transform 和 TransformCooperative 的方法吗?

发布于 2024-12-23 16:42:20 字数 1558 浏览 1 评论 0原文

我一直在研究 D3DXVec3Transform 和 D3DXVec3TransformCoord 函数的运行方式,想知道这是否是正确的数学方式,如果不是,有人可以解释一下原因。我知道已经有 DirectX 函数可以做到这一点,但是,我一直在尝试了解更多有关幕后数学的知识,并且通过研究我得出了这一点。

D3DXVECTOR3 Vec3Transform(D3DXVECTOR3 &vCoordinate, D3DXMATRIX &mTransform)
{
    D3DXVECTOR3 vWorking;

    vWorking.x = (vCoordinate.x * mTransform._11) + (vCoordinate.y * mTransform._21) + (vCoordinate.z * mTransform._31) + mTransform._41;
    vWorking.y = (vCoordinate.x * mTransform._12) + (vCoordinate.y * mTransform._22) + (vCoordinate.z * mTransform._32) + mTransform._42;
    vWorking.z = (vCoordinate.x * mTransform._13) + (vCoordinate.y * mTransform._23) + (vCoordinate.z * mTransform._33) + mTransform._43;

    return D3DXVECTOR3(vWorking.x, vWorking.y, vWorking.z);
}

D3DXVECTOR3 Vec3TransformCoordinate(D3DXVECTOR3 &vCoordinate, D3DXMATRIX &mTransform)
{
    D3DXVECTOR4 vWorking;

    vWorking.x = (vCoordinate.x * mTransform._11) + (vCoordinate.y * mTransform._21) + (vCoordinate.z * mTransform._31) + mTransform._41;
    vWorking.y = (vCoordinate.x * mTransform._12) + (vCoordinate.y * mTransform._22) + (vCoordinate.z * mTransform._32) + mTransform._42;
    vWorking.z = (vCoordinate.x * mTransform._13) + (vCoordinate.y * mTransform._23) + (vCoordinate.z * mTransform._33) + mTransform._43;
    vWorking.w = 1 / ((vCoordinate.x * mTransform._14) + (vCoordinate.y * mTransform._24) + (vCoordinate.z * mTransform._34) + mTransform._44);

    return D3DXVECTOR3(vWorking.x * vWorking.w, vWorking.y * vWorking.w, vWorking.z * vWorking.w);
}

I have been looking into how the D3DXVec3Transform and D3DXVec3TransformCoord functions are operating was wondering if this is the correct way the math should be, if not, could someone please explain why. I understand that there are already DirectX functions to do this, however, I have been attempting to learn more about the math behind the scenes and from research I have come to this.

D3DXVECTOR3 Vec3Transform(D3DXVECTOR3 &vCoordinate, D3DXMATRIX &mTransform)
{
    D3DXVECTOR3 vWorking;

    vWorking.x = (vCoordinate.x * mTransform._11) + (vCoordinate.y * mTransform._21) + (vCoordinate.z * mTransform._31) + mTransform._41;
    vWorking.y = (vCoordinate.x * mTransform._12) + (vCoordinate.y * mTransform._22) + (vCoordinate.z * mTransform._32) + mTransform._42;
    vWorking.z = (vCoordinate.x * mTransform._13) + (vCoordinate.y * mTransform._23) + (vCoordinate.z * mTransform._33) + mTransform._43;

    return D3DXVECTOR3(vWorking.x, vWorking.y, vWorking.z);
}

D3DXVECTOR3 Vec3TransformCoordinate(D3DXVECTOR3 &vCoordinate, D3DXMATRIX &mTransform)
{
    D3DXVECTOR4 vWorking;

    vWorking.x = (vCoordinate.x * mTransform._11) + (vCoordinate.y * mTransform._21) + (vCoordinate.z * mTransform._31) + mTransform._41;
    vWorking.y = (vCoordinate.x * mTransform._12) + (vCoordinate.y * mTransform._22) + (vCoordinate.z * mTransform._32) + mTransform._42;
    vWorking.z = (vCoordinate.x * mTransform._13) + (vCoordinate.y * mTransform._23) + (vCoordinate.z * mTransform._33) + mTransform._43;
    vWorking.w = 1 / ((vCoordinate.x * mTransform._14) + (vCoordinate.y * mTransform._24) + (vCoordinate.z * mTransform._34) + mTransform._44);

    return D3DXVECTOR3(vWorking.x * vWorking.w, vWorking.y * vWorking.w, vWorking.z * vWorking.w);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

和影子一齐双人舞 2024-12-30 16:42:20

通过查看 D3DX 库中的类似函数,您似乎已经忠实地实现了它们的功能。

拥有一个通过 4x4 矩阵变换 (x,y,z,0) 的函数也可能会有所帮助,因为这在平移方向(例如对象的速度或表面的法线)时非常有用。向量将在不应用平移的情况下进行变换,这会破坏方向。

From looking at similar functions in the D3DX Library it seems you have implemented their function faithfully.

It may also help to have a function which transforms (x,y,z,0) by a 4x4 matrix as this is useful when translating directions, such as an object's velocity or a surface's normal. The vector will be transformed without translations being applied, which would have ruined the direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文