Hardware Reference
In-Depth Information
If you want to deine the exact angle Θ (angles are always called theta ), you can apply the
formula shown in Figure 5-2. However, for this project there is no need to work in terms of
angles, basically because all relections are from orthogonal surfaces. his means that you are
considering only horizontal or vertical surfaces to relect from. Take a look at Figure 5-3;
here you see a block bouncing of, or being relected from, a vertical surface. he angle it is
relected at is equal to the incoming angle or incident angle. But the point is that you don't
have to know the actual angle - in fact, you don't care. All that you need to do is reverse the
sign of ∆X - that is, make it negative. he same goes if the block is approaching the relecting
surface from the other direction. ∆X will be negative in that case, and all you need to do is to
reverse the sign. If you make a negative number negative, you end up with a positive.
Figure 5-3:
he relection
from a vertical
surface by
negating ∆X.
I think you can see that exactly the same applies for relections of a horizontal surface - only
this time it is ∆Y that is negated. So when the time comes to bounce of a surface all that you
need to do is to invert the appropriate delta value.
Detecting Collisions
Now all you need to get some bouncy action is to work out when things collide. his is easy
for humans to spot but can be a bit tricky for a computer. Every object you draw on the
screen will be put there by specifying one or more coordinates. However, that describes only
one point on the object. Take a rectangle, for example: You specify the X and Y coordinates of
the top-left corner and the width and height, as well as the line thickness. When you draw a
line, you specify the X and Y coordinates of the start of the line, and the coordinates of where
Search WWH ::




Custom Search