00001
00002
00003 namespace NewGamePhysics.GraphicalElements
00004 {
00005 using System;
00006 using System.Collections.Generic;
00007 using System.Text;
00008
00009 using Microsoft.Xna.Framework;
00010 using Microsoft.Xna.Framework.Content;
00011 using Microsoft.Xna.Framework.Graphics;
00012 using Microsoft.Xna.Framework.Input;
00013
00014 using NewGamePhysics.StateManager;
00015 using NewGamePhysics.Mathematics;
00016 using NewGamePhysics.Physics;
00017 using NewGamePhysics.GraphicalElements;
00018 using NewGamePhysics.PhysicalElements;
00019 using NewGamePhysics.Utilities;
00020
00024 public class DoubleRegularPendulum : GraphicalElementBase
00025 {
00029 DoubleRegularPendulumSimulation pendulum;
00030
00034 Vector2 screenOrigin;
00035
00039 double screenScale;
00040
00044 private static Texture2D rivetTexture;
00045
00059 public DoubleRegularPendulum(
00060 ScreenManager screenManager,
00061 Vector2 simulationOrigin,
00062 double l1,
00063 double m1,
00064 double l2,
00065 double m2,
00066 double g,
00067 RotationalFrictionType f,
00068 Vector2 screenOrigin,
00069 double screenScale)
00070 : base(screenManager)
00071 {
00072
00073 this.pendulum = new DoubleRegularPendulumSimulation(simulationOrigin, l1, m1, l2, m2, g, f);
00074 this.screenOrigin = screenOrigin;
00075 this.screenScale = screenScale;
00076
00077
00078 if (this.ScreenManager.Textures.ContainsKey("rivet"))
00079 {
00080 rivetTexture = this.ScreenManager.Textures["rivet"];
00081 }
00082 }
00083
00087 public DoubleRegularPendulumSimulation Pendulum
00088 {
00089 get { return this.pendulum; }
00090 }
00091
00097 public void Draw(GameTime gameTime)
00098 {
00099
00100 Vector2[] pendulumPoints = this.pendulum.GetPosition(this.screenOrigin, this.screenScale);
00101 this.PrimitiveBatch.Begin(PrimitiveType.LineList);
00102 this.PrimitiveBatch.AddVertex(pendulumPoints[0], Color.White);
00103 this.PrimitiveBatch.AddVertex(pendulumPoints[1], Color.White);
00104 this.PrimitiveBatch.AddVertex(pendulumPoints[1], Color.White);
00105 this.PrimitiveBatch.AddVertex(pendulumPoints[2], Color.White);
00106 this.PrimitiveBatch.End();
00107
00108
00109 if (null != rivetTexture)
00110 {
00111
00112 Rectangle dest = new Rectangle(0, 0, 8, 8);
00113 this.SpriteBatch.Begin(SpriteBlendMode.AlphaBlend);
00114 dest.X = Convert.ToInt32(Math.Round(pendulumPoints[0].X)) - 4;
00115 dest.Y = Convert.ToInt32(Math.Round(pendulumPoints[0].Y)) - 4;
00116 this.SpriteBatch.Draw(rivetTexture, dest, Color.White);
00117 dest.X = Convert.ToInt32(Math.Round(pendulumPoints[1].X)) - 8;
00118 dest.Y = Convert.ToInt32(Math.Round(pendulumPoints[1].Y)) - 8;
00119 dest.Width = 16;
00120 dest.Height = 16;
00121 this.SpriteBatch.Draw(rivetTexture, dest, Color.White);
00122 dest.X = Convert.ToInt32(Math.Round(pendulumPoints[2].X)) - 8;
00123 dest.Y = Convert.ToInt32(Math.Round(pendulumPoints[2].Y)) - 8;
00124 this.SpriteBatch.Draw(rivetTexture, dest, Color.White);
00125 this.SpriteBatch.End();
00126 }
00127 }
00128 }
00129 }
00130