Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

D3DXIntersect' s problems

Started by Black_Moon Sep 21, 2005 at 9:53 AM 1 replies 600+ views
Original Post
Black_Moon
Black_Moon
i'm finding what mesh was picked: D3DVIEWPORT8 vPort; pd3dd->GetViewport(&vPort); D3DXMATRIX m, mProj, mView, mWorld; pd3dd->GetTransform(D3DTS_PROJECTION, &mProj); pd3dd->GetTransform(D3DTS_VIEW, &mView); pd3dd->GetTransform(D3DTS_WORLD, &mWorld); D3DXVECTOR3 vScr, vPickRayDir, vPickRayOrig; vScr.x = (((2.0f*pt.x)/vPort.Width) - 1)/mProj._11; vScr.y = -(((2.0f * pt.y)/vPort.Height) - 1)/mProj._22; vScr.z = 1.0f; // Get the inverse view matrix D3DXMatrixInverse(&m, 0, &mView); // Transform the screen space pick ray into 3D space vPickRayDir.x = vScr.x*m._11 + vScr.y*m._21 + vScr.z*m._31; vPickRayDir.y = vScr.x*m._12 + vScr.y*m._22 + vScr.z*m._32; vPickRayDir.z = vScr.x*m._13 + vScr.y*m._23 + vScr.z*m._33; D3DXVec3Normalize(&vPickRayDir, &vPickRayDir); vPickRayOrig.x = m._41; vPickRayOrig.y = m._42; vPickRayOrig.z = m._43; // calc origin as intersection with near frustum vPickRayOrig += vPickRayDir*NEAR_Z; D3DXVECTOR3 vOrig, vDir; D3DXMatrixInverse(&m, 0, &mWorld); D3DXVec3TransformCoord(&vOrig, &vPickRayOrig, &m); D3DXVec3TransformNormal(&vDir, &vPickRayDir, &m); // test for intersection BOOL bHit; DWORD dwIndex; float u, v; float fDist; D3DXIntersect(m_pConeMesh->lpmesh, &vOrig, &vDir, &bHit, &dwIndex, &u, &v, &fDist, 0, 0); and i always have ray coordinates in [-1.0f..1.0f, -1.0f..1.0f], but real world mesh-coordinates are near (-315.0, -800.0). tryed to init vectors directly vOrig = D3DXVECTOR3(-315.0f, -800.0f, NEAR_Z); vDir = D3DXVECTOR3(-315.0f, -800.0f, FAR_Z); and, never the less bHit=0. Projection - OrthoLH. What's the problem?Thanks.
jollyjeffers
jollyjeffers
That's a whole lot of mathemagical goodness you have there [smile]

Have you considered using D3DXVec3Unproject()?

Once you have your D3DVIEWPORT8 structure, you can construct two input vectors - [mouse_x,mouse_y,viewport.minZ] and [mouse_x,mouse_y,viewport.maxZ], transform them using the aforementioned function.

You should then be able to construct a ray from the near-plane to the far-plane, which should work for what you want. The code should become a lot simpler and provided your input params are correct then you can eliminate your code as being a source of problems...

I've used the opposite (D3DXVec3Project()) a few times and it works a treat [smile]

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
Black_Moon
Black_Moon
I've copied with D3DXIntersect(). The problem was that 2 Vectors
v1(a1, b1, c1), v2(a2, b2, c2) && a1=a2,b1=b2,c1=c2. But length(v1) != length(v2). so my vector-ray not always intersects mesh polygons..

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.