[.net] unproject problem

Started by
-1 comments, last by afsajghfd 15 years, 8 months ago
Hi all, I have a problem with Vector3.Unproject, but i would like to know what's the best way of calculate space coords if I'm using multiple views. When i was using just one view, to calculate space coords was very simple.


v3Position.Unproject(device.Viewport, device.Transform.Projection, device.Transform.View, Matrix.Identity)

But now I have two views (of different size) using

device = New Device(Manager.Adapters.Default.Adapter, DeviceType.Hardware, _
                 handle, createFlags, parametros)
dev2 = New SwapChain(device, parametros)

surface0 = device.GetBackBuffer(0, 0, BackBufferType.Mono)    
surface1 = dev2.GetBackBuffer(0, BackBufferType.Mono)   

To render I never calculate the device.viewport for each picturebox, but it draws well The problem its that I get wrong coords and I think this it's cause I need to store somewhere the parameters of unproject for the two views.

 Public Structure dataP
        Dim viewPort As Viewport
        Dim projection As Matrix
        Dim view As Matrix
 End Structure

Dim XY_Plane, ZX_Plane as dataP

In render


 Select Case tipoVista
            Case Plano.XY
                XY_Plane.view = Matrix.LookAtRH(eye, dest_eye, vector_up)
                Device.Transform.View = XY_Plane.view

                XY_Plane.projection = Matrix.OrthoRH(PictureBox.Width / zoom, PictureBox.Height / zoom, 1, 300)
                Device.Transform.Projection = XY_Plane.projection

            Case Plano.ZX
                ZX_Plane.view = Matrix.LookAtRH(eye, dest_eye, vector_up)
                Device.Transform.View = ZX_Plane.view

                ZX_Plane.projection = Matrix.OrthoRH(PictureBox.Width / zoom, PictureBox.Height / zoom, 1, 300)
                Device.Transform.Projection = ZX_Plane.projection

        End Select


then in the function to getCoords()

      Dim v3Position As Vector3
      Select Case tipoVista
            Case Plano.XY
                v3Position = New Vector3(cX, cY, 0)
                v3Position.Unproject(XY_Plane.viewPort, XY_Plane.projection, XY_Plane.view, Matrix.Identity)
                v3Position.X = Math.Round(CDec(v3Position.X), 2) 
                v3Position.Y = Math.Round(CDec(v3Position.Y), 2)

            Case Plano.ZX
                v3Position = New Vector3(cX, cY, 0)
                v3Position.Unproject(ZX_Plane.viewPort, ZX_Plane.projection, ZX_Plane.view, Matrix.Identity)
                v3Position.X = Math.Round(CDec(v3Position.X), 2)
                v3Position.Y = Math.Round(CDec(v3Position.Z), 2)

        End Select
        Return v3Position

(I set the viewport for each picturebox in the begginnig of the program) but still getting wrong coords :( any suggestions? [dead] thanks in advance

This topic is closed to new replies.

Advertisement