diff options
Diffstat (limited to 'src/RaceTrack.java')
-rw-r--r-- | src/RaceTrack.java | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/RaceTrack.java b/src/RaceTrack.java index 69d45ed..012047a 100644 --- a/src/RaceTrack.java +++ b/src/RaceTrack.java @@ -1,4 +1,5 @@ +import java.awt.Color; import robotrace.Vector; import static java.lang.Math.*; import static javax.media.opengl.GL2.*; @@ -80,6 +81,16 @@ class RaceTrack extends BetterBase { } /** + * Returns the position of the curve at 0 <= {@code t} <= 1 and + * 1 <= laneNo <= (number of robots). + */ + public Vector getPointForLane(double t, double laneNo) { + Vector p = getPoint(t); + Vector lanes_len = new Vector(p.x(), p.y(), 0).normalized().scale(4); + return p.add(lanes_len); + } + + /** * Returns the tangent of the curve at 0 <= {@code t} <= 1. */ public Vector getTangent(double t) { @@ -107,13 +118,13 @@ class RaceTrack extends BetterBase { private void drawTestTrack() { /* A track segment looks like: - * B----------------------------D + * B----------------------------D "outside top" * / : /| - * / G- - - - - - - - - - - - -/--H + * / G- - - - - - - - - - - - -/--H "outside bottom" * / / - * A----------------------------C + * A----------------------------C "inside top" * | | - * E----------------------------F + * E----------------------------F "inside bottom" * ^-- t = t0 ^-- t = t0 + 1 * Assume point A the inner point of the race track. Draw quads from * EF (starting point) to AC, BD, GH. @@ -121,28 +132,38 @@ class RaceTrack extends BetterBase { // previous points Vector point_A = null, point_B = null, point_E = null, point_G = null; - setColor(Colors.PALE_TURQOISE); - - for (double i = 0; i < SEGMENTS; ++i) { - double t = i * 2 * PI / SEGMENTS; + for (double i = 0; i <= SEGMENTS; ++i) { + double t = i / SEGMENTS; Vector point_C = getPoint(t); - Vector lanes_len = new Vector(point_C.x(), point_C.y(), 0).normalized().scale(4); - Vector point_D = point_C.add(lanes_len); + Vector point_D = getPointForLane(t, 4); // Z=1 to Z=-1 Vector point_F = point_C.subtract(new Vector(0, 0, 2)); Vector point_H = point_D.subtract(new Vector(0, 0, 2)); // initially, there are no "previous" vectors to use as start. if (i > 0) { + Vector norm_outside = new Vector(point_E.x(), point_E.y(), 0).normalized(); + Vector norm_inside = norm_outside.scale(-1).normalized(); + Vector norm_up = Vector.Z; + gl.glBegin(GL_QUAD_STRIP); + setColor(Color.RED); + // inside bottom + glNormal(norm_inside); glVertex(point_E); glVertex(point_F); + setColor(Colors.PALE_TURQOISE); + // inside top + glNormal(norm_up.add(norm_inside).normalized()); glVertex(point_A); glVertex(point_C); - setColor(Colors.CHOCOLATE); + // outside top + glNormal(norm_up.add(norm_outside).normalized()); glVertex(point_B); glVertex(point_D); - setColor(Colors.PALE_TURQOISE); + setColor(Color.RED); + // outside bottom + glNormal(norm_outside); glVertex(point_G); glVertex(point_H); gl.glEnd(); |