1,.概念:平面可以用一个向量n和平面中一点p0来表示。其中n是平面的法向量,与这个平面垂直。
np + d = 0; d = -n.p0;//d给出了坐标原点到该平面最短的有符号距离
D3DXPLANE;
2.点和平面的空间关系
FLOAT D3DXPlaneDotCoord{
CONST D3DXPLAEN*pP;//plane
CONST D3DXVECTOR3*pV;//point
}
//test
D3DXPLANE p(3.0f,5.0f,2.0f);
D3DXVECTOR3 v(3.0f,5.0f,2.0f);
float x = D3DXPlaneDotCoord(&p,&v);
if(x approximately equals 0.0f);//v is coplanar to the plane;
if(x>0);//v is in positive half_space;
if(x<0);// v is in negative half_space;
3.平面的创建
//给定法线n和平面上已知点p0
D3DXPLANE* D3DXPlaneFromPointNormal(
D3DXPLANE*pOut,
CONST D3DXVECTOR3*pPoint,
CONST D3DXVECTOR3* pNormal
);
//指定平面上不共线3个点
D3DXPLANE*D3DXPlaneFromPoints(D3DXPLANE*pOut,
CONST D3DXVECTOR3*pV1,//point 1 on the plane
CONST D3DXVECTOR3*pV2,//point 2 on the plane
CONST D3DXVECTOR3*pV3//point 3 on the plane
);
4.平面的规范化
D3DXPLANE*D3DXPlaneNormalize(
D3DXPLANE*pOut,
CONST D3DXPLANE*pP;
);
5.平面的变换
D3DXPLANE*D3DXPlaneTransform(
D3DXPLANE*pOut,//result
CONST D3DXPLANE*pP,//input plane
CONST D3DXMATRX *pM//Transformation matrix
);
//test
D3DXMATRIX T(...);
D3DXMATRIX inverseOfT;
D3DXMATRIX inverseTransposeOfT;
D3DXMatrixInverse(&inverseOfT,0,&T);//逆矩阵
D3DXMatrixTranspose(&inverseTransposeOfT,&inverseOfT);//转置矩阵
D3DXPlaneTransform(&p,&p,&inverseTransposeOfT);