我找到了与函数“D3DXIntersectTri”的交点距离。现在,使用距离值,我怎样才能找到该点值?
IDE:德尔福 - 绝地
语言:帕斯卡
DirectX 9
编辑:实际上我有 2 个圆柱体,只想渲染 3 维中的相交部分。见图片:
如MSDN 文章中所述,您可以使用重心坐标计算点:
p = p1 + pU * (p2 - p1) + pV(p3 - p1)
渲染到屏幕的某些部分是模板缓冲区的任务。除非您想从交叉点创建一个新的顶点缓冲区(可以通过剪裁部分来创建,这并不容易),否则使用模板缓冲区更有效。
模板缓冲区是一个保存整数值的缓冲区。您必须使用深度缓冲区创建它,并指定正确的格式(例如 D24S8)。然后,您可以指定何时丢弃像素。这是想法:
Clear stencil buffer to 0
Enable solid rendering
Enable stencil buffer
Set blend states to not draw anything (Souce: 0, Destination: 1)
Disable depth testing, enable backface culling
Set the following stencil states:
CompareFunc to Always
StencilRef to 1
StencilWriteMask to 255
StencilFail to Replace
StencilPass to Replace
//this will set value 1 to every pixel that will be drawn
Draw the first cylinder
Now set the following stencil states:
CompareFunc to Equal
StencilFail to Keep //this keeps the value where the stencil test fails
StencilPass to Increment //this increments the value to 2 where stencil test passes
Draw the second cylinder
//Now there is a 2 in the stencil buffer where the cylinders intersect
Reset blend states
Reenable depth testing
Set StencilRef to 2 //render only pixels where stencil value == 2
Draw both cylinders
您可能需要在最后一次渲染之前将比较函数更改为 GreaterEqual。如果像素重叠,则可能有大于 2 的值。