please help a poor unfortunate ex-DB user

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

lecks(Posted 2003) [#1]
i've been using DBC for about 6 months now (an 'extended time limit' demo version ;) ), but then found out about blitz 3 days ago and bought it today after a bit of playing.
from the demos, and playing with meshes, i feel i made the right choice by far (i WAS tossing up whether or not to buy db pro until i found blitz and converted some of my code to it). i wish i'd found about about blitz before db, because i've spent a hell of alot of time on this game, only to find out it will never work quick enough, or have good gfx on darkbasic. if anyone could help me, it would be highly appreciated.

my problem is with matrices(in db) or terrains(in blitz). my game physics work independant of the terrain/matrix, but the terrain/matrix has to look the same as the array that the physics work from, or the cars will be flying around no-where near the track :)

this is the darkbasic code (it's a bit messy, but it works, so you can use it in darkbasic classic demo or retail, or possibly db pro (i havent tried) it needs 2 bitmaps, matrixtexture2.bmp, and roadtexture1.bmp (these can be any size or whatever, but a small bitmap will be faster).
here it is:
[CODE]
sync on
tracklength# = 1000
`roadtexture$ = "roadtexture1.bmp"
`groundtexture$ = "matrixtexture1.bmp"
trackfilename$ = "testing" + "_road.map"
open to write 1,trackfilename$
write float 1,tracklength#
write float 1,100
write float 1,100
write float 1,100
write float 1,100
write string 1,roadtexture$
write string 1,roadtexture$

rem load textures
load image "roadtexture1.bmp",1
`load image "reflectred.bmp",2
`load image "reflectgrey.bmp",3
load image "matrixtexture2.bmp",4

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

rem set maximum and current corner and slope variables,
maxcorner# = 10
maxslope# = 5
corner# = 0
slope# = 0
rem the amount of tiles we've travelled past
matrix_z# = 1 : rem hopefully
rem check if moving forward to make the track smoother
moving# = 0
rem when this is 10, a reflector is placed
reflectcounter# = 0
rem reflector object no. start at 900 to avoid conflict in the game
reflectno# = 1000
rem set matrix wireframe off 1
rem 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 spacekey() = 0 and matrix_z# < tracklength# * 10
if moving# = 1
rem store variables for road triangle polygon creation
backtriy# = cam_y# + 0.5
backtrix# = cam_x#
backtriz# = cam_z#


endif

rem set moving if upkey is pressed, and move to next z joint in matrix.
if upkey()=1
cam_z#=cam_z# + 10
moving# = 1
else
moving# = 0
endif

if moving# = 1
if leftkey()=1 and corner# > maxcorner# * -1 then dec corner#
if rightkey()=1 and corner# < maxcorner# then inc corner#
if leftkey() = 0 and rightkey() = 0 and corner# < 0 then corner# = corner# + .5
if leftkey() = 0 and rightkey() = 0 and corner# > 0 then corner# = corner# - .5

if shiftkey() = 1 and slope# < maxslope# then inc slope#
if controlkey() = 1 and slope# > maxslope# * -1 then dec slope#
if shiftkey() = 0 and controlkey() = 0 and slope# < 0 then slope# = slope# + .5
if shiftkey() = 0 and controlkey() = 0 and slope# > 0 then slope# = slope# - .5

cam_x# = cam_x# + corner#
cam_y# = cam_y# + slope#
inc matrix_z#
section = setheight(matrix_z#, cam_y#, 100.0, 100.0)
write float 1, matrix_z#
write float 1, cam_x#
write float 1, cam_y#
rem set triangle variables for road creation
fronttriy# = cam_y# + 0.5
fronttrix# = cam_x#
fronttriz# = cam_z#
backleft# = backtrix# - 25
backright# = backtrix# + 25
frontleft# = fronttrix# - 25
frontright# = fronttrix# + 25
rem create triangle polygons for road, texture them, and make them static
rem | POINT ONE | POINT TWO | POINT THREE |
MAKE OBJECT TRIANGLE roadtri#, frontright#, fronttriy#, fronttriz#, backleft#, backtriy#, backtriz#, frontleft#, fronttriy#, fronttriz#
make static object roadtri#,1
texture object roadtri#, 1
rem delete object roadtri#
inc roadtri#
MAKE OBJECT TRIANGLE roadtri#, backleft#, backtriy#, backtriz#, frontright#, fronttriy#, fronttriz#, backright#, backtriy#, backtriz#
make static object roadtri#,1
texture object roadtri#, 1
inc roadtri#
endif

update matrix section
update matrix section + 1
update matrix section + 2
position camera cam_x#, cam_y# + 30, cam_z# - 100
set cursor 0,0
print " frame " ; frame#
print " zposition" ;matrix_z#
print " real Z position#" ; cam_z#
inc frame#
sync
endwhile

FUNCTION placereflectors(number#, x#, y#, z#, trackwidth#, texture1#, texture2#)
make object box number#,1,10,.1
position object number#, x# - (trackwidth# * .7), y# + 5, z#
make static object number#,1
texture object number#,2
inc number#
make object box number#,1,10,.1
position object number#,x# + (trackwidth# * .7), y# + 5, z#
make static object number#,1
texture object number#,3
ENDFUNCTION

FUNCTION setheight(z#, y#, leftheight#, rightheight#)

section = round(z#, 100.0)
sectiongroup = section
section = section * 3 + 1
oldz# = z#
if section > 3 then oldy# = get ground height( (sectiongroup * 3 + 1) - 3, 500.0, ABS(oldz# - (sectiongroup +.1)) * 10 )
z# = (z# - (((section -1) / 3)*100))
set cursor 0,50
print "setheight Z : " ; z#
print "setheight matrix : " ; section
print "section : " ; sectiongroup
print "setheight Y : " ; y#
print "setheight oldy : " ; oldy#
print "setheight oldz : " ; (oldz# - (((section -1) / 3)+.1)) *10
rem sync
rem set center matrix height
counter# = 10
while counter# > -1
if z# = 1 and section > 3 then SET MATRIX HEIGHT section, counter#, 0, oldy#
SET MATRIX HEIGHT section, counter#, z#, y#
dec counter#
endwhile

rem set matrix height for left side
counter# = 10
while counter# > -1
SET MATRIX HEIGHT section + 1, 10 - counter#, z#, y# + (((counter# * .01) * counter#) * leftheight#)
dec counter#
endwhile

rem set matrix height for right side
counter# = 0
while counter# < 11
SET MATRIX HEIGHT section + 2, counter#, z#, y# + (((counter# * .01) * counter#) * rightheight#)
inc counter#
endwhile
ENDFUNCTION section

FUNCTION preparematrixs(tracklength#, leftheight#, leftwidth#, rightheight#, rightwidth#, groundtex#)
remaindinglength# = tracklength#
while remaindinglength# > 10
dec remaindinglength#,10
inc sections#
endwhile
matrixnumber# = 1
currentsection# = 0
while sections# > currentsection# - 1
rem create center for current section
creatematrix(matrixnumber#, 1000.0, 1000.0, 10.0 , 100.0, 0.0, currentsection# * 1000.0, groundtex#)
inc matrixnumber#
creatematrix(matrixnumber#, leftwidth#, 1000.0, 10.0, 100.0, leftwidth# * -1.0, currentsection# * 1000.0, groundtex#)
inc matrixnumber#
creatematrix(matrixnumber#, rightwidth#, 1000.0, 10.0, 100.0, 1000.0, currentsection# * 1000.0, groundtex#)
inc matrixnumber#
inc currentsection#
set cursor 0,0
print "creating matrix"; matrixnumber#
sync
endwhile
rem 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#)
inc matrixnumber#
creatematrix(matrixnumber#, leftwidth#, remaindinglength# * 100.0, 10.0, remaindinglength# * 10.0, leftwidth# * -1.0, currentsection# * 1000.0, groundtex#)
inc matrixnumber#
creatematrix(matrixnumber#, rightwidth#, remaindinglength# * 100.0, 10.0, remaindinglength#* 10.0, 1000.0, currentsection# * 1000.0, groundtex#)
ENDFUNCTION

FUNCTION creatematrix(matrixnumber#, width#, length#, xsections#, zsections#, xpos#, zpos#, texture#)
make matrix matrixnumber#, width#, length# ,xsections#,zsections#
position matrix matrixnumber#,xpos#,0,zpos#
prepare matrix texture matrixnumber#,texture#,1,1
set matrix texture matrixnumber#,1,0
fill matrix matrixnumber#,0,1
rem set matrix wireframe on matrixnumber#
ENDFUNCTION

FUNCTION round(num#, tonearest#)
ret# = 0
while num# > 0
dec num#, tonearest#
if num# > 0 then inc ret#
endwhile
ENDFUNCTION ret#
[/CODE]
ok, so that's what i want to make. it might be a pretty stupid track editor, but it works perfect for the type of game i'm making, i just need to add functions like addscenery() after it.

ok now i've tried 2 methods to convert it to blitz, the first that i'll show is using "matrix.bb", which is in <blitzfolder>\samples\si\matrix\matrix.bb < this file needs to be in the same folder, im guessing ill get kicked/sued if i include it here, so i wont :). for me, this seems to create the matrices, but then does nothing. this one needs matrixtexture2.bmp (again, any bmp, but preferably a small one, and not pitch black :) )
[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()
;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# = 101

;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
;ERROR - MEMORY ACCESS VIOLATION, i'm leaving this for later :)
;roadpoints(0) = AddVertex(road, frontright#, fronttriy#, fronttriz#)
;roadpoints(1) = AddVertex(road, backleft#, backtriy#, backtriz#)
;roadpoints(2) = AddVertex(road, frontleft#, fronttriy#, fronttriz#)
;roadpoints(3) = AddVertex(road, backleft#, backtriy#, backtriz#)
;roadpoints(4) = AddVertex(road, frontright#, fronttriy#, fronttriz#)
;roadpoints(5) = AddVertex(road, backright#, backtriy#, backtriz#)

;create triangle polygons For road, texture them, And make them static
;AddTriangle(road, roadpoints(0), roadpoints(1), roadpoints(2))
;AddTriangle(road, roadpoints(3), roadpoints(4), roadpoints(5))
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

;not worried about this yet.
;FUNCTION placereflectors(number#, x#, y#, z#, trackwidth#, texture1#, texture2#)
; make object box number#,1,10,.1
; position object number#, x# - (trackwidth# * .7), y# + 5, z#
; make static object number#,1
; texture object number#,2
; inc number#
;; make object box number#,1,10,.1
; position object number#,x# + (trackwidth# * .7), y# + 5, z#
; make static object number#,1
; texture object number#,3
;ENDFUNCTION

FUNCTION setheight(z#, y#, leftheight#, rightheight#)
section = round(z#, 100.0)
sectiongroup = section
section = section * 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#, 100)
remaindinglength# = remainder(tracklength#, 100)
matrixnumber# = 1
currentsection# = 0
while sections# > currentsection# - 1
; create center for current section
creatematrix(matrixnumber#, 1000.0, 1000.0, 10.0 , 100.0, 0.0, currentsection# * 1000.0, groundtex#)
matrixnumber = matrixnumber + 1
creatematrix(matrixnumber#, leftwidth#, 1000.0, 10.0, 100.0, leftwidth# * -1.0, currentsection# * 1000.0, groundtex#)
matrixnumber = matrixnumber + 1
creatematrix(matrixnumber#, rightwidth#, 1000.0, 10.0, 100.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]

the final one is how i would preferably have it (using terrains rather than matrices), but i fear that i will have to completely reprogram my game if i do so. i'll explain what i need at the end of this post. the media needed for this is just matrixtexture2.bmp (again, any bmp)

[CODE]
Graphics3D 640,480,16,0
SetBuffer BackBuffer()

Global camera = CreateCamera()
Type trackstat
Field x#[100]
Field y#
End Type
Global road = CreateMesh()
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")
tracklength = 1000

Dim track.trackstat(tracklength)
For i = 1 To tracklength
track(i) = New trackstat
Next
noofterrains = roundint(tracklength, 100)
Dim terrainentitys(noofterrains)

preparematrixs(tracklength, terraintex)
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
;rem the amount of tiles we've travelled past
matrix_z# = 1 ;: rem hopefully
;rem check if moving forward to make the track smoother
moving# = 0
;rem when this is 10, a reflector is placed
reflectcounter# = 0
;rem reflector object no. start at 900 to avoid conflict in the game
reflectno# = 1000
;rem set matrix wireframe off 1
;rem 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
; rem store variables for road triangle polygon creation
backtriy# = cam_y# + 0.5
backtrix# = cam_x#
backtriz# = cam_z#
EndIf

; set moving If upkey 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
section = setheight(matrix_z#, cam_y#)

; write float 1, matrix_z#
; write float 1, cam_x#
; write float 1, cam_y#
; rem set triangle variables for road creation
fronttriy# = cam_y# + 0.5
fronttrix# = cam_x#
fronttriz# = cam_z#
backleft# = backtrix# - 25
backright# = backtrix# + 25
frontleft# = fronttrix# - 25
frontright# = fronttrix# + 25
;ERROR - MEMORY ACCESS VIOLATION
;roadpoints(0) = AddVertex(road, frontright#, fronttriy#, fronttriz#)
;roadpoints(1) = AddVertex(road, backleft#, backtriy#, backtriz#)
;roadpoints(2) = AddVertex(road, frontleft#, fronttriy#, fronttriz#)
;roadpoints(3) = AddVertex(road, backleft#, backtriy#, backtriz#)
;roadpoints(4) = AddVertex(road, frontright#, fronttriy#, fronttriz#)
;roadpoints(5) = AddVertex(road, backright#, backtriy#, backtriz#)

;rem create triangle polygons For road, texture them, And make them static
; AddTriangle(road, roadpoints(0), roadpoints(1), roadpoints(2))
; AddTriangle(road, roadpoints(3), roadpoints(4), roadpoints(5))
; make static Object roadtri#,1
; texture object roadtri#, 1
; inc roadtri#
EndIf

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

;FUNCTION placereflectors(number#, x#, y#, z#, trackwidth#, texture1#, texture2#)
; make object box number#,1,10,.1
; position object number#, x# - (trackwidth# * .7), y# + 5, z#
; make static object number#,1
; texture object number#,2
; inc number#
; make object box number#,1,10,.1
; position object number#,x# + (trackwidth# * .7), y# + 5, z#
; make static object number#,1
; texture object number#,3
;ENDFUNCTION

Function setheight(z#, y#)
y# = y# * .001
section = round(z#, 100.0)
z# = remainder(z#, 100.0)
Locate 0,50
;rem set center matrix height
counter = 128
While counter > -1
; If z# = 0 And section > 1 Then ModifyTerrain(terrainentitys(section) - 1, 100, z#, y#)
ModifyTerrain(terrainentitys(section), counter, z#, y#)
counter = counter - 1
Wend
End Function

Function preparematrixs(tracklength, texture)
remaindinglength# = tracklength
; sections = 0
sections = roundint(tracklength, 100)
For terrain = 0 To sections
makeTerrain(terrain, texture)
;terrain = terrain + 1
Next
End Function

Function makeTerrain(terrainno, texture)
terrainentitys(terrainno) = CreateTerrain(128)
ScaleEntity terrainentitys(terrainno),1000,10000,1000,1
PositionEntity terrainentitys(terrainno), 0, 0, terrainno * 1000
EntityTexture terrainentitys(terrainno), terraintex
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]

the only requirements are:
+ flat along the x axis (or at least near the track)
+ every z intercept should be 10 units apart in 3d space.
i dont care how many terrains/matrices it uses, what type of surface it uses (a mesh, terrain, or matrix). i just want to know how to get it to work like it did in DB.

please help a poor unfortunate soul that was struck with the disadvantage of knowing that DB exists, before he knew that blitz existed!
i know this is alot to ask, but if you can help me, you will definitely get your name in my credits :)

thanks in advance
lecks


lecks(Posted 2003) [#2]
ps. ignore commented stuff, i'm not worried about that YET ;)

and please dont tell me i'm going to have to rewrite the logic of my game. all it uses atm is track(zpos(onmatrix), ypos)


Gauge(Posted 2003) [#3]
Hrrm, i'm not sure how matrix work in db. I know the terrain funcion kind of sucks in blitz basic. Theres alot of people have made 3d tile progs. I think the best way is to make a terrain one mesh, then have different surfaces. I've never made a car program either, i'm sorta new to blitz. If i was to start a racing game i think you'd have to add collisions for each tire of the car maybe? or you could run a type and store the roll, pitch etc.

Which aspect isn't working exactly, god forbid me, but i'll try downloading darkbasic(no this doesn't damn me to hell, i'll delete it real quick) to see how yours works.

but I do know one thing...it'll be easier, alot easier to code, and alot easier to edit in blitz!


lecks(Posted 2003) [#4]
the reason i included the darkbasic code was to show what i wanted to happen... it works in the demo which is only a couple of meg (from memory). this isnt the game, it's only the track editor, so i'm not worried about positioning the car or collision or anything atm. i'm just trying to create a track in this method with the requirements mentioned above. i hope i'll be able to handle the rest after that.
all 3 lots of code are the full progs, so you can see, how bad the results ended up :). once again i know this is alot to ask, but if someone with some experience in blitz had a browse through it, i'm sure they could figure it out quite quickly.

basically probs are in #2, nothing happens, in #3 something happens, but i dont quite understand what :).

i doubt anyone could understand what i want without downloading the DB classic demo and trying the first code with it (creating the media files mentioned above). dont worry i'm by no means trying to get ppl to try DB, because it seems crap compared to blitz, it's just the only way i can show you my desired result.

i forgot to mention the controls before too:
UP = go - nothing will work without it
left/right = change angle for next x (curve)
right ctrl/shift = change angle for next y (slope)


Jeremy Alessi(Posted 2003) [#5]
Man, just ditch that old code if you're trying to make an editor. You can carve out a nice terrain in Blitz easily just my making a heightmap in photoshop. The use the driver physics for your cars. Then just program a placement editor to place trackside objects and whatnot.

I know you don't want to see your old code wasted but it seems to me that it'll be quicker for you to reprogram your game using aspects of Blitz which are different from what you were doing with DarkBASIC.

It's crazy that it took hours and hours even with MAT Edit to make a nice DB matrix/terrain and you can create the same thing using a heightmap image that'll take 5 mintutes in photoshop. You need to ditch most of your DB knowledge and focus on learning how Blitz works. It'll save you lots of time and effort.

Might I also suggest using a 3rd party modeling utility to create terrains. I was using terrains in Aerial Antics and it's turning out a lot better now that my artist is creating the terrains in 3DS Max.


lecks(Posted 2003) [#6]
well i fixed the matrix one, this was the problem:
[CODE]
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
[/CODE]
(duh).
is it legal to use the matrix library in <blitz folder>\samples\si\matrix in projects?
if not, would a blitz terrain be the way to go? or is guage correct in saying "I know the terrain funcion kind of sucks in blitz basic"?

ill attach the full code here once i sort it out properly


lecks(Posted 2003) [#7]
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]


BlitzSupport(Posted 2003) [#8]

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


While I'm not about to try and understand the DB code, you don't *have* to use heightmaps to create Blitz terrains -- see the ModifyTerrain command...


Rob(Posted 2003) [#9]
You can also build meshes on the fly. Also check out code archives for tips...


lecks(Posted 2003) [#10]
heightmaps didnt work, it didnt create a smooth enough terrain for the road to be placed on.

While I'm not about to try and understand the DB code, you don't *have* to use heightmaps to create Blitz terrains -- see the ModifyTerrain command...


i did try this, but it made the editor run very slow for some reason. may have been my code though, i'm not sure :)

You can also build meshes on the fly. Also check out code archives for tips...


I'm pretty sure the functions in the matrix.bb file creates meshes and uses them as terrains (and calls them matrices). don't quote me on that, but i'm pretty sure it's what it does. I might write my own functions to do this eventually anyway, cutting out the crap thats just there to make it usable in the DB functions. If you have a look at the last piece of code i posted, the road is a mesh being created on the fly. i dont know if i'm doing it the right way though :).

Thanks for your help guys, i'll figure something out one day :) I think i'm trying to rush through and get it done, so i can see how fast the game will work in blitz.

ps. is a 128tile x 128tile Terrain or 128tile x 128tile mesh faster?


lecks(Posted 2003) [#11]
is it possible to edit the pts of a mesh after the entity handle has been changed? eg.
[CODE]
;create mesh and array to use for road
Global road = CreateMesh()
Global roadsurface = CreateSurface(road)
Dim roadpoints(5)

for i = 1 to 50

;just giving it any numbers :)
backleftx# = frontleftx#
backrightx# = frontrightx#
backz# = frontz#
backy# = fronty#
frontleftx# = i*2
frontrightx# = i*2 + 10
frontz# = i*10
fronty# = i

roadpoints(0) = AddVertex(roadsurface, frontrightx#, fronty#, frontz#)
roadpoints(1) = AddVertex(roadsurface, backleftx#, backy#, backz#)
roadpoints(2) = AddVertex(roadsurface, frontleftx#, fronty#, frontz#)
roadpoints(3) = AddVertex(roadsurface, backleftx#, backy#, backz#)
roadpoints(4) = AddVertex(roadsurface, frontrightx#, fronty#, frontz#)
roadpoints(5) = AddVertex(roadsurface, backrightx#, backy#, backz#)

AddTriangle(roadsurface, roadpoints(0), roadpoints(1), roadpoints(2))
AddTriangle(roadsurface, roadpoints(3), roadpoints(4), roadpoints(5))
next
[/CODE]
would it then be possible to edit a point in the middle of this mesh? or would i have to create a huge array to handle each vertice?


IPete2(Posted 2003) [#12]
Lecks,

Don't know if this helps, but check out the deforming code in Mark Sibly's "Markio" demo in the MAK folder in the B3D samples - it may be called 'Castle' I can't remember.

When Markio fires flares into the mesh surface, it deforms into pits.

IPete2.


lecks(Posted 2003) [#13]
this probrably would have the same effect, but i think it uses terrains, not meshes.


Gauge(Posted 2003) [#14]
I'm about 99% sure a 128by 128 tile mesh would be a ton faster then terrain right now. And i think a 128 by 128 surfaces mesh would be faster then either one.

So what you need is a tile editor for terrain, etc etc right?


lecks(Posted 2003) [#15]
i've already decided to use mesh terrains rather that blitz terrains, because some demos with large blitz terrains seem to run quite slow, and if i were using terrains, there would be alot of big terrains.
i could create my own, but i dont know how to move a vertex after its handle has been overwritten.

is there some sort of command like
selectedvertex = VertexAt(Meshhandle, Xpos#, Ypos#, Zpos#)
or do i have to store the handle of every vertex?


jfk EO-11110(Posted 2003) [#16]
Use Linepicks, then:
PickedTriangle() ; Desc. kinda missing :( ,try to search for the word in the forums...
and then
TriangleVertex ( surface,triangle_index,corner )

Or maybe also:
CollisionTriangle ( entity,index )

Btw. You can also parse trough all Vertices and search for the nearest Vertex manually - since there is no 3D Command Execution, this might be a lot faster than a linepick.