actually, I'm slowly making it into a game-like entity.... I was fooling around on the weekend, got collision detection working on it... (took me forever... don't have gravity implemented yet... I'm starting to hate collision....) and added a gun... can shoot spheres now... I'll post the raw (NOT CLEAN) source for the project below... let ppl at least see what I've done... I've got dead-end detection too... either way... yah... here it is:
Dim CPU As New TVEngine
Dim Scene As New TVScene
Dim Column As New TVMesh
Dim Columns(20, 20) As New TVMesh
Dim DeadEnds(20, 20) As Boolean
Dim Sphere As New TVMesh
Dim Spheres(20, 20) As New TVMesh
Dim hwall As New TVMesh
Dim hwalls(20, 20) As New TVMesh
Dim vwall As New TVMesh
Dim vwalls(20, 20) As New TVMesh
Dim mfloor As New TVMesh
Dim IOsys As New TVInputEngine
Dim Mothernature As New TVAtmosphere
Dim CamOldPos As D3DVECTOR
Dim CamNewPos As D3DVECTOR
Dim Math As New TVMathLibrary
Dim Eye As New TVCamera
Dim TwoDee As New TVScreen2DImmediate
Dim blah As D3DVECTOR2
Dim Hands As New TVActor2
Dim HandsNextAnim As Integer
Dim totDeadEnds
Dim LastNonCollidedPosition As D3DVECTOR
Dim matrix As D3DMATRIX
Dim Guts As New TVInternalObjects
Dim Shooting As Boolean
Dim DoneShooting As Boolean
Dim ColRes As TV_COLLISIONRESULT
Dim colide As New TVCollisionResult
Private Sub Form_Load()
CPU.SetDebugMode True, True
CPU.SetDebugFile App.Path & "\Debug.txt"
'CPU.Init3DFullscreen 800, 600, 32, True, False, TV_DEPTHBUFFER_24BITS_8STENCILBITS, , Me.hWnd
CPU.Init3DFullscreen 1024, 768, 32, True, False, TV_DEPTHBUFFER_24BITS_8STENCILBITS, , Me.hWnd
'CPU.Init3DWindowedMode Me.hWnd
CPU.SetSearchDirectory "c:\tv3dsdk\media"
Dim xwalls(20, 20)
Dim ywalls(20, 20)
Scene.LoadTexture "c:\tv3dsdk\media\21.bmp", , , "Wall"
Scene.LoadTexture "c:\tv3dsdk\media\floor_3.bmp", , , "Floor"
Scene.LoadTexture "c:\tv3dsdk\media\front.bmp", , , "front"
Scene.LoadTexture "c:\tv3dsdk\media\back.bmp", , , "back"
Scene.LoadTexture "c:\tv3dsdk\media\right.bmp", , , "right"
Scene.LoadTexture "c:\tv3dsdk\media\left.bmp", , , "left"
Scene.LoadTexture "c:\tv3dsdk\media\top.bmp", , , "top"
Scene.LoadTexture "c:\tv3dsdk\media\bottom.bmp", , , "bottom"
Mothernature.SkyBox_Enable True
Mothernature.SkyBox_SetTexture GetTex("front"), GetTex("back"), GetTex("left"), GetTex("right"), GetTex("top"), GetTex("bottom")
Mothernature.SkyBox_SetDistance 3800
Me.Show
Me.SetFocus
CPU.Clear
Scene.DrawText "Loading", 0, 1
CPU.RenderToScreen
Scene.SetViewFrustum 65, 8000
generatemaze xwalls, ywalls, 20, 20
roomsize = 200
Set Sphere = Scene.CreateMeshBuilder
Sphere.CreateSphere GetTex("floor"), 5, 4, 10
Sphere.EnableSphereMapping True
Set Column = Scene.CreateMeshBuilder
Column.CreateCylinder 20, 51.1, 20
Column.SetTexture GetTex("wall")
Column.RotateX 3.14159
Column.RotateY 2
Column.SetTextureModEnable True
Column.SetTextureModTranslationScale 0, 0, 6, 1
Hands.Load "c:\tv3dsdk\media\v_shotgun.mdl"
Hands.SetAnimationID 0
Hands.PlayAnimation 10
Set mfloor = Scene.CreateMeshBuilder
mfloor.AddFloor GetTex("Floor"), 0, 0, 20 * roomsize, 20 * roomsize, , 40, 40
mfloor.Optimize
Set hwall = Scene.CreateMeshBuilder
hwall.AddWall3D GetTex("Wall"), -roomsize, 0, 0, 0, 50, 10, , , , -1.02, -4.2
hwall.AddFloor GetTex("Wall"), -roomsize, 10, 0, -10, 50
hwall.Optimize
Set vwall = Scene.CreateMeshBuilder
vwall.AddWall3D GetTex("Wall"), 0, 0, 0, -roomsize, 50, 10, , , , -1.02, -4.2
vwall.AddFloor GetTex("Wall"), 10, 0, -10, -roomsize, 50
vwall.Optimize
For x = 0 To 20
For y = 0 To 20
If xwalls(x, y) = True Then
Set hwalls(x, y) = hwall.DuplicateMesh
hwalls(x, y).SetPosition x * roomsize, 0, y * roomsize
End If
If ywalls(x, y) = True Then
Set vwalls(x, y) = vwall.DuplicateMesh
vwalls(x, y).SetPosition x * roomsize, 0, y * roomsize
End If
Set Columns(x, y) = Column.DuplicateMesh
Columns(x, y).SetPosition x * roomsize, 24.5, y * roomsize
If DeadEnds(x, y) Then
Set Spheres(x, y) = Sphere.DuplicateMesh
Spheres(x, y).SetPosition x * roomsize - roomsize / 2, 25, y * roomsize - roomsize / 2
End If
Next
CPU.Clear
Scene.DrawText "Loading " & (80 + x) & "%", 0, 0
CPU.RenderToScreen
DoEvents
Next
Column.SetPosition 20000, 20000, 20000
hwall.SetPosition 20000, 20000, 20000
vwall.SetPosition 20000, 20000, 20000
Dim cx As Single, cy As Single, fu As Single, mx As Long, my As Long, mb1 As Integer
Scene.SetCamera 50, 25, 50, 51, 50, 50
DoneShooting = True
Do
skyrot = skyrot + CPU.AccurateTimeElapsed / 50000
Mothernature.SkyBox_SetRotation 0, skyrot, 0
Eye.SetRotation 0, cy, 0
CamOldPos = Eye.GetPosition
If IOsys.IsKeyPressed(TV_KEY_W) Then Eye.MoveRelative CPU.AccurateTimeElapsed / 7, 0, 0
If IOsys.IsKeyPressed(TV_KEY_S) Then Eye.MoveRelative -CPU.AccurateTimeElapsed / 7, 0, 0
If IOsys.IsKeyPressed(TV_KEY_A) Then Eye.MoveRelative 0, 0, -CPU.AccurateTimeElapsed / 7
If IOsys.IsKeyPressed(TV_KEY_D) Then Eye.MoveRelative 0, 0, CPU.AccurateTimeElapsed / 7
If IOsys.IsKeyPressed(TV_KEY_LEFT) Then cy = cy - CPU.AccurateTimeElapsed / 400
If IOsys.IsKeyPressed(TV_KEY_RIGHT) Then cy = cy + CPU.AccurateTimeElapsed / 400
If IOsys.IsKeyPressed(TV_KEY_UP) Then Eye.MoveRelative CPU.AccurateTimeElapsed / 7, 0, 0
If IOsys.IsKeyPressed(TV_KEY_DOWN) Then Eye.MoveRelative -CPU.AccurateTimeElapsed / 7, 0, 0
If CamOldPos.x = Eye.GetPosition.x And CamOldPos.y = Eye.GetPosition.y And CamOldPos.z = Eye.GetPosition.z Then
HandsNextAnim = 0
Else
HandsNextAnim = 9
End If
IOsys.GetMouseState mx, my, mb1
If mb1 <> 0 Then
HandsNextAnim = 2
If Shooting = False And DoneShooting = True Then
DoneShooting = False
Shooting = True
Else
Shooting = False
End If
Else
Shooting = False
End If
If (Hands.GetKeyFrame >= Hands.GetAnimationLength(Hands.GetAnimation) - 4) Or (Hands.GetAnimation = 0) Or (Hands.GetAnimation = 9) Then
If Hands.GetAnimation <> HandsNextAnim Then Hands.SetAnimationID HandsNextAnim
Hands.PlayAnimation 10
If Shooting = False Then DoneShooting = True
End If
cx = cx + my / 200
cy = cy + mx / 100
Eye.SetRotation cx, cy, 0
CamNewPos = checkbounds(CamOldPos, Eye.GetPosition)
Eye.SetPosition CamNewPos.x, CamNewPos.y, CamNewPos.z
Hands.SetPosition CamNewPos.x, CamNewPos.y, CamNewPos.z
Hands.SetRotation 0, cy + (3.14159 / 2), cx
If Shooting Then
If Scene.AdvancedCollision(CamNewPos, Vector3(CamNewPos.x + Sin(cy) * 2000, CamNewPos.y + Sin(-cx) * 2000, CamNewPos.z + Cos(cy) * Cos(-cx) * 2000), ColRes, TV_COLLIDE_MESH, TV_TESTTYPE_ACCURATETESTING, True) Then
For x = 0 To 20
For y = 1 To 20
If Spheres(x, y).GetMeshIndex = ColRes.MeshID Then Spheres(x, y).Destroy
Next
Next
Scene.DrawText ColRes.MeshID, 0, 40
End If
End If
CPU.Clear
Scene.RenderAllMeshes False
Mothernature.Skybox_Render
Hands.Render
'TwoDee.DRAW_Line3D Hands.GetBonePosition(30, Vector3(0, 0, 0)).x, Hands.GetBonePosition(30, Vector3(0, 0, 0)).y, Hands.GetBonePosition(30, Vector3(0, 0, 0)).z, CamNewPos.x + Sin(cy) * 500, CamNewPos.y + Sin(-cx) * 500, CamNewPos.z + Cos(cy) * Cos(-cx) * 500, RGBA(1, 0, 0, 1)
TwoDee.DRAW_FilledCircle 1024 / 2, 768 / 2, 20, , RGBA(1, 0, 0, 0.2)
TwoDee.DRAW_Line 1024 / 2 - 20, 768 / 2, 1024 / 2 + 20, 768 / 2, RGBA(0, 0, 0, 0.2)
TwoDee.DRAW_Line 1024 / 2, 768 / 2 - 20, 1024 / 2, 768 / 2 + 20, RGBA(0, 0, 0, 0.2)
Scene.DrawText CPU.GetFPS & " Frames Per Second", 0, 0
If Scene.AdvancedCollision(CamNewPos, Vector3(CamNewPos.x + Sin(cy) * 2000, CamNewPos.y + Sin(-cx) * 2000, CamNewPos.z + Cos(cy) * Cos(-cx) * 2000), ColRes, TV_COLLIDE_MESH, TV_TESTTYPE_ACCURATETESTING, True) Then
Scene.DrawText ColRes.MeshID, 0, 40
End If
CPU.RenderToScreen
DoEvents
Loop Until IOsys.IsKeyPressed(TV_KEY_ESCAPE)
DoEvents
CPU.ReleaseAll
DoEvents
Set CPU = Nothing
DoEvents
Unload Me
DoEvents
End
End Sub
Function collision(StartPosition As D3DVECTOR, EndPosition As D3DVECTOR) As D3DVECTOR
collided = False
b1 = Rnd
For a1 = -3.14159 * 1 To 3.14159 * 1 Step 1 '0.5
a2 = a1 + b1
If Scene.Collide(Vector3(EndPosition.x + Sin(a2) * 5, EndPosition.y, EndPosition.z + Cos(a2) * 5), Vector3(StartPosition.x + Sin(a2 - 3.14159) * 5, StartPosition.y, StartPosition.z + Cos(a2 - 3.14159) * 5), TV_TESTTYPE_ACCURATETESTING) Then collided = True
'If Scene.Collide(Vector3(EndPosition.x + Sin(a2) * 5, EndPosition.y, EndPosition.z + Cos(a2) * 5), Vector3(StartPosition.x, StartPosition.y, StartPosition.z), TV_TESTTYPE_ACCURATETESTING) Then collided = True
Next
If collided = True Then
collision = StartPosition
Else
collision = EndPosition
End If
End Function
Function checkbounds(StartPosition As D3DVECTOR, EndPosition As D3DVECTOR) As D3DVECTOR
checkbounds.x = collision(StartPosition, Vector3(EndPosition.x, StartPosition.y, StartPosition.z)).x
checkbounds.z = collision(StartPosition, Vector3(StartPosition.x, StartPosition.y, EndPosition.z)).z
checkbounds.y = EndPosition.y
If LastNonCollidedPosition.x = 0 And LastNonCollidedPosition.y = 0 And LastNonCollidedPosition.z = 0 Then
LastNonCollidedPosition.x = StartPosition.x
LastNonCollidedPosition.y = StartPosition.y
LastNonCollidedPosition.z = StartPosition.z
End If
If checkbounds.x = StartPosition.x And checkbounds.z = StartPosition.z And checkbounds.y = StartPosition.y Then
If checkbounds.x = EndPosition.x And checkbounds.z = EndPosition.z And checkbounds.y = EndPosition.y Then
Else
checkbounds = LastNonCollidedPosition
End If
Else
LastNonCollidedPosition = collision(StartPosition, EndPosition)
End If
End Function
Sub generatemaze(horizwalls, vertwalls, width, height)
Dim walkable() As Boolean
ReDim walkable(width, height)
Dim wentleft As Boolean
Dim wentright As Boolean
Dim wentup As Boolean
Dim wenddown As Boolean
Dim roomcount As Long
Randomize Timer
For x = 1 To width
For y = 1 To height
horizwalls(x, y) = True
vertwalls(x, y) = True
Next
Next
xx = Int(Rnd * width) + 1
yy = Int(Rnd * height) + 1
walkable(xx, yy) = True
wentleft = False
wentright = False
wentup = False
wentdown = False
roomcount = 1
Do
Direction = Int(Rnd * 4)
If wentup And wentdown And wentright And wentleft Then
Do
xx = Int(Rnd * width) + 1
yy = Int(Rnd * height) + 1
Loop Until walkable(xx, yy)
End If
oxx = xx
oyy = yy
Select Case Direction
Case 0 'up
yy = yy - 1
If yy < 1 Then yy = 1
If walkable(xx, yy) = False Then
roomcount = roomcount + 1
walkable(xx, yy) = True
horizwalls(xx, yy) = False
wentup = True
Else
yy = oyy
End If
Case 1 'left
xx = xx - 1
If xx < 1 Then xx = 1
If walkable(xx, yy) = False Then
roomcount = roomcount + 1
walkable(xx, yy) = True
vertwalls(xx, yy) = False
wentleft = True
Else
xx = oxx
End If
Case 2 'down
yy = yy + 1
If yy > height Then yy = height
If walkable(xx, yy) = False Then
roomcount = roomcount + 1
walkable(xx, yy) = True
horizwalls(oxx, oyy) = False
wentdown = True
Else
yy = oyy
End If
Case 3 'right
xx = xx + 1
If xx > width Then xx = width
If walkable(xx, yy) = False Then
roomcount = roomcount + 1
walkable(xx, yy) = True
vertwalls(oxx, oyy) = False
wentright = True
Else
xx = oxx
End If
End Select
If roomcount Mod width = 0 Then
CPU.Clear
Scene.DrawText "Loading " & (roomcount / (width * height) * 80) & "%", 0, 0
CPU.RenderToScreen
End If
DoEvents
Loop Until roomcount = width * height
For a = 1 To 20
horizwalls(a, 0) = True
vertwalls(0, a) = True
Next
For x = 1 To width
For y = 1 To height
wallcount = 0
If horizwalls(x, y - 1) = True Then wallcount = wallcount + 1
If horizwalls(x, y) = True Then wallcount = wallcount + 1
If vertwalls(x - 1, y) = True Then wallcount = wallcount + 1
If vertwalls(x, y) = True Then wallcount = wallcount + 1
If wallcount = 3 Then DeadEnds(x, y) = True
Next
Next
End Sub