John (for Martin),

This routine is in C, but this is the basic logic
that is used in many, many Nintendo, Sega and Sony
golf games:

// ----------------------------------------------------------------------
// given an incomming direction vector and a normal for a surface that
// the incomming direction vector wants to bounce off of... this
// calculates the direction vector for the bounce.
// ----------------------------------------------------------------------
void CalcReflectionDir( FVECTOR *inDir, FVECTOR *normal, FVECTOR *outDir )
{
  float inDotNormal;

  inDotNormal = (float)fabs( DOT_VECTOR( inDir, normal ) );
  
  outDir->vx = (inDir->vx / inDotNormal) + (2.0f * normal->vx);
  outDir->vy = (inDir->vy / inDotNormal) + (2.0f * normal->vy);
  outDir->vz = (inDir->vz / inDotNormal) + (2.0f * normal->vz);
  NormalFVector( outDir );
}

Where an FVECTOR is an structure of three floats: { vx, vy, vz },
fabs() is floating point absolute value, DOT_VECTOR() is a dot
product, and NormalFVector() normalized the passed FVECTOR.

The "inDir" is the direction, normalized, that the ball is traveling
when it hits ANY surface, and the "normal" is a normalized vector
that represents the surface normal at the location of impact.

Pretty simple really. It's also the same logic used in ray tracers
for how a light ray bounces off a shiny surface.

Note that this logic is used in conjunction with some gravity logic
to give the ball a nice arc as it travels. 

-Blake
former team programmer of Tiger Woods 99 PSX.


> -----Original Message-----
> From: John Kanding [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, October 18, 2000 2:07 AM
> To: [EMAIL PROTECTED]
> Subject: <lingo-l> bouncing a ball off a curve
> 
> 
> hey all !
> 
> We're working on a minigolf game and are discussion the best 
> implementation of the ball's bouncing behavior. The retangle 
> objects are easy, but the curves are a different story. Does 
> anyone have any experience the wish to share with us and the 
> rest of the list on this topic. If the ball e.g. hits on top 
> of the curve it should follow the path round it. Are we into 
> hardcoding some path's????
> 
> 
> regards
> 
> (John) on behalf of martin
> 
> 
> 
> [To remove yourself from this list, or to change to digest mode, go to
> http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
> email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
> Lingo-L is for learning and helping with programming Lingo.  Thanks!]
> 

[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi  To post messages to the list,
email [EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo.  Thanks!]

Reply via email to