NewGamePhysics.GraphicalElements.DotPlotter Class Reference

A collection of 2D points which are plotted. More...

List of all members.

Public Member Functions

 DotPlotter (int count)
 Construct a new dotplotter.
void Draw (GameTime gameTime, PrimitiveBatch primitiveBatch)
 Render the plotter.
void MoveDots (Vector2 displacement)
 Move all dots by the given amount.
void AddDot (Vector2 targetPosition, Color color, int type)
 Add a dot to the plot.
void SetTypeAtHead (int type)
 Set the type of the point at the top of the stack.

Detailed Description

A collection of 2D points which are plotted.

Definition at line 13 of file DotPlotter.cs.


Constructor & Destructor Documentation

NewGamePhysics.GraphicalElements.DotPlotter.DotPlotter ( int  count  ) 

Construct a new dotplotter.

Parameters:
count The maximum number of dots in the plotter.

Definition at line 54 of file DotPlotter.cs.

00055         {
00056             if (count <= 0)
00057             {
00058                 throw new ArgumentOutOfRangeException("count");
00059             }
00060 
00061             // Keep size
00062             plotStackSize = count;
00063             pointsInStack = 0;
00064 
00065             // Pre-allocate
00066             plotPositions = new Vector2[plotStackSize];
00067             plotColors = new Color[plotStackSize];
00068             plotType = new int[plotStackSize];
00069             for (int i = 0; i < plotStackSize; i++)
00070             {
00071                 plotPositions[i] = new Vector2(0.0f, 0.0f);
00072                 plotColors[i] = new Color();
00073                 plotType[i] = 0;
00074             }
00075 
00076             // Empty stack
00077             headOfPositionStack = 0;
00078             tailOfPositionStack = 0;
00079         }


Member Function Documentation

void NewGamePhysics.GraphicalElements.DotPlotter.AddDot ( Vector2  targetPosition,
Color  color,
int  type 
)

Add a dot to the plot.

Parameters:
targetPosition The target position of the dot.
color The color of the dot.
type The emphasis type of the dot.

Definition at line 179 of file DotPlotter.cs.

00180         {
00181             // Store plot position and attributes
00182             plotPositions[headOfPositionStack].X = targetPosition.X;
00183             plotPositions[headOfPositionStack].Y = targetPosition.Y;
00184             plotColors[headOfPositionStack] = color;
00185             plotType[headOfPositionStack] = type;
00186 
00187             // Advance head to next empty slot
00188             headOfPositionStack++;
00189 
00190             // Maybe wrap head
00191             if (headOfPositionStack == plotStackSize)
00192             {
00193                 headOfPositionStack = 0;
00194             }
00195 
00196             // Maybe move tail
00197             if (headOfPositionStack == tailOfPositionStack)
00198             {
00199                 // Also advance tail
00200                 tailOfPositionStack++;
00201 
00202                 // Maybe wrap tail
00203                 if (tailOfPositionStack == plotStackSize)
00204                 {
00205                     tailOfPositionStack = 0;
00206                 }
00207             }
00208 
00209             // Count points
00210             if (pointsInStack < plotStackSize)
00211             {
00212                 pointsInStack++;
00213             }
00214         }

void NewGamePhysics.GraphicalElements.DotPlotter.Draw ( GameTime  gameTime,
PrimitiveBatch  primitiveBatch 
)

Render the plotter.

Parameters:
primitiveBatch The primitive batch to use for drawing the lines.
dotColor The color for the dots.

Definition at line 118 of file DotPlotter.cs.

00119         {
00120             if (primitiveBatch == null)
00121             {
00122                 throw new ArgumentNullException("primitiveBatch");
00123             }
00124 
00125             // Do we have enough points
00126             if (pointsInStack > 1)
00127             {
00128                 primitiveBatch.Begin(PrimitiveType.LineList);
00129                 if (headOfPositionStack > tailOfPositionStack)
00130                 {
00131                     for (int i = tailOfPositionStack; i < (headOfPositionStack - 1); i++)
00132                     {
00133                         DrawSegment(plotPositions[i], plotPositions[(i + 1) % plotStackSize],
00134                                     plotColors[i], plotType[i], primitiveBatch);
00135                     }
00136                 }
00137                 else if (headOfPositionStack < tailOfPositionStack)
00138                 {
00139                     for (int i = tailOfPositionStack; i < plotStackSize; i++)
00140                     {
00141                         DrawSegment(plotPositions[i], plotPositions[(i + 1) % plotStackSize],
00142                                     plotColors[i], plotType[i], primitiveBatch);
00143                     }
00144                     if (headOfPositionStack > 0)
00145                     {
00146                         for (int i = 0; i < (headOfPositionStack - 1); i++)
00147                         {
00148                             DrawSegment(plotPositions[i], plotPositions[(i + 1) % plotStackSize],
00149                                         plotColors[i], plotType[i], primitiveBatch);
00150                         }
00151                     }
00152                 }
00153                 else
00154                 {
00155                     // if head==tail there is nothing to do
00156                 }
00157                 primitiveBatch.End();
00158             }
00159         }

void NewGamePhysics.GraphicalElements.DotPlotter.MoveDots ( Vector2  displacement  ) 

Move all dots by the given amount.

Parameters:
displacement 

Definition at line 165 of file DotPlotter.cs.

00166         {
00167             for (int i=0; i<plotStackSize; i++) 
00168             {
00169                 plotPositions[i] += displacement;
00170             }
00171         }

void NewGamePhysics.GraphicalElements.DotPlotter.SetTypeAtHead ( int  type  ) 

Set the type of the point at the top of the stack.

Parameters:
type The emphasis type of the dot.

Definition at line 220 of file DotPlotter.cs.

00221         {
00222             // Do we have points?
00223             if (pointsInStack > 0)
00224             {
00225                 if (headOfPositionStack > 0)
00226                 {
00227                     // Previous position is last point added.
00228                     plotType[headOfPositionStack - 1] = type;
00229                 }
00230                 else
00231                 {
00232                     // Last element in stack is the last point added.
00233                     plotType[plotStackSize - 1] = type;
00234                 }
00235             }
00236         }


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

Generated by  doxygen 1.6.2