summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/RobotRace.java19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/RobotRace.java b/src/RobotRace.java
index 66e2594..e166ad9 100644
--- a/src/RobotRace.java
+++ b/src/RobotRace.java
@@ -506,17 +506,14 @@ public class RobotRace extends Base {
Vector robotPos = raceTrack.getPointForLane(robot.getTimePos(), i);
gl.glTranslated(robotPos.x(), robotPos.y(), robotPos.z());
- /* Calculate angle for the robots to look at, multiply by 180/PI
- * to convert the radions to degrees.
- * First get the tangent of the robot, that is the real direction
- * where the robot is looking to.
- * Then add this vector to the actual position, and from the
- * resulting vector we can calculate the angle. */
- Vector robotTangent = raceTrack.getTangent(robot.getTimePos());
- Vector totalVector = robotTangent.add(robotPos);
-
- double angle = atan2(totalVector.y(), totalVector.x()) * 180/PI;
-
+ /* While the robot looks in the tangent direction, the position of
+ * the robot on the track is determined by the normal. For cases
+ * where the origin is used to create the track (circles), the
+ * robot position could be used as well (for direction). In the
+ * general case though, the normal is needed.
+ */
+ Vector norm = raceTrack.getNormal(robot.getTimePos());
+ double angle = atan2(norm.y(), norm.x()) * 180 / PI;
gl.glRotated(angle, 0, 0, 1);
// Draw the current robot