From 72a4103bc0321906b638cbd73ad197145a2b6e9d Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Fri, 17 Jan 2014 14:53:47 +0100 Subject: Fix robot viewing direction --- src/RobotRace.java | 19 ++++++++----------- 1 file 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 -- cgit v1.2.1