I am trying to write a simple sphere polygon system while i await the ODE plugin (Thanks APEXnow). I am learning the gdk and i am loving it, the only issue im stuck at now is-
1.sphere to sphere collision return sliding data, sphere to polygon i get nothing
2.if i use the intersect function (oldpos,newpos) it returns the distance along that ray (no sliding info) ??? How do i determine which triangle is being hit??? i cant find anything in the help files or online?
3.i got the collision Objectx.collision() to return true of false exactly when the spheres are hitting the mesh of the .x file i loaded but with no sliding data and i dont know which triangle is hitting using this method either.
Here is the code from the vb.net game level example "modified" for these basic tests
Dim NewTestBox(2) As DarkGDK.Basic3D.Sphere
Public Sub GameLoop()
Dim fCameraAngleX As Single = 0.0F
Dim fCameraAngleY As Single = 0.0F
Dim universe As DarkGDK.Basic3D.Object3D
Dim skybox As DarkGDK.Basic3D.Object3D
Dim CollTrue As Boolean, Tstr As String, Collsin As Single, CollRadpx As Single, collRadpy As Single, collradpz As Single
'Dim Cmod As New CollModule
Dim BspC As New DarkGDK.World.BSPCollision
'BspC.SetCameraCollision(Camera.DefaultCamera, 40, True)
DarkGDK.Text.ShowText(0, 0, "Please wait... Loading Game Level")
DarkGDK.Core.Sync()
DarkGDK.Core.Sync()
DarkGDK.IO.File.SetCurrentDirectory("C:\Program Files\dx8sdk\samples\Multimedia\VBSamples\Media")
universe = New DarkGDK.Basic3D.Object3D("lev1.x")
universe.AffectedByAnyLights() = False
universe.Collidable = True
universe.SetCollisionToPolygons()
'skybox = New DarkGDK.Basic3D.Object3D("skybox2.x")
'skybox.AffectedByAnyLights() = False
''skybox.Scale(5000, 5000, 5000)
'skybox.SetTexture(Basic3D.TextureWrapMode.Clamp, 2)
DarkGDK.Camera.DefaultCamera.PositionCurrent(434, 42, -517)
'Tests for collsion detection
MakeTestbox(500, 0, 0, 10, 15, 10, 0)
MakeTestbox(500, 50, 0, 20, 15, 20, 1)
Dim Px As Single, Py As Single, Pz As Single
Dim p2x As Single, p2y As Single, p2z As Single
'BspC.SetObjectCollision(NewTestBox(0), 20, True)
'BspC.SetObjectCollision(NewTestBox(1), 30, True)
'BspC.SetObjectCollision(universe, 10, True)
'universe.ShowBounds()
NewTestBox(0).ShowBounds()
NewTestBox(1).ShowBounds()
'' Force the window to take focus
DarkGDK.Display.WindowToFront()
DarkGDK.IO.Mouse.Hide()
'
' Loop continuously until StopGDKLoop is called, or the ESC key is pressed.
'
While DarkGDK.Engine.LoopGDK()
'CollTrue = False
DarkGDK.Camera.DefaultCamera.ControlDefaultUsingArrowKeys(6, 5)
fCameraAngleX = DarkGDK.Core.WrapValue(fCameraAngleX + CSng(IO.Mouse.MoveY) * 0.4F)
fCameraAngleY = DarkGDK.Core.WrapValue(fCameraAngleY + CSng(IO.Mouse.MoveX) * 0.4F)
DarkGDK.Camera.DefaultCamera.CurrentAngleX = fCameraAngleX
DarkGDK.Camera.DefaultCamera.CurrentAngleY = fCameraAngleY
'/Release objects for movement
NewTestBox(0).Collidable = False
NewTestBox(1).Collidable = False
Px = NewTestBox(0).X
Py = NewTestBox(0).Y
Pz = NewTestBox(0).Z
'///////intersect test return point along ray???
Collsin = universe.Intersect(p2x, p2y, p2z, Px, Py, Pz)
'NewTestBox(0).Position(Px - (NewTestBox(0).CollisionX), Py - (NewTestBox(0).CollisionY), Pz - (NewTestBox(0).CollisionZ))
Px = NewTestBox(0).X
Py = NewTestBox(0).Y
Pz = NewTestBox(0).Z
If IO.Keyboard.Left = True Then
NewTestBox(0).MoveUp(1) '.Position(Px, Py + 1, Pz)
End If
If IO.Keyboard.Right = True Then
NewTestBox(0).MoveDown(1) '.Position(Px, Py - 1, Pz)
End If
If IO.Keyboard.Space = True Then
NewTestBox(0).MoveLeft(1) '..Position(Px, Py, Pz + 1)
End If
If IO.Keyboard.Return = True Then
NewTestBox(0).MoveRight(1) '.Position(Px, Py, Pz - 1)
End If
'/reset collidable state
NewTestBox(0).Collidable = True
NewTestBox(1).Collidable = True
universe.Collidable = True
CollTrue = NewTestBox(0).Collision(universe)
DarkGDK.Text.ShowText(10, 10, NewTestBox(0).CollisionX & " : " & NewTestBox(0).CollisionY & " : " & NewTestBox(0).CollisionZ)
Tstr = (p2x - Px) & ":" & (p2y - Py) & ":" & (p2z - Pz)
'///temporary
If Collsin <> 0 Then
CollRadpx = Px + ((p2x - Px) * Collsin)
collRadpy = Py + ((p2y - Py) * Collsin)
collradpz = Pz + ((p2z - Pz) * Collsin)
NewTestBox(0).Position(Px - (CollRadpx), Py - ((collRadpy)), Pz + (collradpz))
'Stop
End If
DarkGDK.Text.ShowText(10, 20, CollTrue & " <>" & Collsin & ":" & Tstr) 'NewTestBox(1).CollisionX & " : " & NewTestBox(1).CollisionY & " : " & NewTestBox(1).CollisionZ)
' Tell DarkGDK.NET to render our default camera display
p2x = Px
p2y = Py
p2z = Pz
DarkGDK.Core.Sync()
End While
End Sub
Private Sub MakeTestbox(ByVal Bposx As Double, ByVal BposY As Double, ByVal BposZ As Double, ByVal Bsizex As Double, ByVal Bsizey As Double, ByVal Bsizez As Double, ByVal BoxNum As Integer)
Dim myCol As Color
myCol = Color.IndianRed
NewTestBox(BoxNum) = New DarkGDK.Basic3D.Sphere(20, myCol) '.Box(Bsizex, Bsizey, Bsizez, myCol)
NewTestBox(BoxNum).Position(Bposx, BposY, BposZ)
NewTestBox(BoxNum).Collidable = True
NewTestBox(BoxNum).SetCollisionToSpheres()
NewTestBox(BoxNum).AutomaticCollision(10, True)
'NewTestBox(BoxNum).MakeCollisionBox(10, 0, 0, -10, 10, 10, False)
End Sub