please help a poor unfortunate ex-DB user

Blitz3D Forums/Blitz3D Programming/please help a poor unfortunate ex-DB user

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

damn i type too slow :)

i do want to use blitz terrains rather than Db stuff, but i still need to make the terrain suitable for the game, and i think this could be quite difficult using height maps to create terrains.

i might give it a try anyway, and see how it goes. the matrix version works ok, but i would rather use blitz features than db features.

thanks for your input.

heres the code using matrix.bb (needs a texture matrixtexture2.bmp, or you can change the filename near the top). It's messy, but it sort of works and shows what im trying to do (sort of :) )

[CODE]
Graphics3D 640,480,16,0
SetBuffer BackBuffer()
Include "matrix.bb"

Global camera = CreateCamera()
; gonna be for saving (hopefully)
;Type trackstat
; Field x#[100]
; Field y#
;End Type
;was gonna be for the road, but doest work yet
Global road = CreateMesh()
Global roadsurface = CreateSurface(road)
Dim roadpoints(5)

;roadtexture$ = "roadtexture1.bmp"
groundtexture$ = "matrixtexture2.bmp"
;trackfilename$ = "testing" + "_road.map"


;Global roadtex = LoadTexture("roadtexture1.bmp")
;Global flectred = LoadTexture("reflectred.bmp")
;Global flectgrey = LoadTexture("reflectgrey.bmp")
;Global terraintex = LoadTexture("matrixtexture2.bmp")

DB_LoadImage( groundtexture, 4 )
tracklength# = 2100

;Dim track.trackstat(tracklength)
;For i = 1 To tracklength
; track(i) = New trackstat
;Next

noofterrains = roundint(tracklength, 100)
Dim terrainentitys(noofterrains)

preparematrixs(tracklength#, 100.0, 100.0, 100.0, 100.0, 4.0)
cam_z# = 0
cam_y# = 0
cam_x# = 500

;set maximum and current corner and slope variables,
maxcorner# = 10
maxslope# = 5
corner# = 0
slope# = 0
;the amount of tiles we've travelled past
matrix_z# = 1 ;: hopefully
;check if moving forward to make the track smoother
moving# = 0
;when this is 10, a reflector is placed
reflectcounter# = 0
;reflector object no. start at 900 to avoid conflict in the game
reflectno# = 1000
;set matrix wireframe off 1
;1st Triangle to create road from
roadtri# = 20000
backtriy# = 0
fronttriy# = 0
backtrix# = 500
fronttrix# = 500
backtriz# = 0
fronttriz# = 0
moving# = 0
frame# = 0
section = 1

While matrix_z# < tracklength
If moving# = 1
; store variables for road triangle polygon creation
backtriy# = cam_y# + 0.5
backtrix# = cam_x#
backtriz# = cam_z#
EndIf

; set moving If up key is pressed, And move To Next z joint in matrix.
If KeyDown(200)=1
cam_z#=cam_z# + 10
moving# = 1
Else
moving# = 0
EndIf
If KeyDown(108) Then cam_z# = cam_z# - 1
If moving# = 1

If KeyDown(203)=1 And corner# > maxcorner# * -1 Then corner# = corner - 1
If KeyDown(205)=1 And corner# < maxcorner# Then corner# = corner + 1
If KeyDown(203) = 0 And KeyDown(205) = 0 And corner# < 0 Then corner# = corner# + .5
If KeyDown(203) = 0 And KeyDown(205) = 0 And corner# > 0 Then corner# = corner# - .5

If KeyDown(54) = 1 And slope# < maxslope# Then slope# = slope + 1
If KeyDown(157) = 1 And slope# > maxslope# * -1 Then slope# = slope# - 1
If KeyDown(54) = 0 And KeyDown(157) = 0 And slope# < 0 Then slope# = slope# + .5
If KeyDown(54) = 0 And KeyDown(157) = 0 And slope# > 0 Then slope# = slope# - .5

cam_x# = cam_x# + corner#
cam_y# = cam_y# + slope#
matrix_z# = matrix_z# + 1
setheight(matrix_z#, cam_y#, 100, 100)
fronttriy# = cam_y# + 0.5
fronttrix# = cam_x#
fronttriz# = cam_z#
backleft# = backtrix# - 25
backright# = backtrix# + 25
frontleft# = fronttrix# - 25
frontright# = fronttrix# + 25
roadpoints(0) = AddVertex(roadsurface, frontright#, fronttriy#, fronttriz#)
roadpoints(1) = AddVertex(roadsurface, backleft#, backtriy#, backtriz#)
roadpoints(2) = AddVertex(roadsurface, frontleft#, fronttriy#, fronttriz#)
roadpoints(3) = AddVertex(roadsurface, backleft#, backtriy#, backtriz#)
roadpoints(4) = AddVertex(roadsurface, frontright#, fronttriy#, fronttriz#)
roadpoints(5) = AddVertex(roadsurface, backright#, backtriy#, backtriz#)

;rem create triangle polygons For road, texture them, And make them static
AddTriangle(roadsurface, roadpoints(0), roadpoints(1), roadpoints(2))
AddTriangle(roadsurface, roadpoints(3), roadpoints(4), roadpoints(5))
; EntityTexture(road, roadtex)
EndIf

PositionEntity camera,cam_x#, cam_y# + 30, cam_z# - 100
; PositionEntity camera,cam_x#, 60,0
Locate 0,0
Print " frame " + frame#
Print " zposition" + matrix_z#
Print " real Z position#" + cam_z#
frame# = frame# + 1
UpdateWorld
RenderWorld
Flip
Wend


FUNCTION setheight(z#, y#, leftheight#, rightheight#)
sectiongroup = round(z#, 100.0)
;first matrix number
section = sectiongroup * 3 + 1
oldz# = z#
If section > 3 Then oldy# = getgroundheight( (sectiongroup * 3 + 1) - 3, 500.0, Abs(oldz# - (sectiongroup +.1)) * 10 )
z# = (z# - (((section -1) / 3)*100))

; set center matrix height
counter# = 10
While counter# > -1
;try to join 'matrices' together.. doesnt work yet though
If z# = 1 And section > 3 Then SETMATRIXHEIGHT(section, counter#, 0, oldy#)
SETMATRIXHEIGHT(section, counter#, z#, y#)
counter# = counter# - 1
Wend
;left matrix height
counter# = 10
While counter# > -1
SETMATRIXHEIGHT(section + 1, 10 - counter#, z#, y# + (((counter# * .01) * counter#) * leftheight#))
counter = counter - 1
Wend

; set matrix height for right side
counter# = 0
While counter# < 11
SETMATRIXHEIGHT(section + 2, counter#, z#, y# + (((counter# * .01) * counter#) * rightheight#))
counter = counter + 1
Wend
End Function

FUNCTION preparematrixs(tracklength#, leftheight#, leftwidth#, rightheight#, rightwidth#, groundtex#)
sections# = round(tracklength#, 1000)
remaindinglength# = remainder(tracklength#, 1000)
matrixnumber# = 1
currentsection# = 0
while sections# > currentsection# - 1
; create center for current section
creatematrix(matrixnumber#, 1000.0, 1000.0, 100.0 , 100.0, 0.0, currentsection# * 1000.0, groundtex#)
matrixnumber = matrixnumber + 1
creatematrix(matrixnumber#, leftwidth#, 1000.0, 100.0, 10.0, leftwidth# * -1.0, currentsection# * 1000.0, groundtex#)
matrixnumber = matrixnumber + 1
creatematrix(matrixnumber#, rightwidth#, 1000.0, 100.0, 10.0, 1000.0, currentsection# * 1000.0, groundtex#)
matrixnumber = matrixnumber + 1
currentsection# = currentsection# + 1
;set cursor 0,0
Print "creating matrix" + matrixnumber#
; sync
Wend
;create matrix from the remainder
remaindinglength# = int(remaindinglength#)
creatematrix(matrixnumber#, 1000.0, remaindinglength# * 100.0, 10.0, remaindinglength# * 10.0, 0.0, currentsection# * 1000.0, groundtex#)
matrixnumber = matrixnumber + 1
creatematrix(matrixnumber#, leftwidth#, remaindinglength# * 100.0, 10.0, remaindinglength# * 10.0, leftwidth# * -1.0, currentsection# * 1000.0, groundtex#)
matrixnumber = matrixnumber + 1
creatematrix(matrixnumber#, rightwidth#, remaindinglength# * 100.0, 10.0, remaindinglength#* 10.0, 1000.0, currentsection# * 1000.0, groundtex#)
End Function

Function creatematrix(matrixnumber#, width#, length#, xsections#, zsections#, xpos#, zpos#, texture#)
makematrix(matrixnumber#, width#, length# ,xsections#,zsections#)
positionmatrix(matrixnumber#,xpos#,0,zpos#)
preparematrixtexture(matrixnumber#,texture#,1,1)
;setmatrixtexture(matrixnumber#,1,0)
fillmatrix(matrixnumber#,0,1)
; set matrix wireframe on matrixnumber#
End Function

Function round(num#, tonearest#)
ret# = 0
While num# > 0
num# = num# - tonearest#
If num# > 0 Then ret# = ret# + 1
Wend
Return ret#
End Function

Function roundint(num, tonearest#)
ret = 0
While num > 0
num = num - tonearest
If num > 0 Then ret = ret + 1
Wend
Return ret
End Function

Function remainder(num#, tonearest#)
ret# = 0
While num# > 0
num# = num# - tonearest#
If num# > 0 Then ret# = num#
Wend
Return ret#
End Function
[/CODE]