我用函数'D3DXIntersectTri‘找到了交点的距离。现在,使用距离值,我如何找到该点值?
IDE: Delphi - JEDI
语言:帕斯卡语
DirectX 9
编辑:实际上我有两个圆柱体,只想在三维中渲染相交的部分。请参见图像:
发布于 2013-04-03 23:05:38
如MSDN article中所述,您可以使用重心坐标计算点:
p = p1 + pU * (p2 - p1) + pV(p3 - p1)
发布于 2013-04-08 16:57:35
模板缓冲区的任务是渲染到屏幕的某些部分。除非你想从交叉点创建一个新的顶点缓冲区(这可以通过裁剪部分来创建,这并不容易),否则使用模具缓冲区会更有效。
模板缓冲区是保存整数值的缓冲区。您必须使用深度缓冲区创建它,并指定正确的格式(例如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
在最后一次渲染过程之前,可能需要将compare函数更改为GreaterEqual。如果像素重叠,则可能存在大于两个的值。
https://stackoverflow.com/questions/15783579
复制相似问题