0

I have found intersection point's distance with function 'D3DXIntersectTri'. Now, using distance value, how can i find that points value?

IDE: Delphi - JEDI

Language: Pascal

DirectX 9

EDIT: Actually i have 2 cylinder and want to render only intersected part in 3-dimention. see Image: enter image description here

Ganpat
  • 768
  • 3
  • 15
  • 30
  • 1
    Possible duplicate of: http://stackoverflow.com/questions/10294286/get-world-coordinates-from-d3dxintersecttri – paiden Apr 03 '13 at 10:28

2 Answers2

1

As explained in the MSDN article, you can calculate the point with the barycentric coordinates:

p = p1 + pU * (p2 - p1) + pV(p3 - p1)
Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
  • i am getting same value of p and p1. – Ganpat Apr 05 '13 at 11:33
  • What parameters do you provide? The function is for ray-triangle intersection. Your updated question suggests the usage of a stencil buffer, because the cylinders are not volumes but surfaces. Therefore, their intersection are circular paths (kind of). – Nico Schertler Apr 07 '13 at 09:20
  • D3DXIntersectTri(PtHr0, PtHrH1, PtHr2, ptOrg, ptFnlDir, sngU, sngV, sngDist). My first three parameter is vertex of Horizontal cylinder. and Origin and Direction parameter is vertex of Vertical cylinder. – Ganpat Apr 08 '13 at 06:48
  • The ray and triangle probably do not intersect. However, as I already mentioned, finding an intersection of a triangle and a ray is probably not the best choice. I added another answer for the stencil buffer way. – Nico Schertler Apr 08 '13 at 08:58
0

Rendering to certain parts of the screen is the task of the stencil buffer. Unless you want to create a new vertex buffer from the intersection (which could be created by clipping parts away, which is not that easy), using the stencil buffer is more efficient.

The stencil buffer is a buffer that holds integer values. You have to create it with the depth buffer, specifying the correct format (e.g. D24S8). You can then specify when pixels are discarded. Here is the idea:

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

You might need to change the compare function to GreaterEqual before the last render pass. If pixels overlap, there can be values greater than two.

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
  • Thanks a lot Nico Schertler. My question is only for finding intersected point, so i will ask another question for rendering intersection part. – Ganpat Apr 09 '13 at 05:48