21 List<Vector2f>
points =
new ArrayList<Vector2f>();
22 SlipstreamSegment prev =
null;
23 float unitsPerNormals = 2000f;
24 float distSoFar = unitsPerNormals;
26 for (
int i = 0; i < segments.size(); i++) {
27 SlipstreamSegment seg = segments.get(i);
28 if (distSoFar >= unitsPerNormals || i == segments.size() - 1) {
29 distSoFar -= unitsPerNormals;
30 Vector2f n1 =
new Vector2f(seg.loc);
31 Vector2f n2 =
new Vector2f(seg.loc);
32 n1.x += seg.normal.x * seg.width * 0.5f;
33 n1.y += seg.normal.y * seg.width * 0.5f;
34 n2.x -= seg.normal.x * seg.width * 0.5f;
35 n2.y -= seg.normal.y * seg.width * 0.5f;
39 points.add(
new Vector2f(seg.loc));
41 if (seg.width * 0.5f >
padding) {
45 distSoFar += Misc.getDistance(seg.loc, prev.loc);
118 float minArea = Float.MAX_VALUE;
119 float [] best =
null;
120 float bestAngle = 0f;
127 Vector2f edge = Vector2f.sub(p2, p1,
new Vector2f());
128 edge = Misc.normalise(edge);
130 float angle = (float) Math.acos(edge.y) * Misc.DEG_PER_RAD;
134 if (area < minArea) {
151 Vector2f p1 =
new Vector2f(best[0], best[1]);
152 Vector2f p2 =
new Vector2f(best[2], best[1]);
153 Vector2f p3 =
new Vector2f(best[2], best[3]);
154 Vector2f p4 =
new Vector2f(best[0], best[3]);
155 box =
new ArrayList<Vector2f>();
162 this.angle = bestAngle;
191 this.points =
new ArrayList<Vector2f>(
points);
199 float minY = Float.MAX_VALUE;
200 for (Vector2f p :
points) {
206 final Map<Vector2f, Float> angles =
new HashMap<Vector2f, Float>();
207 for (Vector2f p :
points) {
208 if (p == p1)
continue;
209 float angle = Misc.getAngleInDegreesStrict(p1, p);
211 angles.put(p,
angle);
214 List<Vector2f> sorted =
new ArrayList<Vector2f>(
points);
216 Collections.sort(sorted,
new Comparator<Vector2f>() {
217 public int compare(Vector2f o1, Vector2f o2) {
218 float diff = angles.get(o1) - angles.get(o2);
219 if (diff < 0)
return -1;
220 if (diff > 0)
return 1;
227 for (Vector2f p : sorted) {
262 GL11.glDisable(GL11.GL_TEXTURE_2D);
263 GL11.glEnable(GL11.GL_BLEND);
264 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
266 GL11.glEnable(GL11.GL_POINT_SMOOTH);
267 GL11.glPointSize(10f);
268 GL11.glBegin(GL11.GL_POINTS);
269 Misc.setColor(Color.yellow);
271 for (Vector2f p :
points) {
272 GL11.glVertex2f(p.x, p.y);
277 Misc.setColor(Color.white);
278 GL11.glEnable(GL11.GL_LINE_SMOOTH);
279 GL11.glLineWidth(3f);
280 GL11.glBegin(GL11.GL_LINE_LOOP);
283 GL11.glVertex2f(p.x, p.y);
288 Misc.setColor(Color.cyan);
289 GL11.glEnable(GL11.GL_LINE_SMOOTH);
290 GL11.glLineWidth(3f);
291 GL11.glBegin(GL11.GL_LINE_LOOP);
293 for (Vector2f p :
box) {
294 GL11.glVertex2f(p.x, p.y);