Visualization Experience

 <  Day Day Up  >  

On the CD-ROM, you will find a demo named Cannon Physics . Here's a brief description from the programmers, Michael Fawcett and Mike Wigand:

The Cannonball program is meant to look and feel a little like a Tank Wars or Scorched Earth clone, because we felt that many people would be familiar with the simple interface, and it lent itself to simple projectile physics nicely . The framework is kept to a minimum so that you can concentrate on the physics code rather than getting lost in files of collision code, Win32 code, image loaders, and so on .

Run the demo by double-clicking Cannon Physics.exe. You see a black background with two small cannons at the bottom of the screen and a bunch of information at the top of the screen. Basically, two cannons shoot back and forth at each other. Above each cannon, certain variables are tracked. In the middle are the instructions so that you don't need to memorize the hot keys.

Start by experimenting with player 1 (on the left). Use the right arrow to change the angle to 60 °, use the up arrow to change the force to 50N, and leave the mass at 1kg. Press the spacebar to launch the cannonball. You see the numbers above start to change, and the projectile path is a white dotted line. When the cannonball finally comes to rest, a Settings window pops up. You'll change those settings later, so just click OK for now. On the top-left side of the screen you see that the initial velocity is 10m/s. Chapter 12, "Energy," addresses how to calculate that value, so for now just let the program calculate it for you. This tells you that the initial velocity when the cannonball is shot is 10m/s @ 60 °.

Now it's player 2's turn to shoot back. Use the left arrow to change the angle to 120 °, use the up arrow to change the force to 50N, and leave the mass at 1kg. These are essentially the same settings that player 1 had, but this time you're shooting toward the left. This means that the initial velocity is 10m/s @ 120 °. Calculate what the maximum height of the cannonball should be on paper before you press the spacebar. Your calculations should look similar to this:

Horizontal

Vertical

Given

Find

Given

Find

v x = 10cos120 °

     

= 10m/s

 

v iy = 10sin120 °

 

8.660

D y = ?

   

a x = 0m/s 2

 

a y = “9.8m/s 2

 
   

V fy = 0m/s

 

On the vertical side, you can use equation 5 to calculate the height:

graphics/10equ04.gif


(0m/s) 2 = (8.660) 2 + 2( “9.8m/s 2 ) D y

D y = 3.8263

Be careful; it's tempting to stop here. Keep in mind that you just calculated D y , which is the change in y . Did the cannonball leave from the ground? No, it was shot from the top of the cannon. If you look at the top of the screen, you see that the initial height (labeled Launch Pos_ y ) is 2.87m above the ground, so you need to add that to the change in y . Therefore, the maximum height should be 6.69m.

Press the spacebar and see what happens. The maximum height is reported at the top of the screen. Is it the same height you calculated? It should be. You might want to retry this process with a different angle and/or a different force for extra practice.

Notice that the Settings window appears at the completion of the launch. This time, put up a wall. In the Settings window, check the box next to Wall, and input the following three values for the wall:

Left: 5 m

Width: 1 m

Height: 20 m

Before launching player 1 again, calculate by hand how high the cannonball will be when it hits the wall. If you use the same settings as before (60 °, 50N, 1kg), the magnitude of the initial velocity should still be 10m/s. If the wall is at the 5m mark (3m away from the cannon), how high ( D y ) will the cannonball be after traveling 3m horizontally ( D x )? Again, don't forget to add the cannon's height.

After you calculate the answer, get ready to press the spacebar. Also get ready to press the P key quickly so that you can pause the motion and read the current height. Press the spacebar, and then try to pause the cannonball just as it hits the wall. What is its current height? Were you close?

When the Settings window appears, you can either leave the wall there or uncheck the box next to the wall to remove it. Now it's player 2's turn. Leave the cannon at 120 ° and the mass at 1kg, but use the up arrow to change the force to 200N. When you press the spacebar, the cannonball launches, and you can see at the top of the screen that this time the initial velocity is 20m/s.

The Settings window appears again. Create a new wall with the following dimensions:

Left: 25 m

Width: 1 m

Height: 15 m

Now it's player 1's turn. Let's keep the angle at 60 ° and the mass at 1kg. Use the up arrow to increase the force to 200N. Just like last time, the initial velocity should have a magnitude of 20m/s. With these settings, will the cannonball make it over the wall 23 meters away? Try to calculate the answer on paper first. Then press the spacebar to see if you are correct. The cannonball should clear!

What about the other side? Leave the wall exactly where it is. Make sure player 2 has an angle of 120 °, a force of 200N, and a mass of 1kg. This should give you an initial velocity of 20m/s. If the wall is 23 meters away from the cannon, will the cannonball clear the wall again? Try calculating an answer on paper first. Then press the spacebar to see if you are correct. The cannonball should clear again!

Here's a final challenge. With a force of 250N and a mass of 1kg, what angle allows you to hit the other cannon, which is approximately 46 meters away? See if you can figure it out on paper, and then use the program to see if you're correct!

 <  Day Day Up  >  


Beginning Math and Physics for Game Programmers
Beginning Math and Physics for Game Programmers
ISBN: 0735713901
EAN: 2147483647
Year: 2004
Pages: 143
Authors: Wendy Stahler

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net