A ball bouncing in a room. This new version should be easier to work out and also to make remixes from.
One loop does all the display, and another one does the position in 3D - bouncing, falling etc.
To remix, try duplicating the ball, and you'll get a second ball in no time. Change its starting coordinates and speed.
The old notes are here:
To understand this, download it first (!). The ball has 3 co-ordinates in the room: x, y, z positions (z is depth away from you). First, we decide on the proportions of the space where we are working. I wanted the ball to be half the size when it's at the far end, so z is transformed following this formula:
zfactor = 1+(z/400)
This way, if - z=0, zfactor = 1 (max size) - z=400, zfactor = 2 (furthest away, min size)
Now to place the ball we do:
screen x = x/zfactor screen y = y/zfactor size % = 100/zfactor
Simple, innit? It's called one-point perspective.
To get the ball to move, we use speed co-ordinates, like a ball in 2D, only there are 3 speeds, for the 3 axes. I added a co-ordinate to the "gravity ball" example provided with the samples.
Comments
You need to be logged in to post comments
Add a Comment
That's brilliant! Hopefully someone will have more imagination than me and make a game out of all this?
(view all replies)Comment Reply