Sign in to follow this  
LotusExigeS1

[SlimDX] Ray.Intersects help

Recommended Posts

LotusExigeS1    134
[size="3"][color="#2a2a2a"]Can someone please help with the below. I only get a positive 'hit' when I am in the bounding box. Thanks for any help.[/color][/size]

[color="#2a2a2a"][size="2"][code]Public Function RayBBIntersects(ByVal bb As BoundingBox, ByVal xPos As Single, ByVal yPos As Single) As Boolean
Dim near As New Vector3(xPos, yPos, 0.0F)
Dim far As New Vector3(xPos, yPos, 1.0F)
Dim n As Vector3 = Vector3.Unproject(near, 0, 0, cClientArea.Width, cClientArea.Height, -1000, 1000, cViewMatrix * cProjectionMatrix)
Dim f As Vector3 = Vector3.Unproject(far, 0, 0, cClientArea.Width, cClientArea.Height, -1000, 1000, cViewMatrix * cProjectionMatrix)

Dim direction As Vector3 = f - n
direction.Normalize()

Dim r As New Ray(n, direction)
Dim distance As Single = 0
Return Ray.Intersects(r, bb, distance)
End Function[/code]
[/size][/color]

[color="#2a2a2a"][size="2"]Thanks guys ![/size][/color]

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