Here is my standard sliding collision routing converted to VB.Net & DarkGDK.Net:
Module SlidingCollisionDemo
Public StartX As Single
Public StartY As Single
Public StartZ As Single
Public MovePerSec As Single
Public UseReticle As Boolean
Public EyeHeight As Integer
Public MouseSens As Integer
Public Airborn As Boolean
Public Gravity As Single
Public ColliderObjNum As Integer
Sub Main()
If Not InitializeDGDK("") Then End
oDBDisplay.SetWindowOff()
oDBCore.SyncOn()
oDBCore.SyncRate(0)
oDBCamera.AutoCamOff()
oDBInput.HideMouse()
oDBCamera.SetCameraRange(0.1, 5000)
StartX = 120
StartY = 64
StartZ = 120
MovePerSec = 240
UseReticle = True
EyeHeight = 64
MouseSens = 3
Gravity = 512
ColliderObjNum = 2
oDB3D.LoadObject("colltest.x", 1)
oDB3D.SetObjectCollisionToPolygons(1)
oDB3D.MakeObjectSphereB(ColliderObjNum, EyeHeight / 2)
oDB3D.SetObjectCollisionOn(ColliderObjNum)
oDB3D.HideObject(ColliderObjNum)
oDBCamera.PositionCameraC(0, StartX, StartY, StartZ)
oDB3D.PositionObject(ColliderObjNum, StartX, StartY, StartZ)
oDBLight.SetAmbientLight(100)
oDBLight.FogColor(oDB2D.RGBC(128, 128, 128))
oDBLight.FogDistance(1000)
oDBLight.FogOn()
oDBImage.SetImageColorKey(255, 0, 255)
oDBImage.LoadImage("Compass.bmp", 10)
oDBSprite.Sprite(10, 25, 100, 10)
oDBSprite.OffsetSprite(10, 25.5, 25.5)
Do While oDBP.LoopGDK()
If Not Airborn Then CheckCollision()
If Airborn Then Fall()
oDBCore.SetCursor(0, 0)
oDBCore.Print("FPS: " + oDBDisplay.ScreenFPS().ToString + " Polys: " + oDB3D.Statistic(1).ToString)
oDBCore.Print("X: " + oDBCamera.CameraPositionXB(0).ToString + " Y: " + oDBCamera.CameraPositionYB(0).ToString + " Z: " + oDBCamera.CameraPositionZB(0).ToString)
oDBCore.Print("Airborn: " + Airborn.ToString)
SetCompass(10)
oDBCore.Sync()
Loop
End
End Sub
Private Sub Fall()
Dim ox As Single
Dim oy As Single
Dim oz As Single
Dim Delta As Single
Dim ny As Single
ox = oDB3D.ObjectPositionX(ColliderObjNum)
oy = oDB3D.ObjectPositionY(ColliderObjNum)
oz = oDB3D.ObjectPositionZ(ColliderObjNum)
Delta = Gravity / oDBDisplay.ScreenFPS()
ny = EyeHeight + (oy - oDB3D.IntersectObject(1, ox, oy, oz, ox, -1000, oz))
If (oy - ny) <= Delta Then
oDB3D.PositionObject(ColliderObjNum, ox, ny, oz)
oDBCamera.PositionCameraC(0, ox, ny, oz)
Airborn = False
Else
oDB3D.PositionObject(ColliderObjNum, ox, oy - Delta, oz)
oDBCamera.PositionCameraC(0, ox, oy - Delta, oz)
End If
If UseReticle = 1 Then
oDB2D.Circle(oDBDisplay.ScreenWidth() / 2, oDBDisplay.ScreenHeight() / 2, 8)
End If
End Sub
Private Sub SetCompass(ByVal SpriteNum As Integer)
oDBSprite.RotateSprite(10, oDBCore.WrapValue(oDBCamera.CameraAngleYB(0)))
End Sub
Private Sub CheckCollision()
Dim moving As Boolean
Dim ox As Single
Dim oy As Single
Dim oz As Single
Dim delta As Single
Dim cx As Single
Dim cy As Single
Dim cz As Single
Dim k As String
Dim nx As Single
Dim ny As Single
Dim nz As Single
moving = False
ox = oDB3D.ObjectPositionX(ColliderObjNum)
oy = oDB3D.ObjectPositionY(ColliderObjNum)
oz = oDB3D.ObjectPositionZ(ColliderObjNum)
delta = MovePerSec / oDBDisplay.ScreenFPS()
If delta > EyeHeight Then
delta = EyeHeight
End If
oDB3D.RotateObject(ColliderObjNum, oDB3D.ObjectAngleX(ColliderObjNum) + (oDBInput.MouseMoveY() / MouseSens), oDB3D.ObjectAngleY(ColliderObjNum) + (oDBInput.MouseMoveX() / MouseSens), 0)
If oDB3D.ObjectAngleX(ColliderObjNum) > 90 Then oDB3D.XRotateObject(ColliderObjNum, 90)
If oDB3D.ObjectAngleX(ColliderObjNum) < -90 Then oDB3D.XRotateObject(ColliderObjNum, -90)
cx = oDB3D.ObjectAngleX(ColliderObjNum)
cy = oDB3D.ObjectAngleY(ColliderObjNum)
cz = oDB3D.ObjectAngleZ(ColliderObjNum)
oDBCamera.RotateCamera(cx, cy, cz)
oDB3D.RotateObject(ColliderObjNum, cx, cy, cz)
If UseReticle = 1 Then
oDB2D.Circle(oDBDisplay.ScreenWidth() / 2, oDBDisplay.ScreenHeight() / 2, 8)
End If
k = (oDBCore.InKey()).ToUpper
If oDBInput.UpKey() = 1 Or k = "W" Then
oDB3D.XRotateObject(ColliderObjNum, 0)
oDB3D.MoveObject(ColliderObjNum, delta)
oDB3D.XRotateObject(ColliderObjNum, cx)
End If
If oDBInput.DownKey() = 1 Or k = "S" Then
oDB3D.XRotateObject(ColliderObjNum, 0)
oDB3D.MoveObject(ColliderObjNum, 0 - Delta)
oDB3D.XRotateObject(ColliderObjNum, cx)
End If
If oDBInput.LeftKey() = 1 Or k = "A" Then
oDB3D.XRotateObject(ColliderObjNum, 0)
oDB3D.YRotateObject(ColliderObjNum, cy - 90)
oDB3D.MoveObject(ColliderObjNum, Delta)
oDB3D.YRotateObject(ColliderObjNum, cy)
oDB3D.XRotateObject(ColliderObjNum, cx)
End If
If oDBInput.RightKey() = 1 Or k = "D" Then
oDB3D.XRotateObject(ColliderObjNum, 0)
oDB3D.YRotateObject(ColliderObjNum, cy - 90)
oDB3D.MoveObject(ColliderObjNum, 0 - Delta)
oDB3D.YRotateObject(ColliderObjNum, cy)
oDB3D.XRotateObject(ColliderObjNum, cx)
End If
nx = oDB3D.ObjectPositionX(ColliderObjNum)
nz = oDB3D.ObjectPositionZ(ColliderObjNum)
ny = EyeHeight + (oy - oDB3D.IntersectObject(1, nx, oy, nz, nx, -1000, nz))
If oDB3D.ObjectCollision(ColliderObjNum, 0) <> 0 Then
oDB3D.PositionObject(ColliderObjNum, ox, ny, nz)
If oDB3D.ObjectCollision(ColliderObjNum, 0) <> 0 Then
oDB3D.PositionObject(ColliderObjNum, nx, ny, oz)
If oDB3D.ObjectCollision(ColliderObjNum, 0) <> 0 Then
oDB3D.PositionObject(ColliderObjNum, nx, oy, nz)
If oDB3D.ObjectCollision(ColliderObjNum, 0) <> 0 Then
ny = oy
nx = ox
nz = oz
Else
ny = oy
End If
Else
nz = oz
End If
Else
nx = ox
End If
End If
If (oy - ny) > EyeHeight Then
Airborn = 1
ny = oy
CheckFall()
End If
oDBCamera.PositionCameraC(0, nx, ny, nz)
oDB3D.PositionObject(ColliderObjNum, nx, ny, nz)
End Sub
Private Sub CheckFall()
Dim ox As Single
Dim oy As Single
Dim oz As Single
Dim ny As Single
ox = oDB3D.ObjectPositionX(ColliderObjNum)
oy = oDB3D.ObjectPositionY(ColliderObjNum)
oz = oDB3D.ObjectPositionZ(ColliderObjNum)
ny = EyeHeight + (oy - oDB3D.IntersectObject(1, ox, oy, oz, ox, -1000, oz))
oDB3D.PositionObject(ColliderObjNum, ox, ny, oz)
If oDB3D.ObjectCollision(ColliderObjNum, 0) <> 0 Then
Airborn = 0
End If
End Sub
End Module
Intel Pentium 4, 3.4GHz, 1280MB RAM, NVidia Quadro FX3000/256MB, 240GB HD, XP Pro