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 / Look What I Just Did!

Author
Message
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 21st Jul 2007 00:12
I've just finished this 3D world program using only 2D commands.
I'm pretty damn chuffed with myself but I could use some help turning the code into functions.
Can anyone help?

CONTROLS:
LEFT/RIGHT - Moves cube along X-Axis
UP/DOWN - Moves cube along Y-Axis
SHIFT/CONTROL - Moves cube along Z-Axis



I am king of the noobs!
Pixelator
16
Years of Service
User Offline
Joined: 8th Jul 2007
Location: here
Posted: 21st Jul 2007 00:24
crazy:0

The problem with the gaming community is people think that the resolution of a game defines how good it is. I am not afraid to make a game where the main character is 50x50.
Insert Name Here
17
Years of Service
User Offline
Joined: 20th Mar 2007
Location: Worcester, England
Posted: 21st Jul 2007 13:34
What is Pixelator talking about?

I never tell the truth.
That ain't a paradox.
I always tell lies is though.
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 22nd Jul 2007 20:13
@Obese87

I may be misunderstanding your goal, so sorry if this doesn't fit with what you are trying to do. Your approach may be limiting - by that I mean if you look at 3d in 2d as lines, you may run into trouble. If you think of 3d in 2d as 3d points (vertices) translated to 2d, then you're more on the road to how 3d is actually rendered on 2d screens.

A cube, for example, can be considered to have 8 vertices. When the vertices are connected together in the manner you described above, you get your cube - no mystery there. Now if we actually want to move this cube along the z axis (assuming z is into and out of the monitor directly in front of us), those vertices either spread apart, or get closer together. In the most basic form, the x and y positions in 2d of the x,y and z position of 3d are repesented by 2dx=x/z and 2dy=y/z .

Basically, for the cube, each of the x and y positions will be divided by a z that is increasing or decreasing. As the z increases, x and y are getting smaller so the vertices move closer together. If z decreases, x and y are getting larger so the vertices move farther apart. After the z transformation, reconnect the lines between the vertices to redraw the cube.

This doesn't account for camera perspective or clipping plane or the screen size and coordinates, but that is beyond the scope of this post at present.

If your 2d world has a 45 degree perspective (everything is diagonal) your premise is sound - except the object is going to scale as it moves on the z axis. You can get a scaling factor much in the same way by dividing by an imaginary z. The steps between z will determine how fast towards or away from the viewer the object moves. This can be applied to anything you want to draw. If you use block images like sprites, then you won't be using the individual vertices I was mentioning earlier, but you would be scaling the whole object by your z. The only thing, if the sprite is scaling up, it will pixelate as it gets larger, so you may have more detailed images that are used when the scale goes past a certain level.

Enjoy your day.
Libervurto
17
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 22nd Jul 2007 20:45
@Latch
Quote: "Your approach may be limiting - by that I mean if you look at 3d in 2d as lines, you may run into trouble. If you think of 3d in 2d as 3d points (vertices) translated to 2d, then you're more on the road to how 3d is actually rendered on 2d screens."

This is exactly what I thought as soon as I'd finished it lol.

Your explanation of the Z deformation helps a lot
The original purpose of creating this was for a game I'm making called DARK KNIGHTS (see community project thread), the purpose was to make a 3D world for sprites so they can have 3D collisions.
If I can factor in the Z-scaling that will be enough for the game, but I also want to take this idea further.

Here is a game I made with the 2D 3D world, I entered it in the DBC challenge (its much better now though)

2D CUBE CATCHER!
use the arrow keys to catch the cubes.
10pt bonus for precision
use SHIFT and CONTROL to change perspective! very cool
set Time_Limit = 0 if you don't want a timer.



I am king of the noobs!

Login to post a reply

Server time is: 2024-05-18 16:25:09
Your offset time is: 2024-05-18 16:25:09