diff options
author | Peter Wu <lekensteyn@gmail.com> | 2014-01-17 14:53:47 +0100 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2014-01-17 14:53:47 +0100 |
commit | 72a4103bc0321906b638cbd73ad197145a2b6e9d (patch) | |
tree | 436d0614698f313b7b1646c7d39956a1211a7127 | |
parent | fe257bbd8b9304578c38ee3e386c8a4660f8589e (diff) | |
download | 2iv60-robots-72a4103bc0321906b638cbd73ad197145a2b6e9d.tar.gz |
Fix robot viewing direction
-rw-r--r-- | src/RobotRace.java | 19 |
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 |