DirectX学习:D3DX中关于平面的函数

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.
 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值