Jump to content
  • Advertisement
Sign in to follow this  

[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.

If you intended to correct an error in the post then please contact us.

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: img2 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? img3 The yellow spheres are the unprojected point coordinates If I transform my view to look from top onto the model it works: img6 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)

' 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)


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 this post

Link to post
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 = mtxWorldMatrix

' 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 = mtxWorldMatrix

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!