NewGamePhysics.PhysicalElements.CircularObjectSimulation Class Reference

Represents a moving circular object in 2D space under gravity influence. More...

List of all members.

Public Member Functions

 CircularObjectSimulation (double objectDiameter, double objectDensity, double gravity, double atmosphereDensity)
 Constructor for animated circular object.
void InitialConditionsAtRest ()
 Resets the initial conditions (position and velocity) for the object to be at rest.
void SetInitialConditions (double x, double y, double vx, double vy)
 Sets the initial conditions (position and speed) for the the object simulation.
void Animate ()
 Animate the circular object.
void Drive (Vector2 force)
 Drive ball by force transfer, changing its speed.
void SetPosition (Vector2 position)
 Set the ball positions to a point. Resets speed to zero.
void SetPosition (Vector2 position, double scale)
 Set the ball positions to a point which is at a particular scale.
Vector2 GetPosition ()
 Get object positions.
Vector2 GetPosition (double scale)
 Get object positions relative to a particular scale.

Detailed Description

Represents a moving circular object in 2D space under gravity influence.

Definition at line 20 of file CircularObjectSimulation.cs.


Constructor & Destructor Documentation

NewGamePhysics.PhysicalElements.CircularObjectSimulation.CircularObjectSimulation ( double  objectDiameter,
double  objectDensity,
double  gravity,
double  atmosphereDensity 
)

Constructor for animated circular object.

Parameters:
objectDiameter Object (ball) diameter
objectDensity Object (ball) material density
gravity Acceleration due to gravity
atmosphereDensity The density of the atmosphere

Definition at line 80 of file CircularObjectSimulation.cs.

00081         {
00082             // Time and stepsize
00083             t = 0;
00084             h = 0.01;
00085 
00086             // Drag coefficient (cD)
00087             double dragSphere = DragCoefficient.Sphere;
00088 
00089             // Ball mass = density * volume
00090             this.mass = objectDensity * Volume.Sphere(objectDiameter / 2.0);
00091 
00092             // Ball acceleration
00093             this.circularObjectAcceleration =
00094                 new CircularObjectAcceleration(objectDiameter, objectDensity, dragSphere, -gravity, atmosphereDensity);
00095 
00096             // Reset state
00097             this.p = new VectorN(2);
00098             this.v = new VectorN(2);
00099 
00100             // Create integrator
00101             this.circularObjectIntegrator = new NystromIntegrator(
00102                 (ISecondDerivative)this.circularObjectAcceleration, 
00103                 this.h, 
00104                 this.p, 
00105                 this.v);
00106             this.integratorNeedsReset = false;
00107 
00108             // Allocate physical state variables as cache
00109             circularObjectPosition = new Vector2();
00110         }


Member Function Documentation

void NewGamePhysics.PhysicalElements.CircularObjectSimulation.Animate (  ) 

Animate the circular object.

Definition at line 144 of file CircularObjectSimulation.cs.

00145         {
00146             // Check if integrator needs to be reset
00147             if (this.integratorNeedsReset)
00148             {
00149                 this.acceleration = circularObjectIntegrator.Reset(this.p, this.v);
00150             }
00151 
00152             // Animate ball
00153             // double t; VectorN p, v, acceleration;
00154             circularObjectIntegrator.Step(out t, out p, out v, out acceleration);
00155         }

void NewGamePhysics.PhysicalElements.CircularObjectSimulation.Drive ( Vector2  force  ) 

Drive ball by force transfer, changing its speed.

Parameters:
force The force to apply to the object.

Definition at line 161 of file CircularObjectSimulation.cs.

00162         {
00163             v[0] = this.h * force.X * this.mass;
00164             v[1] = this.h * force.Y * this.mass;
00165         }

Vector2 NewGamePhysics.PhysicalElements.CircularObjectSimulation.GetPosition ( double  scale  ) 

Get object positions relative to a particular scale.

Parameters:
scale The scale of the ball (pixels/meter).
Returns:
The scaled position.

Definition at line 220 of file CircularObjectSimulation.cs.

00221         {
00222             // Set position
00223             circularObjectPosition.X = (float)(scale * p[0]);
00224             circularObjectPosition.Y = (float)(scale * p[1]);
00225 
00226             return circularObjectPosition;
00227         }

Vector2 NewGamePhysics.PhysicalElements.CircularObjectSimulation.GetPosition (  ) 

Get object positions.

Returns:
The position.

Definition at line 206 of file CircularObjectSimulation.cs.

00207         {
00208             // Set position
00209             circularObjectPosition.X = (float)(p[0]);
00210             circularObjectPosition.Y = (float)(p[1]);
00211 
00212             return circularObjectPosition;
00213         }

void NewGamePhysics.PhysicalElements.CircularObjectSimulation.InitialConditionsAtRest (  ) 

Resets the initial conditions (position and velocity) for the object to be at rest.

Definition at line 116 of file CircularObjectSimulation.cs.

00117         {
00118             SetInitialConditions(0.0, 0.0, 0.0, 0.0);
00119         }

void NewGamePhysics.PhysicalElements.CircularObjectSimulation.SetInitialConditions ( double  x,
double  y,
double  vx,
double  vy 
)

Sets the initial conditions (position and speed) for the the object simulation.

Parameters:
x The x coordinate of the object.
y The y coordinate of the object.
vx The x component of the objects speed.
vy The y component of hte objects speed.

Definition at line 129 of file CircularObjectSimulation.cs.

00130         {
00131             // Store values
00132             this.p[0] = x;
00133             this.p[1] = y;
00134             this.v[0] = vx;
00135             this.v[1] = vy;
00136 
00137             // Mark for integrator to require a reset
00138             this.integratorNeedsReset = true;
00139         }

void NewGamePhysics.PhysicalElements.CircularObjectSimulation.SetPosition ( Vector2  position,
double  scale 
)

Set the ball positions to a point which is at a particular scale.

Parameters:
position Scaled position where to place the ball.
scale The scale of the ball (pixels/meter).

Definition at line 188 of file CircularObjectSimulation.cs.

00189         {
00190             // Set position
00191             if (scale != 0.0)
00192             {
00193                 p[0] = position.X / scale;
00194                 p[1] = position.Y / scale;
00195             }
00196 
00197             // Reset speed
00198             v[0] = 0.0f;
00199             v[1] = 0.0f;
00200         }

void NewGamePhysics.PhysicalElements.CircularObjectSimulation.SetPosition ( Vector2  position  ) 

Set the ball positions to a point. Resets speed to zero.

Parameters:
position Position where to place the ball.

Definition at line 172 of file CircularObjectSimulation.cs.

00173         {
00174             // Set position
00175             p[0] = position.X;
00176             p[1] = position.Y;
00177 
00178             // Reset speed
00179             v[0] = 0.0f;
00180             v[1] = 0.0f;
00181         }


The documentation for this class was generated from the following file:

Generated by  doxygen 1.6.2