1:D3DXPlaneFromPoints():通过三个点来求得一个平面;
2:D3DXPlaneFromPointNormal():通过一个点和一个法线来求得一个平面;
3:D3DXPlaneIntersectLine():直线与平面的交点;
4:D3DXPlaneDotCoord():利用该函数返回值的符号可决定点在平面的哪一侧。和下面不同的是,向量点为一个3D向量;W值假定为1;
D3DXPlaneDot():计算一个平面和一个4D向量的点积;可以用它来计算一个点和一个平面的位置关系;和上面不同的是,此向量点为一个4D向量,
对于1个给定了法向量n和内部一点p0的平面,任意1点p与该平面的位置关系可用两向量的点积n . (p - p0) 进行判断,分为如下的3种情形:
(1) 点p在法向量n的同一侧,即n . (p - p0) > 0
(2) 点p在平面上,即n . (p - p0) = 0
(3) 点p在法向量n的反侧,即n . (p - p0) < 0
对于以方程式ax+by+cz+d=0给出的平面,由系数a, b和c构成的向量(a, b, c)必然是1个垂直于该平面的向量法向量。
称向量(a, b, c)为平面ax + by + cz +d = 0的默认法向量。
判断一点p(x0, y0, z0)与ax+by+z+d=0平面的位置关系,可以直接利用ax0+by0+cz0+d的符号来决定。
ax0+by0+cz0+d > 0表示点p在默认法向量的一侧,也可以说是位于平面的前方。
ax0+by0+cz0+d = 0表示点p在平面上。
ax0+by0+cz0+d < 0表示点p在默认法向量的另一侧,也可以说是位于平面的后方。
5:D3DXPlaneDotNormal():用来计算一个平面和一个3D向量的点积,向量的W值假定为0;
给定一个平面 (a, b, c, d) 和一个3D向量 (x, y, z) ,函数的返回值是 a*x + b*y + c*z + d*0. 此函数常常用来计算一个平面法线和另一个法的夹角;
6:D3DXPlaneNormalize(D3DXPLANE *pOut, CONST D3DXPLANE *pP):平面的单位化,如果平面ax+by+cz+d=0的默认法向量n=(a,b,c)为单位向量,那么该平面称为单位化平面。
7:D3DXPlaneTransform():平面的转换;
我们可以把一个法向量和距离的形式的平面进行转换,我们所做的只是把这个平面当作4D向量,并且把他和一个需要的 转换矩阵的逆转置形式相乘。
注意:这个平面必须先进行单位化。
所需要的D3DX函数是:
D3DXPLANE *D3DXPlaneTransform(
D3DXPLANE *pOut, // 输出结果
CONST D3DXPLANE *pP, // 输入平面.
CONST D3DXMATRIX *pM // 转换矩阵.
);
例子代码
D3DXMATRIX T(...); // 初始化需要的转换矩阵
D3DXMATRIX inverseOfT;
D3DXMATRIX inverseTransposeOfT;
D3DXMatrixInverse( &inverseOfT, 0, &T );//逆矩阵
D3DXMatrixTranspose( &inverseTransposeOfT, &inverseOfT );
D3DXPLANE p(...); // 初始化平面
D3DXPlaneNormalize( &p, &p ); // 保证平面正规化
D3DXPlaneTransform( &p, &p, &inverseTransposeOfT );//进行转换
SDK如是说:
Examples
This example transforms a plane by applying a non-uniform scale.
D3DXPLANE planeNew;
D3DXPLANE plane(0,1,1,0);
D3DXPlaneNormalize(&plane, &plane);
D3DXMATRIX matrix;
D3DXMatrixScaling(&matrix, 1.0f,2.0f,3.0f);
D3DXMatrixInverse(&matrix, NULL, &matrix);
D3DXMatrixTranspose(&matrix, &matrix);
D3DXPlaneTransform(&planeNew, &plane, &matrix);
A plane is described by ax + by + cz + dw = 0. The first plane is created with (a,b,c,d) = (0,1,1,0), which is a plane described by y + z = 0. After scaling, the new plane contains (a,b,c,d) = (0, 0.353f, 0.235f, 0), which shows the new plane to be described by 0.353y + 0.235z = 0.
The parameter pM contains the inverse transpose of the transformation matrix. The inverse transpose is required by this method so that the normal vector of the transformed plane can be correctly transformed as well.
8:D3DXPlaneScale():用一个给定的缩放因子来缩放一个平面;
9:D3DXPlaneTransformArray():转换一组平面;
SDK如是说:
This example transforms one plane by applying a non-uniform scale.
#define ARRAYSIZE 4
D3DXPLANE planeNew[ARRAYSIZE];
D3DXPLANE plane[ARRAYSIZE];
for(int i = 0; i < ARRAYSIZE; i++)
{
plane = D3DXPLANE( 0.0f, 1.0f, 1.0f, 0.0f );
D3DXPlaneNormalize( &plane[i], &plane[i] );
}
D3DXMATRIX matrix;
D3DXMatrixScaling( &matrix, 1.0f, 2.0f, 3.0f );
D3DXMatrixInverse( &matrix, NULL, &matrix );
D3DXMatrixTranspose( &matrix, &matrix );
D3DXPlaneTransformArray( &planeNew, sizeof (D3DXPLANE), &plane,
sizeof (D3DXPLANE), &matrix, ARRAYSIZE );
A plane is described by ax + by + cz + dw = 0. The first plane is created with (a,b,c,d) = (0,1,1,0), which is a plane described by y + z = 0. After scaling, the new plane contains (a,b,c,d) = (0, 0.353f, 0.235f, 0), which shows the new plane to be described by 0.353y + 0.235z = 0.
The parameter pM, contains the inverse transpose of the transformation matrix. The inverse transpose is required by this method so that the normal vector of the transformed plane can be correctly transformed as well.