I'm working on making my first Pong game with XNA Framework 4.0. Right now i've put 2 pong paddles and a ball (they have separate classes). In the "Paddle" class i've made a function that returns a Vector2 list of the normals to its edges (i'm going to leave all 4 of them as i'm considering adding rotation and other things in the future).
Right now i'm trying to do my own implementation of the separating axis theorem. My question is: is there a more efficient method of computing the edges(or the normals to them), other than doing them by hand? Here's my code from the Paddle class:
public List<Vector2> NormalsToEdges()
{
Vector2 Edge = Vector2.Zero;
List<Vector2> lst = new List<Vector2>();
//take this normal because our reference axes have the origin in the top left corner
//upper edge
Edge = (this.paddlePosition + new Vector2(this.Width, 0)) - this.paddlePosition;
if (Edge != Vector2.Zero)
{
Edge.Normalize();
lst.Add(new Vector2(Edge.Y, -Edge.X));
}
//right edge
Edge = (this.paddlePosition + new Vector2(this.Width, this.Height)) - (this.paddlePosition + new Vector2(this.Width, 0));
if (Edge != Vector2.Zero)
{
Edge.Normalize();
lst.Add(new Vector2(Edge.Y, -Edge.X));
}
//bottom edge
Edge = (this.paddlePosition + new Vector2(0, this.Height)) - (this.paddlePosition + new Vector2(this.Width, this.Height));
if (Edge != Vector2.Zero)
{
Edge.Normalize();
lst.Add(new Vector2(Edge.Y, -Edge.X));
}
//left edge
Edge = this.paddlePosition - (this.paddlePosition + new Vector2(0, this.Height));
if (Edge != Vector2.Zero)
{
Edge.Normalize();
lst.Add(new Vector2(Edge.Y, -Edge.X));
}
return lst;
}
I don't know why but i have a feeling that i'm over-complicating things (considering that i have to update these edges on every update cycle in the main game). For example, if i decide to change the sprite to some convex irregular polygon with 50+ (or 500+) edges will the performance impact be high? (suppose i know all the vertex coordinates and/or that i can actually get the list of edge-vectors somehow, in CCW or CW order).
Second issue. Suppose i want to heighten one of the paddles under certain conditions in the game. I know i can use scaling for this (on Draw) and test the scale factor (like if it's 1.0f i use height/width of the original sprite, otherwise i make a new property that gives the scaled values), but is there a way to actually scale the sprite itself? (so that height/width/etc values will return the scaled versions). I'm asking this because i think it might save additional coding of properties, recalculation of rectangles etc.
All in all, i'm aiming for maximum efficiency.
Thanks