Ray Picking
Ray Picking
Ray Picking
Ray Picking
Ray Picking
Ray Picking Ray Picking Ray Picking Ray Picking Ray Picking Ray Picking Ray Picking Ray Picking
Ray Picking Ray Picking
Ray Picking
Go Back  Xtreme Visual Basic Talk > > > > Ray Picking


Reply
 
Thread Tools Display Modes
  #1  
Old 06-11-2006, 09:57 PM
Agwan's Avatar
Agwan Agwan is offline
Freshman
 
Join Date: Nov 2005
Location: Australia
Posts: 45
Angry Ray Picking


FindMousePosition is only used in windoed mode, fullscreen works perfectly but windowed mode does not work correctly?

Code:
            ''' <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
__________________
Agwan - EXtremeSolutions
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Ray Picking
Ray Picking
Ray Picking Ray Picking
Ray Picking
Ray Picking
Ray Picking Ray Picking Ray Picking Ray Picking Ray Picking Ray Picking Ray Picking
Ray Picking
Ray Picking
 
Ray Picking
Ray Picking
 
-->