Sign in to follow this  
lallebob

[MDX] Unproject Problem

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)
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 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
Me._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 = mtxWorldMatrix
Me._mesh.DrawSubset(0)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this