Here’s what I love about this: it took maybe 5 minutes to modify an existing example from Keith Peter’s book Making Things Move to make the balls bounce around in 3D. Then it took a few hours to figure out how to skew the grids to make the cube walls. I’m learning FP10 3D slowly but surely.
view source |
If you’ve read Keith’s book then you’ll see in the code that all I had to do was copy the code for either the x or y properties and then convert them to z. Before we had: vx and vy. Just toss in a vz. The boundry detection was pretty much the same. Where we had:
if( ball.y + ball.radius > _height ) {
ball.y = _height - ball.radius;
ball.vy *= bounce;
} else if( ball.y - ball.radius < 0 ) {
ball.y = ball.radius;
ball.vy *= bounce;
}
That detected the y-boundaries. Now just make a small adjustment to do the same for z:
if( ball.z + ball.radius > _depth ) {
ball.z = _depth - ball.radius;
ball.vz *= bounce;
} else if( ball.z - ball.radius < -_depth ) {
ball.z = - _depth + ball.radius;
ball.vz *= bounce;
}
I’m really looking forwand to seeing what everyone is going to do with this new dimension that is so readibly accessible to us. I’m thinking there will be some disigns that are going to be jaw dropping.
Making things move with FlashPlayer10 3D goodness originally appeared on polyGeek.com on November 30, 2008.