D3DX矩阵函数

来源:互联网 发布:默小宝的淘宝店假货 编辑:程序博客网 时间:2024/04/29 08:26
1:D3DXMatrixAffineTransformation():创建一个仿射变换变换矩阵。NULL的参数就会当作是单位矩阵。
定义
D3DXMATRIX *WINAPI D3DXMatrixAffineTransformation(           D3DXMATRIX *pOut,
     FLOAT Scaling,
     const D3DXVECTOR3 *pRotationCenter,
     const D3DXQUATERNION *pRotation,
     const D3DXVECTOR3 *pTranslation
);
参数
pOut [in, out] 指向D3DXMATRIX结构返回结果的矩阵。
Scaling [in] 缩放系数。
pRotationCenter [in] 指向D3DXVECTOR3结构指针,旋转中心向量。如果设置为NULL,就用一个单位矩阵代替Mrc 。
pRotation [in] 指向D3DXQUATERNION结构旋转矩阵。如果参数为NULL,就用单位矩阵Mr 代替。
pTranslation [in] 指向D3DXVECTOR3 结构变换向量。如果为NULL,就用单位矩阵Mt 。
返回值:
指向 D3DXMATRIX 结构的仿射变换矩阵。
说明:
本函数是用下面的公式来计算一个仿射变换矩阵:
     Mout = Ms * (Mrc)-1 * Mr * Mrc * Mt
其中:
     Mout = 输出矩阵 (pOut)
     Ms = 缩放矩阵 (Scaling)
     Mrc = 旋转矩阵中心 (pRotationCenter)
     Mr = 旋转矩阵 (pRotation)
     Mt = 平移矩阵 (pTranslation)
返回值跟pOut 是一样的,这样可以让D3DXMatrixAffineTransformation 成为其它函数参数使用。2D的仿射变换矩阵用D3DXMatrixAffineTransformation2D
2:D3DXMatrixAffineTransformation2D():在X-Y平面创建一个仿射变换变换矩阵。NULL的参数就会当作是单位矩阵
3:D3DXMatrixDecompose():分解一个3D变换矩阵为缩放系数,旋转分量和平移向量。
4:D3DXMatrixDeterminant():计算矩阵行列式值。
5:D3DXMatrixIdentity():创建一个单位化矩阵
6:D3DXMatrixInverse():计算矩阵的逆矩阵。如果逆阵不存在,就返回NULL;
7:D3DXMatrixIsIdentity():判断一个矩阵是否是单位阵;
8:D3DXMatrixLookAtLH():Builds a left-handed, look-at matrix.
D3DXMatrixLookAtRH():
9:D3DXMatrixMultiply():矩阵的乘积;
10:D3DXMatrixMultiplyTranspose():计算两个矩阵乘积之后再转置,此函数常用在vertex and pixel shaders中;
11:D3DXMatrixOrthoLH()、D3DXMatrixOrthoRH():
Builds a left-handed orthographic projection matrix.
12:D3DXMatrixOrthoOffCenterLH(),D3DXMatrixOrthoOffCenterRH():
13:D3DXMatrixPerspectiveFovLH(),D3DXMatrixPerspectiveFovRH():
14:D3DXMatrixPerspectiveLH(),D3DXMatrixPerspectiveRH():
15:D3DXMatrixReflect()
从平面方程创建一个平面反射矩阵。
说明:
本函数先规格化平方程的系数,然后再创建平面方程的反射矩阵。
函数返回值跟pOut 参数返回值是一样的。这样可以让函数D3DXMatrixReflect作为其它函数的参数使用。
本函数用下面的公式来计算平面反射矩阵:
P = normalize(Plane);
-2 * P.a * P.a + 1   -2 * P.b * P.a       -2 * P.c * P.a         0
-2 * P.a * P.b       -2 * P.b * P.b + 1   -2 * P.c * P.b         0
-2 * P.a * P.c       -2 * P.b * P.c       -2 * P.c * P.c + 1     0
-2 * P.a * P.d       -2 * P.b * P.d       -2 * P.c * P.d         1
如果做一个物体沿一个平面做镜像,可以用此函数;
16:D3DXMatrixRotationAxis():创建一个绕一个轴旋转的矩阵;
17:D3DXMatrixRotatioxnX;D3DXMatrixRotationY;D3DXMatrixRotationZ;
18:D3DXMatrixRotationQuaternion():Builds a rotation matrix from a quaternion
19:D3DXMatrixRotationYawPitchRoll
Builds a matrix with a specified yaw, pitch, and roll.
D3DXMATRIX * D3DXMatrixRotationYawPitchRoll(
   D3DXMATRIX * pOut,
   FLOAT Yaw,
   FLOAT Pitch,
   FLOAT Roll
);
Parameters
pOut
[in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
Yaw
[in] Yaw around the y-axis, in radians.
Pitch
[in] Pitch around the x-axis, in radians.
Roll
[in] Roll around the z-axis, in radians.
Return Values
Pointer to a D3DXMATRIX structure with the specified yaw, pitch, and roll.
注意转换的次序是先roll,再pitch,然后是yaw;即,先绕Z轴转,再绕X轴旋转,再绕X轴旋转;
20:D3DXMatrixScaling():创建一个缩放矩阵;
21:D3DXMatrixShadow():
创建一个平面的阴影矩阵。
定义:
D3DXMATRIX *WINAPI D3DXMatrixShadow(           D3DXMATRIX *pOut,
     CONST D3DXVECTOR4 *pLight,
     CONST D3DXPLANE *pPlane
);
参数:
pOut
[in, out] 指向D3DXMATRIX 结构的操作结果矩阵。
pLight
[in] 指向D3DXVECTOR4 结构的光线位置向量。
pPlane
[in] 指向D3DXPLANE 结构的平面方程。
返回值:
指向D3DXMATRIX 结构的矩阵,它是用来把几何在平面阴影变换矩阵。
说明:
如果从光线照射几何物体有阴影,就可以用函数D3DXMatrixShadow 计算阴影变换矩阵。
函数返回值跟pOut 参数返回值是一样的。这样可以让函数D3DXMatrixShadow作为其它函数的参数使用。
用下面的方法计算这个矩阵:
P = normalize(Plane);
L = Light;
d = dot(P, L)
P.a * L.x + d   P.a * L.y       P.a * L.z       P.a * L.w  
P.b * L.x       P.b * L.y + d   P.b * L.z       P.b * L.w  
P.c * L.x       P.c * L.y       P.c * L.z + d   P.c * L.w  
P.d * L.x       P.d * L.y       P.d * L.z       P.d * L.w + d
如果光线的W分量是0,表示从原点发出的方向光。如果W分量是1,表示它是一个点光源。
在一个产生物体平面阴影的Demo中看到如下代码:
        // position shadow
        D3DXVECTOR4 lightDirection(0.707f, -0.707f, 0.707f, 0.0f);
          /*他定义的面是XZ平面*/
        D3DXPLANE groundPlane(0.0f, -1.0f, 0.0f, 0.0f);
        D3DXMATRIX S;
        D3DXMatrixShadow(
               &S,
               &lightDirection,
               &groundPlane);
        D3DXMATRIX T;
        D3DXMatrixTranslation(
               &T,
               TeapotPosition.x,
               TeapotPosition.y,
               TeapotPosition.z);
        D3DXMATRIX W = T * S;
        Device->SetTransform(D3DTS_WORLD, &W);
22:D3DXMatrixTransformation(),D3DXMatrixTransformation2D()
创建一个变换矩阵。如果参数设置为NULL,就当作单位矩阵处理。
定义:
D3DXMATRIX *WINAPI D3DXMatrixTransformation(           D3DXMATRIX *pOut,
     CONST D3DXVECTOR3 *pScalingCenter,
     CONST D3DXQUATERNION *pScalingRotation,
     CONST D3DXVECTOR3 *pScaling,
     CONST D3DXVECTOR3 *pRotationCenter,
     CONST D3DXQUATERNION *pRotation,
     CONST D3DXVECTOR3 *pTranslation
);
参数:
pOut [in, out] 指向D3DXMATRIX 结构的操作结果矩阵。
pScalingCenter [in] 指向D3DXVECTOR3 结构的缩放中心点向量。如果为NULL,Msc 矩阵就是单位矩阵。
pScalingRotation [in] 指向D3DXQUATERNION 结构的缩放和旋转的四元组。如果参数为NULL,Msr 矩阵就是单位矩阵。
pScaling [in] 指向D3DXVECTOR3 结构的缩放向量。如果参数为NULL,Ms 矩阵就是单位矩阵。
pRotationCenter [in] 指向D3DXVECTOR3 结构的旋转中心向量。如果参数为NULL,Mrc 矩阵是单位矩阵。
pRotation [in] 指向D3DXQUATERNION 结构的旋转的四元组。如果参数为NULL,Mr 矩阵就是单位矩阵。
pTranslation
[in] 指向D3DXVECTOR3 结构的平移向量。如果参数是NULL,Mt 矩阵就是单位矩阵。
返回值:指向 D3DXMATRIX 结构的变换矩阵。matrix.
说明:本函数用下面的公式计算变换矩阵:
     Mout = (Msc)-1 * (Msr)-1 * Ms * Msr * Msc * (Mrc)-1 * Mr * Mrc * Mt
其中:
    Mout = 输出矩阵 (pOut)
     Msc = 缩放中心矩阵 (pScalingCenter)
     Msr = 缩放旋转矩阵 (pScalingRotation)
     Ms = 缩放矩阵 (pScaling)
     Mrc = 旋转中心矩阵 (pRotationCenter)
     Mr = 旋转矩阵 (pRotation)
     Mt = 平移矩阵 (pTranslation)
函数返回值跟pOut 参数返回值是一样的。这样可以让函数D3DXMatrixTransformation作为其它函数的参数使用。
如果是2D的变换矩阵,就要用函数 D3DXMatrixTransformation2D。
23:D3DXMatrixTranslation():
Builds a matrix using the specified offsets.
24:D3DXMatrixTranspose():对矩阵进行转置
原创粉丝点击