Tricks of the Windows Game Programming Gurus:Playing God: Basic Physics Modeling

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

### Resolving the n-t Coordinate System

Now that we have the final collision response, we need to figure out how to get the initial values for (vai)n, (vai)t, (vbi)n, (vbi)t and then when the problem is solved we have to convert the values in the n-t axes back into values in the x,y axes. Let’s begin by first finding the vectors n and t.

To find n we want a vector that is unit length (length equal to 1.0) and along the line from the center of ball A(xa0,ya0) to the center of ball B(xb0,yb0). Let’s begin by finding a vector from ball A to B, calling it N, and then normalizing it:

Equation 8: Computation of n and t

    N = B – A = <xb0 – xa0, yb0 – ya0>

Normalizing N to find n, we get

    n = N/|N| = <nx,ny>

Now we need the tangential axis t which is perpendicular to n. We could find it again using vector geometry, but there’s a trick we can use; if we rotate n 90 degrees clockwise, that’s what we want. However, when a 2D vector <x,y> is rotated in a plane 90 degrees clockwise, the rotated vector is just t=<-y, x>=<tx, ty>. Take a look at Figure 13.35.

Figure 13.35 Rotating a vector 90 degrees to find its perpendicular.

Now that we have both n and t and they are both unit vectors (since n was unit, t is unit also) we’re ready to go. We want to resolve the initial velocities of each ball into terms of n and t for ball A and B, respectively:

    vai=<xvai, yvai>

    vbi=<xvbi, yvbi>

This is nothing more than a dot product. To find (vai)n, the component of the initial velocity of ball A along axis n, here’s what you do:

    (vai)n = vai . n = <xvai, yvai> . <nx,ny>

           = (xvai*nx + yvai* ny).

Note the result is a scalar, as it should be. Computing the other initial velocities is the same as shown in Equation 9.

Equation 9: Components of vai along n and t:

    (vai)n = vai . n = <xvai, yvai> . <nx,ny>

           = (xvai*nx + yvai* ny)

    (vai)t = vai . t = <xvai, yvai> . <tx,ty>

           = (xvai*tx + yvai* ty)

Components of vbi along n and t:

     (vbi)n = vbi . n = <xvbi, yvbi> . <nx,ny>

           = (xvbi*nx + yvbi* ny)

    (vbi)t = vbi . t = <xvbi, yvbi> . <tx,ty>

           = (xvbi*tx + yvbi* ty)

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.