hello
Ive made a program with a 10 by 10 grid of randomized matrices and i want to walk the camera over it.
I\'ve written this code...
ground:
rem // make values for camx and cam z 1 per matrix(size of matrix is 1000 units)
camx = camera position x(0)/1000
camz = camera position z(0)/1000
remstart
the x row is ten 1000 unit matrices joined along the x axis, numbered one to 10.
the z row is ten 1000 unit matrices joined along the z axis, numbers go up in tens
eg
11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10
remend
rem // round the devided figures to a whole number
camx = int (camx + 1)
camz = int (camz * 10)
rem // add the two numbers to determine the matrix number
matno = camx + camz
rem // visual confermation of correct matrix number
print matno
remstart
After repeated failure to get the camera to stick to the matrix y plane,
I figured that the problem must lie in the fact that I have a 1000 unit matrix,
however the camera x z co-ordinates can be more than 1000, possibly screwing with the Get Ground Height(Matno,x,z) command.
I wrote the following code to get a co-ordinate that was less than 1000
It didnt help, however, i\'ve left It in here for future use and troubleshooting
remend
matx$ = str$(camera position x(0))
matx$ = right$(matx$,3)
matz$ = str$(camera position z(0))
matz$ = right$(matx$,3)
matx = val(matx$)
matz = val(matz$)
rem // visual confermation of variables
print \"matx: \", matx
print \"matz: \", matz
return
...to find the current matrix the camera is over, and it seems to display the correct matrix number.
however when I try to Use the Get ground height() command
It doesnt seem to respond correctly, it seems like its taking the ground height from another matrix and nothing I do seems to fix it.
here is the entire program to run and see
Rem Project: Matrix grid
Rem Created: Wednesday, February 09, 2011
Rem ***** Main Source File *****
rem // load your own image here
load image \"media\\grass4.jpg\",1
color backdrop 0
sync rate 60
set camera range 0,1,2000
rem // declare variables
playerspeed = 6
top = 10
a = 1
b = top
size = 1000
hills = 5
hillsize = size / 10
mx = 0
mz = 0
max = top * top
h1 = 0
h2 = 0
h3 = 0
rem // generate matrix
gosub matgen:
rem // join the sides of the matrix
gosub MatJoin:
rem // join the corners of the matrix
gosub cornerjoin:
rem // make an object for the keys to control and the camera to follow
make object cube 1,1
position object 1, 0,30,0
rotate object 1,90,0,0
position camera 0,0,30,0
rem // main loop
do
gosub Ground:
gosub mouselook:
rem position camera 0,camera position x(0), get ground height(matno,camera position x(0),camera position z(0)) +30,camera position z(0)
print \"x : \",camera position x(0)
print \"z : \",camera position z(0)
print \"y : \",camera position y(0)
print \"My: \",get ground height(matno,matx,matz) + 10
loop
mouselook:
rem // move cube attached to camera
if Keystate(17) = 1 then move object up 1,playerspeed
if Keystate(30) = 1 then move object left 1,playerspeed
if Keystate(31) = 1 then move object down 1,playerspeed
if Keystate(32) = 1 then move object right 1,playerspeed
if Keystate(17) = 1 and Keystate(30) = 1
move object up 1,playerspeed/2
move object left 1,playerspeed/2
endif
if Keystate(17) = 1 and Keystate(32) = 1
move object up 1,playerspeed/2
move object right 1,playerspeed/2
endif
if Keystate(31) = 1 and Keystate(30) = 1
move object down 1,playerspeed/2
move object left 1,playerspeed/2
endif
if Keystate(31) = 1 and Keystate(32) = 1
move object down 1,playerspeed/2
move object right 1,playerspeed/2
endif
rem // determine x y z co-ordinates of the camera/object
x = object position x(1)
z = object position z(1)
y = get ground height (matno,matx,matz) +10
position object 1,x,y,z
position camera 0,x,y,z
rem // mouselook
CX#=Camera Angle X(): CY#=Camera Angle Y(): CZ#=Camera Angle Z()
If MType = 0
CY#=Wrapvalue(CY#+mousemovex())
CX#=Wrapvalue(CX#+mousemovey())
Else
CY# = CurveAngle(CY#+mousemovex(),CY#,10.0)
CX# = CurveAngle(CX#+mousemovey(),CX#,10.0)
Endif
Rotate Camera CX#,CY#,CZ#
rotate object 1,90,cy#,cz#
return
ground:
rem // make values for camx and cam z 1 per matrix(size of matrix is 1000 units)
camx = camera position x(0)/1000
camz = camera position z(0)/1000
remstart
the x row is ten 1000 unit matrices joined along the x axis, numbered one to 10.
the z row is ten 1000 unit matrices joined along the z axis, numbers go up in tens
eg
11 12 13 14 15 16 17 18 19 20
1 2 3 4 5 6 7 8 9 10
remend
rem // round the devided figures to a whole number
camx = int (camx + 1)
camz = int (camz * 10)
rem // add the two numbers to determine the matrix number
matno = camx + camz
rem // visual confermation of correct matrix number
print matno
remstart
After repeated failure to get the camera to stick to the matrix y plane,
I figured that the problem must lie in the fact that I have a 1000 unit matrix,
however the camera x z co-ordinates can be more than 1000, possibly screwing with the Get Ground Height(Matno,x,z) command.
I wrote the following code to get a co-ordinate that was less than 1000
It didnt help, however, i\'ve left It in here for future use and troubleshooting
remend
matx$ = str$(camera position x(0))
matx$ = right$(matx$,3)
matz$ = str$(camera position z(0))
matz$ = right$(matx$,3)
matx = val(matx$)
matz = val(matz$)
rem // visual confermation of variables
print \"matx: \", matx
print \"matz: \", matz
return
cornerjoin:
rem // Loop to cycle through all the matrices and get an average of their corner heights. setting all corners to that value
for mat = 1 to max - 1 step 1
h1 = get ground height ((mat + 1),0,hills)
h2 = get ground height ((mat + 1),hills,hills)
if mat < 90
h3 = get ground height ((mat + 10),0,0)
h4 = get ground height ((mat + 10),0,hills)
h5 = get ground height ((mat + 11),0,hills)
else
h3 = 0
h4 = 0
endif
h6 = (h1+h2+h3+h4+h5)/5
set matrix height mat,hills,0,h6
set matrix height mat,0,0,h6
set matrix height (mat+1),0,hills,h6
set matrix height (mat+1),hills,hills,h6
if mat < 90
set matrix height (mat+10),0,0,h6
set matrix height (mat+10),0,hills,h6
set matrix height (mat+11),0,hills,h6
endif
update matrix mat
next mat
return
MatJoin:
rem // Loop to cycle through all the matrices and get an average of their edge heights. setting all sides to that average value
for mat = 1 to (max - 1) step 1
for side = 0 to hills step 1
if mat < 99
h1 = get ground height ((mat+1), hills,side) rem // side A
h2 = get ground height ((mat),0,side) rem // side C
h3 = (h1+h2)/2
set matrix height mat,hills,side, h3
set matrix height (mat+1),0,side,h3
endif
if mat < 90
h1 = get ground height (mat, side,hills) rem // side D
h2 = get ground height ((mat+10),side,0) rem // side B
h3 = (h1+h2)/2
set matrix height mat,side,hills, h3
set matrix height (mat+10),side,0, h3
endif
next side
update matrix mat
next mat
return
matgen:
rem // generates a grid of matrices
for MatrixZ = 1 to top step 1
for M = a to b step 1
make matrix m,size,size,hills,hills
position matrix M,mx,0,mz
terrain = rnd(2)+1
select terrain
case 1: ground = 5 :endcase
case 2: ground = 70 :endcase
case 3: ground = 200 :endcase
case default: print \"I hate computers\":endcase
endselect
randomize matrix M, ground
prepare matrix texture M,1,1,1
update matrix M
mx = mx + size
next M
mx = 0
mz = mz + size
a = a + top
b = b + top
next matrixz
return
Can anyone see what I am doing wronge?
Is there an easier way to determine which matrix my camera is moving over?
thankyou
kezzla
Sometimes I like to use words out of contents