- Main Page
- Classes
- Files

- File List

# C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/NewGamePhysics/GraphicalElements/RotationalActionIndicator.cs

    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.Graphics;
    00011
    00012     using NewGamePhysics.StateManager;
    00013     using NewGamePhysics.Utilities;
    00014
    00019     public class RotationalActionIndicator
    00020     {
    00024         private ScreenManager screenManager;
    00025
    00029         private bool visible = false;
    00030
    00034         private const double actionRotationSpeed = 4.0;
    00035
    00039         private float actionIndicatorRotation;
    00040
    00044         private Vector2 center;
    00045
    00049         private float scale;
    00050
    00054         private Color drawColor = Color.Red;
    00055
    00059         public RotationalActionIndicator(ScreenManager screenManager)
    00060         {
    00061             this.screenManager = screenManager;
    00062             this.actionIndicatorRotation = 0.0f;
    00063             this.center = new Vector2();
    00064             this.scale = 20.0f;
    00065         }
    00066
    00071         public void SetPosition(Vector2 position)
    00072         {
    00073             this.center = position;
    00074         }
    00075
    00080         public void Animate(double intensity)
    00081         {
    00082             if (intensity == 0)
    00083             {
    00084                 this.visible = false;
    00085                 return;
    00086             }
    00087
    00088             this.visible = true;
    00089             this.actionIndicatorRotation += (float)(actionRotationSpeed * intensity);
    00090             this.actionIndicatorRotation = MathHelper.WrapAngle(this.actionIndicatorRotation);
    00091
    00092             if (intensity < 0.0)
    00093             {
    00094                 this.drawColor = Color.Red;
    00095             }
    00096             else
    00097             {
    00098                 this.drawColor = Color.Green;
    00099             }
    00100         }
    00101
    00106         public void Draw(GameTime gameTime)
    00107         {
    00108             if (visible)
    00109             {
    00110                 PrimitiveBatch primitiveBatch = screenManager.PrimitiveBatch;
    00111
    00112                 const int segments = 16;
    00113                 const double angle = MathHelper.TwoPi / segments;
    00114
    00115                 double curAngle = this.actionIndicatorRotation;
    00116                 primitiveBatch.Begin(PrimitiveType.LineList);
    00117                 for (int i = 0; i < segments; i++)
    00118                 {
    00119                     Vector2 point = this.center + new Vector2(
    00120                         this.scale * (float)Math.Round(Math.Sin(curAngle), 4),
    00121                         this.scale * (float)Math.Round(Math.Cos(curAngle), 4));
    00122                     primitiveBatch.AddVertex(point, this.drawColor);
    00123                     curAngle += angle;
    00124                 }
    00125
    00126                 primitiveBatch.End();
    00127             }
    00128         }
    00129     }
    00130 }