[Resolved, source code posted]Sliding collision (camera) against a BSP tree
hi "CadeF" i was working with 3D collision detection in C# and i got some result not perfect but it is ok and it needs some corrections i didn't have time to correct it , what i did in my collision detection algorithm is that i gave my function the mesh i want to detect collision against it and i calculated the nearest collision point and make my responce to it "which i think is wrong because i am ignoring the other collision points" so that's what i want to correct , if u want we can exchange our 3d collison detection algorithms and work together to obtain a good result , what u say ????????
And, code for pushing a sphere, converted to use a node-based bsp
This code works perfectly, it is all I am using for sliding collision detection. :)
[Edited by - CadeF on February 11, 2006 6:21:02 AM]
Public Function TestPointWorldLocality(ByVal pt As Vector3, Optional ByVal Prev As Integer = -1) As Boolean Select Case PointPlaneLocality(pt, Center, Normal, 0) Case Enum_PointPlaneLocality.Front If Front > -1 Then Return World.BSP.Node(Front).TestPointWorldLocality(pt, Front) Else Return True End If Case Enum_PointPlaneLocality.Back If Back > -1 Then Return World.BSP.Node(Back).TestPointWorldLocality(pt, Back) Else Return False End If Case Enum_PointPlaneLocality.Split Return False End Select Return False End Function Public Sub PushSphere(ByRef Pos As Vector3, ByVal Radius As Single) Dim d As Single = Abs(PointPlaneLocalityDot(Pos, Center, Normal)) If d <= Radius Then If World.BSP.Node(0).TestPointWorldLocality(Pos + Vector3.Scale(Normal, Radius)) <> World.BSP.Node(0).TestPointWorldLocality(Pos - Vector3.Scale(Normal, Radius - d)) Then Pos.Subtract(Vector3.Scale(Normal, Radius - d)) End If End If If Front > -1 Then World.BSP.Node(Front).PushSphere(Pos, Radius) If Back > -1 Then World.BSP.Node(Back).PushSphere(Pos, Radius) End Sub
This code works perfectly, it is all I am using for sliding collision detection. :)
[Edited by - CadeF on February 11, 2006 6:21:02 AM]
Discovered the odd bug in that code. This code fixes that bug, seems to work flawlessly now.
Not doing it all wrong now, am I? :)
Class clsFace Public Function IsAbove(ByVal Pos As Vector3) As Boolean Dim I As Integer = 0 Dim J As Integer = Points.Length - 1 For I = 0 To Points.Length - 1 Dim EdgeNorm As Vector3 = Vector3.Cross(Normal, Points(I) - Points(J)) If Vector3.Dot(EdgeNorm, Pos) - Vector3.Dot(EdgeNorm, Points(I)) < 0 Then Return False End If J = I Next Return True End FunctionClass clsBSPNode Public Sub PushSphere(ByRef Pos As Vector3, ByVal Radius As Single) Dim d As Single = Abs(PointPlaneLocalityDot(Pos, Center, Normal)) If d < Radius Then If World.Face(Face).IsAbove(Pos) Then Pos.Subtract(Vector3.Scale(Vector3.Normalize(Normal), Radius - d)) End If End If If Front > -1 Then World.BSP.Node(Front).PushSphere(Pos, Radius) If Back > -1 Then World.BSP.Node(Back).PushSphere(Pos, Radius) End Sub
Not doing it all wrong now, am I? :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement