HTML and CSS Reference

In-Depth Information

Shooting the ball

We change the state of the ball from staic to dynamic before applying some force to it.

Forces only affect dynamic bodies.

Once we know any two points in the screen, we can calculate the rotaion angle. This is

done using the geometry formula. The following igure shows the relaionship between

the edges of the triangle and angles between them:

=y/r

=x/r

=y/x

sin

cos

tan

0

r

y

0

0

0

x

The calculated angle is correct only if it is in the first quadrant. We determine the quadrant

of the mouse cursor by referencing the ball's posiion as the original point. The following

figure shows the four quadrants:

quadrant 2

quadrant 1

cursor

ball position

quadrant 4

quadrant 3

According to math, we need to add addiional degrees to the calculated result if the cursor

is not in the first quadrant. The degrees to be added, depending on the quadrant, are shown

as follows:

F
Quadrant 1: Add 0

F
Quadrant 2 and 3: Add 180 (PI)

F
Quadrant 4: Add 360 (
PI * 2
)