NewGamePhysics.GraphicalElements.DoubleSquarePendulum Class Reference

Animated and drawable double square pendulum. More...

Inheritance diagram for NewGamePhysics.GraphicalElements.DoubleSquarePendulum:
NewGamePhysics.GraphicalElements.GraphicalElementBase

List of all members.

Public Member Functions

 DoubleSquarePendulum (ScreenManager screenManager, Vector2 simulationOrigin, double l, double m, double g, RotationalFrictionType f, Vector2 screenOrigin, double screenScale)
 Create an animated double square pendulum.
void Draw (GameTime gameTime)
 Draws the double square pendulum.

Properties

DoubleSquarePendulumSimulation Pendulum [get]
 Gets the pendulum simulation.

Detailed Description

Animated and drawable double square pendulum.

Definition at line 23 of file DoubleSquarePendulum.cs.


Constructor & Destructor Documentation

NewGamePhysics.GraphicalElements.DoubleSquarePendulum.DoubleSquarePendulum ( ScreenManager  screenManager,
Vector2  simulationOrigin,
double  l,
double  m,
double  g,
RotationalFrictionType  f,
Vector2  screenOrigin,
double  screenScale 
)

Create an animated double square pendulum.

Parameters:
simulationOrigin The origin for pendulum in simulation space.
l The length of the side of each square in simulation space.
m The mass of each square.
g The gravitational acceleration to apply.
f The friction model to use for the hinges.
screenOrigin The origin for mapping simulation space to the screen.
screenScale The scale for mapping simulation space to the screen.

Definition at line 60 of file DoubleSquarePendulum.cs.

00069             : base(screenManager)
00070         {
00071             // Create pendulum simulation
00072             this.pendulum = new DoubleSquarePendulumSimulation(simulationOrigin, l, m, g, f);
00073             this.screenOrigin = screenOrigin;
00074             this.screenScale = screenScale;
00075 
00076             // Prepare textures
00077             if (this.ScreenManager.Textures.ContainsKey("rivet"))
00078             {
00079                 rivetTexture = this.ScreenManager.Textures["rivet"];
00080             }
00081 
00082             if (this.ScreenManager.Textures.ContainsKey("metal"))
00083             {
00084                 blockTexture = this.ScreenManager.Textures["metal"];
00085             }
00086 
00087         }


Member Function Documentation

void NewGamePhysics.GraphicalElements.DoubleSquarePendulum.Draw ( GameTime  gameTime  ) 

Draws the double square pendulum.

Parameters:
gameTime Current game time.

Definition at line 101 of file DoubleSquarePendulum.cs.

00102         {
00103             // Get physical state of pendulum
00104             double[] pendulumSizes = this.pendulum.GetSize(this.screenScale);
00105             double[] pendulumAngles = this.pendulum.GetAngle();
00106             Vector2[] pendulumPoints = this.pendulum.GetPosition(this.screenOrigin, this.screenScale);
00107 
00108             // Temp var
00109             Rectangle dest = new Rectangle();
00110 
00111             // Draw top box
00112             if (null != blockTexture)
00113             {
00114                 this.SpriteBatch.Begin(SpriteBlendMode.AlphaBlend);
00115                 dest = new Rectangle();
00116                 dest.X = Convert.ToInt32(Math.Round(pendulumPoints[0].X));
00117                 dest.Y = Convert.ToInt32(Math.Round(pendulumPoints[0].Y));
00118                 dest.Width = (int)pendulumSizes[0];
00119                 dest.Height = dest.Width;
00120                 this.SpriteBatch.Draw(
00121                     blockTexture,
00122                     dest,
00123                     null,
00124                     Color.White,
00125                     (float)(Math.PI / 4 - pendulumAngles[0]),
00126                     new Vector2(),
00127                     SpriteEffects.None,
00128                     (float)0.0);
00129                 this.SpriteBatch.End();
00130             }
00131 
00132             // Draw top frame
00133             this.PrimitiveBatch.Begin(PrimitiveType.LineList);
00134             this.PrimitiveBatch.AddVertex(pendulumPoints[0], Color.Black);
00135             this.PrimitiveBatch.AddVertex(pendulumPoints[1], Color.Black);
00136             this.PrimitiveBatch.AddVertex(pendulumPoints[1], Color.Black);
00137             this.PrimitiveBatch.AddVertex(pendulumPoints[2], Color.Black);
00138             this.PrimitiveBatch.AddVertex(pendulumPoints[2], Color.Black);
00139             this.PrimitiveBatch.AddVertex(pendulumPoints[3], Color.Black);
00140             this.PrimitiveBatch.AddVertex(pendulumPoints[3], Color.Black);
00141             this.PrimitiveBatch.AddVertex(pendulumPoints[0], Color.Black);
00142             this.PrimitiveBatch.End();
00143 
00144             // Draw top rivet
00145             if (null != rivetTexture)
00146             {
00147                 this.SpriteBatch.Begin(SpriteBlendMode.AlphaBlend);
00148                 dest.X -= 4;
00149                 dest.Y -= 4;
00150                 dest.Width = 8;
00151                 dest.Height = 8;
00152                 this.SpriteBatch.Draw(
00153                     rivetTexture,
00154                     dest,
00155                     Color.White);
00156                 this.SpriteBatch.End();
00157             }
00158 
00159             // Draw bottom box
00160             if (null != blockTexture)
00161             {
00162                 this.SpriteBatch.Begin(SpriteBlendMode.AlphaBlend);
00163                 dest.X = Convert.ToInt32(Math.Round(pendulumPoints[4].X));
00164                 dest.Y = Convert.ToInt32(Math.Round(pendulumPoints[4].Y));
00165                 dest.Width = (int)pendulumSizes[1];
00166                 dest.Height = dest.Width;
00167                 this.SpriteBatch.Draw(
00168                     blockTexture,
00169                     dest,
00170                     null,
00171                     Color.White,
00172                     (float)(Math.PI / 4 - pendulumAngles[1]),
00173                     new Vector2(),
00174                     SpriteEffects.None,
00175                     (float)0.0);
00176                 this.SpriteBatch.End();
00177             }
00178 
00179             // Draw bottom frame
00180             this.PrimitiveBatch.Begin(PrimitiveType.LineList);
00181             this.PrimitiveBatch.AddVertex(pendulumPoints[4], Color.Black);
00182             this.PrimitiveBatch.AddVertex(pendulumPoints[5], Color.Black);
00183             this.PrimitiveBatch.AddVertex(pendulumPoints[5], Color.Black);
00184             this.PrimitiveBatch.AddVertex(pendulumPoints[6], Color.Black);
00185             this.PrimitiveBatch.AddVertex(pendulumPoints[6], Color.Black);
00186             this.PrimitiveBatch.AddVertex(pendulumPoints[7], Color.Black);
00187             this.PrimitiveBatch.AddVertex(pendulumPoints[7], Color.Black);
00188             this.PrimitiveBatch.AddVertex(pendulumPoints[4], Color.Black);
00189             this.PrimitiveBatch.End();
00190 
00191             // Draw bottom rivet
00192             if (null != rivetTexture)
00193             {
00194                 this.SpriteBatch.Begin(SpriteBlendMode.AlphaBlend);
00195                 dest.X -= 4;
00196                 dest.Y -= 4;
00197                 dest.Width = 8;
00198                 dest.Height = 8;
00199                 this.SpriteBatch.Draw(
00200                     rivetTexture,
00201                     dest,
00202                     Color.White);
00203                 this.SpriteBatch.End();
00204             }
00205         }


Property Documentation

DoubleSquarePendulumSimulation NewGamePhysics.GraphicalElements.DoubleSquarePendulum.Pendulum [get]

Gets the pendulum simulation.

Definition at line 93 of file DoubleSquarePendulum.cs.


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

Generated by  doxygen 1.6.2