関数「D3DXIntersectTri」で交差点の距離を見つけました。さて、距離値を使用して、そのポイント値を見つけるにはどうすればよいですか?
IDE: デルファイ - JEDI
言語: パスカル
ダイレクト X 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 より大きい値が存在する可能性があります。