NewGamePhysics.GraphicalElements.GravitySelector Class Reference

Represents a 3D animated gravity selector for XNA. More...

List of all members.

Public Member Functions

 GravitySelector (ScreenManager manager, CelestialObject celestialObject, GravityCalculator gravityCalculator)
 Constructor of the AnimatedGravitySelector instance.
void Update (GameTime gameTime)
 Update the game state.
void Draw (GameTime gameTime)
 Draw the animated gravity selector (sphere, value indicators, cross-hair).

Properties

double Gravity [get]
 Gets the current selected gravity value.
float DisplaySize [get, set]
 Gets or sets the current display size. 2 zoomed, 1 fully visible, 0 invisible;.
double Latitude [get, set]
 Gets or sets the currently shown latitude. Maintains value range of [-90,90].
double Longitude [get, set]
 Gets or sets the currently shown longitude. Maintains value range of [0,360].

Detailed Description

Represents a 3D animated gravity selector for XNA.

Definition at line 24 of file GravitySelector.cs.


Constructor & Destructor Documentation

NewGamePhysics.GraphicalElements.GravitySelector.GravitySelector ( ScreenManager  manager,
CelestialObject  celestialObject,
GravityCalculator  gravityCalculator 
)

Constructor of the AnimatedGravitySelector instance.

Parameters:
manager The screen manager to use.
celestialObject The celestial object to show and use for the selection.
gravityCalculator The gravity calculator to use for determining the gravity.

Definition at line 162 of file GravitySelector.cs.

00166         {
00167             // Keep reference to screen manager for drawing
00168             this.screenManager = manager;
00169 
00170             // Initialize body
00171             this.celestialBody = new CelestialBody(celestialObject);
00172 
00173             // Load texture (default variation)
00174             this.surfaceTexture = screenManager.Game.Content.Load<Texture2D>(
00175                 this.celestialBody.GetTextureName(0));
00176 
00177             // Initialize gravity calculator and value
00178             this.gravityCalculator = gravityCalculator;
00179             this.gravity = this.gravityCalculator.Value;
00180 
00181             // Create textured sphere object
00182             this.planetSphere = new TexturedSphere(
00183                 screenManager.GraphicsDevice, 
00184                 36, 
00185                 36, 
00186                 1.0f, 
00187                 this.surfaceTexture);
00188 
00189             // Center of screen
00190             this.screenCenter = new Vector2(
00191                 (float)(screenManager.GraphicsDevice.Viewport.Width / 2),
00192                 (float)(screenManager.GraphicsDevice.Viewport.Height / 2));
00193 
00194             // Aspect ratio of screen
00195             float aspectRatio = 
00196                 (float)screenManager.GraphicsDevice.Viewport.Width /
00197                 (float)screenManager.GraphicsDevice.Viewport.Height;
00198 
00199             // Set projection matrix for view
00200             this.projectionMatrix = Matrix.CreatePerspectiveFieldOfView(
00201                 0.1f * MathHelper.PiOver4, 
00202                 aspectRatio, 
00203                 5.0f, 
00204                 10000.0f);
00205 
00206             // Create a view matrix for the camera
00207             this.displaySize = 1.0f;
00208             UpdateViewMatrix();
00209 
00210             // Reset values
00211             this.latitude = 0.0;
00212             this.longitude = 0.0;
00213 
00214             // Create indicators and set initial value which will autoset ranges
00215             this.latitudeIndicator = new ValueIndicator(
00216                 this.screenManager, "Latitude", "{0,20:####.##} deg", -90.0, 90.0);
00217             this.latitudeIndicator.SetPosition(new Vector2(20.0f, 20.0f));
00218             this.latitudeIndicator.SetValueInRange(this.latitude);
00219 
00220             this.longitudeIndicator = new ValueIndicator(
00221                 this.screenManager, "Longitude", "{0,20:####.##} deg", 0.0, 360.0);
00222             this.longitudeIndicator.SetPosition(new Vector2(20.0f, 80.0f));
00223             this.longitudeIndicator.LowHighColoring = false;
00224             this.longitudeIndicator.SetValueInRange(this.longitude);
00225 
00226             this.gravityIndicator = new ValueIndicator(
00227                 this.screenManager, "Gravity", "{0,20:###.######} N");
00228             this.gravityIndicator.SetPosition(new Vector2((float)screenManager.GraphicsDevice.Viewport.Width - 20.0f - ValueIndicator.Width, 20.0f));
00229             this.latitudeIndicator.LowHighColoring = false;
00230             this.gravityIndicator.SetValue(this.gravity);
00231 
00232             // Load fonts
00233             this.screenManager.AddFont("retro", "Fonts/retroMedium");
00234 
00235             // Create scrollers
00236             SpriteFont font = this.screenManager.Fonts["game"];
00237             int width = this.screenManager.GraphicsDevice.Viewport.Width;
00238             int yPos = this.screenManager.GraphicsDevice.Viewport.Height - 32;
00239             string infoText =
00240                 "Model Info: " +
00241                 gravityCalculator.GetModelInfo() +
00242                 " --- Texture Info: " +
00243                 celestialBody.GetTextureInfo() +
00244                 "  ";
00245             infoText = infoText.Replace("\n", "  *  ");
00246             scrollingInfoText = new ScrollingText(infoText, font, width, yPos);
00247             scrollingInfoText.TextScale = 0.5f;
00248 
00249             // Set draw color
00250             this.drawColor = new Color(1.0f, 0.25f, 0.25f);
00251         }


Member Function Documentation

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

Draw the animated gravity selector (sphere, value indicators, cross-hair).

Parameters:
gameTime Current game time.

Definition at line 337 of file GravitySelector.cs.

00338         {
00339             // Earth is rotated by longitude and latitude
00340             Matrix sphereRollingMatrix = Matrix.CreateRotationY((float)(this.longitude * Math.PI / 180.0))
00341                                        * Matrix.CreateRotationX((float)(this.latitude * Math.PI / 180.0));
00342             planetSphere.Render(
00343                 this.screenManager.GraphicsDevice,
00344                 this.viewMatrix, 
00345                 this.projectionMatrix, 
00346                 sphereRollingMatrix,
00347                 this.DisplaySize);
00348 
00349             // Overlay cross-hair
00350             PrimitiveBatch primitiveBatch = screenManager.PrimitiveBatch;
00351             float offset = (float)Math.Abs(Math.Sin(Math.PI * gameTime.TotalRealTime.TotalSeconds));
00352             offset = 4.0f * MathHelper.SmoothStep(0.0f, 1.0f, offset);
00353             float max_size = 12.0f + offset;
00354             float min_size =  1.0f + offset;
00355 
00356             // Lines
00357             primitiveBatch.Begin(PrimitiveType.LineList);
00358 
00359             primitiveBatch.AddVertex(screenCenter + new Vector2( max_size, 0.0f), this.drawColor);
00360             primitiveBatch.AddVertex(screenCenter + new Vector2( min_size, 0.0f), this.drawColor);
00361 
00362             primitiveBatch.AddVertex(screenCenter + new Vector2(-max_size, 0.0f), this.drawColor);
00363             primitiveBatch.AddVertex(screenCenter + new Vector2(-min_size, 0.0f), this.drawColor);
00364 
00365             primitiveBatch.AddVertex(screenCenter + new Vector2(0.0f,  max_size), this.drawColor);
00366             primitiveBatch.AddVertex(screenCenter + new Vector2(0.0f,  min_size), this.drawColor);
00367 
00368             primitiveBatch.AddVertex(screenCenter + new Vector2(0.0f, -max_size), this.drawColor);
00369             primitiveBatch.AddVertex(screenCenter + new Vector2(0.0f, -min_size), this.drawColor);
00370 
00371             primitiveBatch.End();
00372 
00373             // Draw indicators and scroller
00374             if (this.displaySize > 0.99f)
00375             {
00376                 longitudeIndicator.Draw(gameTime);
00377                 latitudeIndicator.Draw(gameTime);
00378                 gravityIndicator.Draw(gameTime);
00379 
00380                 SpriteBatch spriteBatch = this.screenManager.SpriteBatch;
00381                 scrollingInfoText.Draw(gameTime, spriteBatch);
00382             }
00383         }

void NewGamePhysics.GraphicalElements.GravitySelector.Update ( GameTime  gameTime  ) 

Update the game state.

Definition at line 328 of file GravitySelector.cs.

00329         {
00330             scrollingInfoText.Update(gameTime);
00331         }


Property Documentation

float NewGamePhysics.GraphicalElements.GravitySelector.DisplaySize [get, set]

Gets or sets the current display size. 2 zoomed, 1 fully visible, 0 invisible;.

Definition at line 135 of file GravitySelector.cs.

double NewGamePhysics.GraphicalElements.GravitySelector.Gravity [get]

Gets the current selected gravity value.

Definition at line 126 of file GravitySelector.cs.

double NewGamePhysics.GraphicalElements.GravitySelector.Latitude [get, set]

Gets or sets the currently shown latitude. Maintains value range of [-90,90].

Definition at line 258 of file GravitySelector.cs.

double NewGamePhysics.GraphicalElements.GravitySelector.Longitude [get, set]

Gets or sets the currently shown longitude. Maintains value range of [0,360].

Definition at line 294 of file GravitySelector.cs.


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

Generated by  doxygen 1.6.2