[MDX] Unproject Problem

This topic is 4478 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi everyone! I have a problem with the unproject function from managed directx. I want to make screenshots of my 3D scene and put them together in one large image. I do the following. I compute the bounding box (blue) of my mesh and Project the vMin and vMax Vectors to Screenspace. Than I calculate a Rectangle (Magenta) around these coordinates and devide it into smaller Rectangles (yellow/orange/red) of the size of my Screen. The Result looks like this: Now I want to Unproject the middle points of the rectangles to 3D space, navigate to each point and take a screenshot. The screen X coordinate gets unprojected correctly. But the screen Y coordinate is wrong. I can't find any reason. What am I doing wrong? The yellow spheres are the unprojected point coordinates If I transform my view to look from top onto the model it works: Here are my matrices:
_mtxDefaultWorldMatrix = Matrix.Translation(New Vector3(m_fMoveX, 0.0F, m_fMoveY))
_mtxViewMatrix = Matrix.LookAtLH(New Vector3(Me.tbPitch.Value, 200, Me.tbPitch.Value), New Vector3(0.0F, 0.0F, 0.0F), New Vector3(0.0F, 1.0F, 0.0F))
' Orthogonal Projection needed so the Screenshots fit together.
_mtxProjectionMatrix = Matrix.OrthoLH(-m_iZoomX, -m_iZoomY, 0.0F, 2000.0F)


Project the Bounding box coords:
' Compute Bounding Box
Geometry.ComputeBoundingBox(mesh.LockVertexBuffer(LockFlags.None), mesh.NumberVertices, mesh.VertexFormat, vMin, vMax)
mesh.UnlockVertexBuffer()

' Project to Screen space
vMin.Project(Me.m_GfxDevice.Viewport, Me._mtxProjectionMatrix, Me._mtxViewMatrix, Me._mtxDefaultWorldMatrix)
vMax.Project(Me.m_GfxDevice.Viewport, Me._mtxProjectionMatrix, Me._mtxViewMatrix, Me._mtxDefaultWorldMatrix)


Unproject the screenshot coords:
' project the computed Screenshot Coords
v = Array.CreateInstance(GetType(Vector3), ptScreenshotCoords.Length)
For iIdx = 0 To ptScreenshotCoords.Length - 1
v(iIdx) = New Vector3(ptScreenshotCoords(iIdx).X, ptScreenshotCoords(iIdx).Y, 0.0F)
v(iIdx).Unproject(Me.m_GfxDevice.Viewport, Me._mtxProjectionMatrix, Me._mtxViewMatrix, Me._mtxDefaultWorldMatrix)

Next


Maybe there is even a better way to accomplish all of this. I'm pretty new to this stuff. Any suggestions are welcome. Thanks to all of you in advance!

Share on other sites
I solved the problem. When rendering the unprojected screenshot coords i put 0.0F for the Y coord. But I had to put the real Y coord. Stupid me! [totally]

mtxWorldMatrix = Matrix.Translation(New Vector3(m_fMoveX + _aryScreenshotVecs(ssv).X, 0.0F, m_fMoveY + _aryScreenshotVecs(ssv).Z))Me.m_GfxDevice.Transform.World = mtxWorldMatrixMe._mesh.DrawSubset(0)' Should be -->mtxWorldMatrix = Matrix.Translation(New Vector3(m_fMoveX + _aryScreenshotVecs(ssv).X, _aryScreenshotVecs(ssv).Y, m_fMoveY + _aryScreenshotVecs(ssv).Z))Me.m_GfxDevice.Transform.World = mtxWorldMatrixMe._mesh.DrawSubset(0)

• 32
• 12
• 10
• 9
• 9
• Forum Statistics

• Total Topics
631352
• Total Posts
2999483
×