Hi Guys. I'm working on an n-player pong, in which I need to dynamically generate paddles for each player. I'm currently translating the coordinate system to the center (width/2, height/2), and basing all coordinates off of that origin (to make it more similar to a normal coordinate grid). Then, I generate coordinates for each of the end points based on the number of players, by rotating a radius around the origin. That portion works fine, and adds to an ArrayList with each of the points in the form of a PVector in that arraylist.
I then (attempt to) generate paddles.
Paddles are generated by using the same method I used to create endpoints, but providing a smaller radius (so each coordinate endpoint is inside the polygon generated by the boundaryGen function. So, here's the paddle class:
class Paddle {
PVector endPointA;
PVector endPointB;
PVector smallPosA;
PVector smallPosB;
PVector midpoint;
PVector slope;
Paddle(PVector point1, PVector point2, int rIndexI) {
endPointA = new PVector(point1.x, point1.y);
endPointB = new PVector(point2.x, point2.y);
slope = new PVector(endPointB.x - endPointA.x,endPointB.y - endPointA.y);
slope.setMag(1);
slope.mult(5);
midpoint = new PVector((endPointA.x + endPointB.x )/2, (endPointA.y + endPointB.y)/2);
smallPosA = midpoint;
smallPosB = midpoint;
smallPosA.add(slope);
smallPosB.add(slope);
}
void display(int i) {
line (smallPosA.x, smallPosA.y, smallPosB.x, smallPosB.y);
}
}
So, the paddle class had endPointA and endPointB which define the line that bounds the axis that the paddle can move around. Those points are passed from the paddle edge generation function, as defined above. If needed, I can post that as well.
So, then it defines a vector as a slope between those two points. That slope seems to work okay. A midpoint is then generated between the two endpoints, to which I figured I'd add or subtract the slope (multiplied by a width) to the midpoint, which should hopefully generate two points that are slightly away from the midpoint. The problem is, those points are somehow equal when the time to create the line comes around, and it becomes just a point (which is not what I want to happen). I've been gnawing at this for 5 hours and I still haven't been able to figure out what is wrong. I'd really appreciate any pointers.
Thanks,
Hades
EDIT: The main class is below:
ArrayList<PVector> bPoints = new ArrayList<PVector>(); //boundary Points arraylist
ArrayList<Paddle> paddles = new ArrayList<Paddle>();
final int numberOfSides = 8;
final int buffer = 8; //distance to keep away from the sides
final float innerBuffer = .95; //modifier for the distance the paddles are away from the boundary
final float pAngle = (180*(numberOfSides-2))/numberOfSides; //inner angle between the shape
final float innerAngle = 360/numberOfSides; //distance to rotate the coordinate system to generate each point