DirectX9 平面

来源:互联网 发布:网络虚拟物品交易平台 编辑:程序博客网 时间:2024/04/27 18:23

D3DXPLANE

The D3DX library uses the followingstructure for a plane:

typedef struct D3DXPLANE

{

#ifdef __cplusplus

public:

D3DXPLANE() {}

D3DXPLANE( CONST FLOAT* );

D3DXPLANE( CONST D3DXFLOAT16* );

D3DXPLANE( FLOAT a, FLOAT b, FLOAT c,FLOAT d );

// casting

operator FLOAT* ();

operator CONST FLOAT* () const;

// unary operators

D3DXPLANE operator + () const;

D3DXPLANE operator - () const;

// binary operators

BOOL operator == ( CONST D3DXPLANE& )const;

BOOL operator != ( CONST D3DXPLANE& )const;

#endif //__cplusplus

FLOAT a, b, c, d;

} D3DXPLANE, *LPD3DXPLANE;

 

This next D3DX functionevaluatesn n·p+dfor a particularplane and point:

FLOAT D3DXPlaneDotCoord(

CONST D3DXPLANE *pP, // plane.

CONST D3DXVECTOR3 *pV // point.

);

// Test the locality of a point relativeto a plane.

D3DXPLANE p(0.0f, 1.0f, 0.0f, 0.0f);

D3DXVECTOR3 v(3.0f, 5.0f, 2.0f);

float x = D3DXPlaneDotCoord( &p,&v );

if( x approximately equals 0.0f ) // v iscoplanar to the plane.

if(x>0) //visinpositive half-space.

if(x<0) //visinnegative half-space.

 

The D3DX library provides the followingfunction to perform thisD3DXPlaneFromPointNormalcalculation:

D3DXPLANE *D3DXPlaneFromPointNormal(

D3DXPLANE* pOut, // Result.

CONST D3DXVECTOR3* pPoint, // Point onthe plane.

CONST D3DXVECTOR3* pNormal // The normalof the plane.

);

 

The D3DX library provides the followingfunction to compute a plane, giventhree points on the plane:

D3DXPLANE *D3DXPlaneFromPoints(

D3DXPLANE* pOut, // Result.

CONST D3DXVECTOR3* pV1, // Point 1 on theplane.

CONST D3DXVECTOR3* pV2, // Point 2 on theplane.

CONST D3DXVECTOR3* pV3 // Point 3 on theplane.

);

 

We can use the following D3DX functionto normalize a plane’s normal vector:

D3DXPLANE *D3DXPlaneNormalize(

D3DXPLANE *pOut, // Resulting normalizedplane.

CONST D3DXPLANE *pP // Input plane.

);

 

we can transform a plane(n,d) by treating it as a 4D vector and multiplying it bythe inverse-transpose ofthe desired transformation matrix. Note that the plane’s normal vector must benormalized

first.We use the followingD3DX function to do this:

D3DXPLANE *D3DXPlaneTransform(

D3DXPLANE *pOut, // Result

CONST D3DXPLANE *pP, // Input plane.

CONST D3DXMATRIX *pM // Transformationmatrix.

);

Sample code:

D3DXMATRIX T(...); // Init. T to adesired transformation.

D3DXMATRIX inverseOfT;

D3DXMATRIX inverseTransposeOfT;

D3DXMatrixInverse( &inverseOfT, 0,&T );

D3DXMatrixTranspose(&inverseTransposeOfT, &inverseOfT );

D3DXPLANE p(...); // Init. Plane.

D3DXPlaneNormalize( &p, &p ); //make sure normal is normalized.

D3DXPlaneTransform( &p, &p,&inverseTransposeOfT );

0 0
原创粉丝点击