DrectX 切割 知识点

HRESULT D3DXIntersect(
  _In_   LPD3DXBASEMESH pMesh,
  _In_   const D3DXVECTOR3 *pRayPos,
  _In_   const D3DXVECTOR3 *pRayDir,
  _Out_  BOOL *pHit,
  _Out_  DWORD *pFaceIndex,
  _Out_  FLOAT *pU,
  _Out_  FLOAT *pV,
  _Out_  FLOAT *pDist,
  _Out_  LPD3DXBUFFER *ppAllHits,
  _Out_  DWORD *pCountOfHits
);

Parameters

pMesh [in]

Type: LPD3DXBASEMESH

Pointer to an ID3DXBaseMesh interface, representing the mesh to be tested.

pRayPos [in]

Type: const D3DXVECTOR3*

Pointer to a D3DXVECTOR3 structure, specifying the point where the ray begins.

pRayDir [in]

Type: const D3DXVECTOR3*

Pointer to a D3DXVECTOR3 structure, specifying the direction of the ray.

pHit [out]

Type: BOOL*

Pointer to a BOOL. If the ray intersects a triangular face on the mesh, this value will be set to TRUE. Otherwise, this value is set to FALSE.

pFaceIndex [out]

Type: DWORD*

Pointer to an index value of the face closest to the ray origin, if pHit is TRUE.

pU [out]

Type: FLOAT*

Pointer to a barycentric hit coordinate, U.

pV [out]

Type: FLOAT*

Pointer to a barycentric hit coordinate, V.

pDist [out]

Type: FLOAT*

Pointer to a ray intersection parameter distance.

ppAllHits [out]

Type: LPD3DXBUFFER*

Pointer to an ID3DXBuffer object, containing an array of D3DXINTERSECTINFO structures.

pCountOfHits [out]

Type: DWORD*

Pointer to a DWORD that contains the number of entries in the ppAllHits array.



 
HRESULT SetRenderState(
  D3DRENDERSTATETYPE State,
  DWORD Value
);


D3DRS_CULLMODE 这个参数用来指定三角形背面的剔除方式。它的值是一个D3DCULL类型的枚举类型。D3DCULL_NONE,不要剔除背面;D3DCULL_CW,按照顺时针的方向的顶点剔除背面;D3DCULL_CCW,按照逆时针方向剔除背面。而最后一个就是默认值,还没弄清楚区别在什么地方。


HRESULT SetClipPlane(
  DWORD Index,
  CONST float * pPlane
);


参数:
第一个是索引,不用说了。

第二个是存着 A B C D的数组。
这个数组最后会用来构建 Ax+By+Cz+Dw = 0;平面。

然后顶点会根据自已的位置(x,y,z,w)来进行判断。如果Ax+By+Cz+Dw >= 0。则表示在平面前方,保留。反之则在后方,被裁剪掉。

值得注意的时,在固定管线使用平面裁剪的时候,是在世界坐标系中处理的。


而用SHADER的时候,是在裁剪空间中处理的。(即顶点输出的时候的坐标系)
貌似还是太抽象。比如顶点输入坐标是pos   此时的坐标变换阵是WVP,则 Output.pos = mul(pos,WVP);  那么,此时的裁剪空间就是Output.pos对应的坐标系空间。
 

另外,默认情况下D3DRS_CLIPPLANEENABLE 是没有打开的,应该在SetRenderState中手工打开。 






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值