Game Development Reference
In-Depth Information
// Convert the loft angle from degrees to radians and
// assign values to some convenience variables.
loft = loft*Math.PI/180.0;
double cosL = Math.cos(loft);
double sinL = Math.sin(loft);
// Calculate the pre-collision velocities normal
// and parallel to the line of action.
double vcp = cosL*velocity;
double vcn = -sinL*velocity;
// Compute the post-collision velocity of the ball
// along the line of action.
double vbp = (1.0+e)*clubMass*vcp/(clubMass+ballMass);
// Compute the post-collision velocity of the ball
// perpendicular to the line of action.
double vbn = (2.0/7.0)*clubMass*vcn/(clubMass+ballMass);
// Compute the initial spin rate assuming ball is
// rolling without sliding.
double omega = (5.0/7.0)*vcn/radius;
// Rotate post-collision ball velocities back into
// standard Cartesian frame of reference. Because the
// line of action was in the xy plane, the z-velocity
// is zero.
double vx0 = cosL*vbp - sinL*vbn;
double vy0 = 0.0;
double vz0 = sinL*vbp + cosL*vbn;
Once the initial translational and angular velocities have been determined, a GolfBall
object is created. The start method is called on a Timer object to start the simulation.
// Create a GolfBall object representing the golf ball.
golfball = new GolfBall(0.0, 0.0, 0.0, vx0, vy0, vz0,
0.0, ballMass, area, density, cd, windVx, windVy,
rx, ry, rz, omega, radius);
// Update the display.
updateDisplay();
// Start the box sliding using a Timer object
// to slow down the action.
gameTimer.start();
}
Search WWH ::




Custom Search