summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank v/d Haterd <f.h.a.v.d.haterd@student.tue.nl>2013-12-22 16:53:17 +0100
committerFrank v/d Haterd <f.h.a.v.d.haterd@student.tue.nl>2013-12-22 16:53:17 +0100
commitcbfd16060e8352d7ea8f05d9bb8d58253243930d (patch)
treeafc048a67b3d63de0c88c1b0a06309cc9fbb0432
parent41ed8265a84b6e00aff50f75640abc807b3ffc24 (diff)
download2iv60-robots-cbfd16060e8352d7ea8f05d9bb8d58253243930d.tar.gz
New commit of the rotation, seems to be working now.
-rw-r--r--src/RobotRace.java13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/RobotRace.java b/src/RobotRace.java
index bcfceab..ee7fbcc 100644
--- a/src/RobotRace.java
+++ b/src/RobotRace.java
@@ -414,9 +414,16 @@ 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.
- double angle = atan2(robotPos.y(), robotPos.x()) * 180/PI;
+ /* 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;
gl.glRotated(angle, 0, 0, 1);