Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Matrix Tile Physics

Author
Message
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 12th Feb 2003 05:47
With outside help I am going to program matrix physics, which will include how the slope of a matrix affects your movement. I will share my formulas and snippets gladly with the community, because I know how much this will benefit everyone.

Right now I NEED to know how to find the X,Y and Z values of the VERTICIES of a matrix tile. I need a way to find what tile you are on, and then find the corner coordinants. Can anyone help me with this? Because I know it will be a great advance in using matricies in game, once I derive the movment formulas.
trager
21
Years of Service
User Offline
Joined: 5th Feb 2003
Location: United Kingdom
Posted: 12th Feb 2003 11:21
I havent done any work with matrix but the description for the "set matrix height" function may offer some clues as to their inner workings.
arras
21
Years of Service
User Offline
Joined: 3rd Feb 2003
Location: Slovakia
Posted: 12th Feb 2003 12:54
Bit of math should do it easily

in what tile you are:

Tile_number_x=int(Matrix_size_x/Coordinate_x)+1
Tile_number_z=int(Matrix_size_z/Coordinate_z)+1

corner coordinates:

Corner_x1=(Tile_number_x-1) * Tilesize_x
Corner_z1=(Tile_number_z-1) * Tilesize_z
Corner_x2=Tile_number_x * Tilesize_x
Corner_z2=Tile_number_z * Tilesize_z

-tile have 4 corners: x1,z1 x1,z2 x2,z1 x2,z2

EXAMPLE:
if u have matrix 600*600 big and divided in to 3 tiles in x axis and 3 tiles z axis. Your coordinates are 350*450:

Matrix_size_x=600
Matrix_size_z=600

Tilesize_x=600 / 3 = 200
Tilesize_z=600 / 3 = 200

Coordinate_x=350
Coordinate_z=450
------------------------------------
Tile_number_x=2
Tile_number_z=3
it means you are in tile 2 on x axis and 3 on z axis or second from left to right and thirth fom down to up

Corner_x1=200
Corner_z1=400
Corner_x2=400
Corner_z2=600
these are coordinates of four corners your tile have

try it and let me know if it works for you, I was just typing it from head without codyng and testing it...

arras
21
Years of Service
User Offline
Joined: 3rd Feb 2003
Location: Slovakia
Posted: 12th Feb 2003 13:03
well there is one thing wrong, it should be like this:

Tile_number_x=int(Coordinate_x/Tilesize_x)+1
Tile_number_z=int(Coordinate_z/Tilesize_z)+1

sorry...

QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 12th Feb 2003 14:34
wait, I was assuming there would be 3 coordinants for each corner vertices, x y and z, with 12 variables in all. This gives me 4, and I really need to know the height of all four verticies (and the x and z of all four) to do the physics equations.
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 12th Feb 2003 14:53
that was worded stupidly. I need 12 variabless, 3 for each vertices

x1#,y1#,z1#
x2#,y2#,z2#
x3#,y3#,z3#
x4#,y4#,z4#

in order to program the physics of the motion.
arras
21
Years of Service
User Offline
Joined: 3rd Feb 2003
Location: Slovakia
Posted: 12th Feb 2003 15:10
Well then you should do this:

Use GET MATRIX HEIGHT() comand. Look DBhelp for description of what height you get for understanding next. This comand is not giving you height of tile but height of specified grid point coordinate which is in fact one corner of tile.

from example above:

corner_y=GET MATRIX HEIGHT(Matrix Number,Tile_number_x,Tile_number_z)

if you need all 4 corners of tile, you have to do it 4 times:

at coordinate x1,z1:
corner_y1=GET MATRIX HEIGHT(Matrix Number,Tile_number_x,Tile_number_z)

at coordinate x1,z2:
corner_y2=GET MATRIX HEIGHT(Matrix Number,Tile_number_x,Tile_number_z-1)

at coordinate x2,z1:
corner_y3=GET MATRIX HEIGHT(Matrix Number,Tile_number_x-1,Tile_number_z)

at coordinate x2,z2:
corner_y4=GET MATRIX HEIGHT(Matrix Number,Tile_number_x-1,Tile_number_z-1)


You can use comands above and store all data in arrays for faster and simple use
like:
dim matrix_tileheight(number_of_tiles_x,number_of_tiles_z) for storing data for each tile in matrix.

I hope I described ti clear enought for you...

arras
21
Years of Service
User Offline
Joined: 3rd Feb 2003
Location: Slovakia
Posted: 12th Feb 2003 15:25
for tile 2,3 it would be

GET MATRIX HEIGHT(Matrixnum,2,3) for right top corner
GET MATRIX HEIGHT(Matrixnum,2,2) for right down corner
GET MATRIX HEIGHT(Matrixnum,1,3) for left top corner
GET MATRIX HEIGHT(Matrixnum,1,2) for left down corner

two numbers inside brackets are grid point coordinate of tile corner
so right top corner have grid coordinate 2,3
if you need real coordinate just make 2*tilesize,3*tilesize
if tilesize is 200 you would get that right top corner have x and z coordinate 400,600 ..y you have from GET MATRIX HEYGHT() comand already

Is my description clear enought now?

trager
21
Years of Service
User Offline
Joined: 5th Feb 2003
Location: United Kingdom
Posted: 12th Feb 2003 19:37
do you reckon
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 12th Feb 2003 21:10
veeeeeeeeeeeery good ty
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 12th Feb 2003 21:51
are there commands to find the total number of tiles on the x and z coordiants, and to find the total matrix x and z lengths?

like
matrixXlength=matrix size x(matrixnum)
?

anything like that?
freak
21
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 13th Feb 2003 01:13
to do these physics you don't need the x,y and z position of matrix tiles

just check the player object and calculate the angle it made (by comparing previous and new coordinates)

when the angle's positive you'll have to let your player object move slower, and when it's negative you'll have to let it move faster

seems very easy

QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 13th Feb 2003 01:29
so tell me how you slide when you are stationary.
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 13th Feb 2003 01:37
or how if you jump onto a steep slope, you slide off it
freak
21
Years of Service
User Offline
Joined: 20th Jan 2003
Location:
Posted: 13th Feb 2003 01:37
you mean how to let your player slide when the hill's to steep?

just move your player when the angle's to big... In which direction? Before your sync, just move your player with a positive amount, then with a negative amount. Save both coordinates and check which one was the lowest. The player has to move in the direction of that coordinate.

QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 13th Feb 2003 02:38
oh nevermind, I got it all worked out
spooky
21
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 13th Feb 2003 13:13
I loaded up the 'iced' game off original DB and it has really good matrix code, including sliding collision, slide down slopes (even when you are stationary), resistance force when you walk up slopes, e.t.c.

The game is all on one 'height' and so most of the code does not even get run even though it's in there.

I have taken all the juicy bits of code out, simplified it, and put them in a little demo to demonstrate it.

I'm at work at moment but will paste code tonight if you are interested.

I love it when a plan comes together
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 14th Feb 2003 00:03
NOOOOO!!!! DAMNIT!!! ITS NOT DIVIDED INTO SQUARES, ITS DIVIDED INTO TRIANGLES!! AND THEY HAVE DIFFERENT SLOPES! darn darn darn, I thougth I had it all worked out...

Is there any to find which triangle you are on, and then THOSE THREE corner coordiants? I was sooo close, then this came up! I mean one triangle could be flat and the other one could be really steep, so sadly this code wont work unless you know what triangle you are on...

help!?!??!!!!!!!!!! (
spooky
21
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 14th Feb 2003 01:03
I know what you mean by the DAMN TRIANGLES!

Only tested in DBPro





I love it when a plan comes together
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 14th Feb 2003 05:59
except for the fact that you slide down everythign (easily fixed) that's pretty nifty
spooky
21
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 14th Feb 2003 13:54
My weekend challenge:

1. Don't slide down everything - only steep hills

2. Put in some 3d objects and do sliding collision on those

3. Maybe do a jump routine, but jumping off big cliffs needs some sort of gravity code which may need more time!

I love it when a plan comes together
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 15th Feb 2003 02:14
that makes me angry, you did in 2 perfectly hours what it took me 2 days to botch terribly
spooky
21
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 16th Feb 2003 00:53
Look in code snippets for updated version which now has option for not autosliding down shallow hills!

It now also does slding collision on objects.

Be happy in the thought that it took me a hell of a lot longer than 2 hours to knock up.

Gronda, Gronda

Login to post a reply

Server time is: 2024-05-19 21:11:45
Your offset time is: 2024-05-19 21:11:45