Agwan
06-11-2006, 08:57 PM
FindMousePosition is only used in windoed mode, fullscreen works perfectly but windowed mode does not work correctly?
''' <summary>
''' Convert mouse position from fullscreen to windowed
''' </summary>
''' <param name="XC"></param>
''' <param name="YC"></param>
''' <param name="Target"></param>
''' <remarks></remarks>
Private Sub FindMousePosition(ByRef XC As Single, ByRef YC As Single, ByRef Target As Form, ByVal DisplayBuffer As Vector2)
Dim Temp As Point
'''''''''''''''''''''''''''''''''''''''''''''
Temp = Target.PointToClient(Cursor.Position)
Dim Size As Vector2
Dim Screen As Vector2
Screen.X = My.Computer.Screen.Bounds.Width
Screen.Y = My.Computer.Screen.Bounds.Height
If Not (Target.FormBorderStyle = FormBorderStyle.None) Then
Size.X = (Target.Width - 8)
Size.Y = (Target.Width - 34)
Else
Size.X = Target.Width
Size.Y = Target.Width
End If
Dim Const1 As Vector2
Const1.X = Screen.X / Size.X
Const1.Y = Screen.Y / Size.Y
Temp.X = Temp.X * Const1.X
Temp.Y = Temp.Y * Const1.Y
XC = Temp.X
YC = Temp.Y
End Sub
''' <summary>
''' Ray Collistion test
''' </summary>
''' <param name="mesh1"></param>
''' <param name="meshMatrix"></param>
''' <param name="x"></param>
''' <param name="y"></param>
''' <returns></returns>
''' <remarks></remarks>
Function DoesMouseHitMesh(ByVal mesh1 As Mesh, ByVal meshMatrix As Matrix, ByVal x As Single, ByVal y As Single) As Boolean
Dim viewport As Viewport
Dim world As Matrix
Dim proj As Matrix
Dim view As Matrix
Dim vIn As Vector3, vNear As Vector3, vFar As Vector3, vDir As Vector3
Dim ClosestHit As IntersectInformation
viewport = Device1.Viewport
world = meshMatrix
'Get the Current Projection Matrix
proj = Device1.Transform.Projection
'Get the Current View Matrix
view = Device1.Transform.View
vIn.X = x
vIn.Y = y
'Compute point on Near Clip plane at cursor
vIn.Z = 0
vNear = Microsoft.DirectX.Vector3.Unproject(vIn, viewport, proj, view, world)
'Compute point on far clip plane at cursor
vIn.Z = 1
vFar = Microsoft.DirectX.Vector3.Unproject(vIn, viewport, proj, view, world)
'Compute direction vector
vDir = Microsoft.DirectX.Vector3.Subtract(vFar, vNear)
If mesh1.Intersect(vNear, vDir, ClosestHit) = True Then 'objMesh is the Mesh itself.
Return True
End If
End Function
Any ideas
''' <summary>
''' Convert mouse position from fullscreen to windowed
''' </summary>
''' <param name="XC"></param>
''' <param name="YC"></param>
''' <param name="Target"></param>
''' <remarks></remarks>
Private Sub FindMousePosition(ByRef XC As Single, ByRef YC As Single, ByRef Target As Form, ByVal DisplayBuffer As Vector2)
Dim Temp As Point
'''''''''''''''''''''''''''''''''''''''''''''
Temp = Target.PointToClient(Cursor.Position)
Dim Size As Vector2
Dim Screen As Vector2
Screen.X = My.Computer.Screen.Bounds.Width
Screen.Y = My.Computer.Screen.Bounds.Height
If Not (Target.FormBorderStyle = FormBorderStyle.None) Then
Size.X = (Target.Width - 8)
Size.Y = (Target.Width - 34)
Else
Size.X = Target.Width
Size.Y = Target.Width
End If
Dim Const1 As Vector2
Const1.X = Screen.X / Size.X
Const1.Y = Screen.Y / Size.Y
Temp.X = Temp.X * Const1.X
Temp.Y = Temp.Y * Const1.Y
XC = Temp.X
YC = Temp.Y
End Sub
''' <summary>
''' Ray Collistion test
''' </summary>
''' <param name="mesh1"></param>
''' <param name="meshMatrix"></param>
''' <param name="x"></param>
''' <param name="y"></param>
''' <returns></returns>
''' <remarks></remarks>
Function DoesMouseHitMesh(ByVal mesh1 As Mesh, ByVal meshMatrix As Matrix, ByVal x As Single, ByVal y As Single) As Boolean
Dim viewport As Viewport
Dim world As Matrix
Dim proj As Matrix
Dim view As Matrix
Dim vIn As Vector3, vNear As Vector3, vFar As Vector3, vDir As Vector3
Dim ClosestHit As IntersectInformation
viewport = Device1.Viewport
world = meshMatrix
'Get the Current Projection Matrix
proj = Device1.Transform.Projection
'Get the Current View Matrix
view = Device1.Transform.View
vIn.X = x
vIn.Y = y
'Compute point on Near Clip plane at cursor
vIn.Z = 0
vNear = Microsoft.DirectX.Vector3.Unproject(vIn, viewport, proj, view, world)
'Compute point on far clip plane at cursor
vIn.Z = 1
vFar = Microsoft.DirectX.Vector3.Unproject(vIn, viewport, proj, view, world)
'Compute direction vector
vDir = Microsoft.DirectX.Vector3.Subtract(vFar, vNear)
If mesh1.Intersect(vNear, vDir, ClosestHit) = True Then 'objMesh is the Mesh itself.
Return True
End If
End Function
Any ideas