summaryrefslogtreecommitdiff
path: root/src/Robot.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Robot.java')
-rw-r--r--src/Robot.java32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/Robot.java b/src/Robot.java
index 3b9c0cb..3eeb1af 100644
--- a/src/Robot.java
+++ b/src/Robot.java
@@ -63,6 +63,8 @@ class Robot extends BetterBase {
*/
private final static double TRACK_LENGTH = 76.0;
+ private final WalkAnimation walkAnim;
+
/**
* Constructs the robot with initial parameters.
*/
@@ -85,6 +87,7 @@ class Robot extends BetterBase {
this.boneSize = 0.02f;
this.depth = 0.24f;
this.laneNo = laneNo;
+ this.walkAnim = new DumbWalkAnimation();
}
/**
@@ -105,6 +108,9 @@ class Robot extends BetterBase {
// stands on the XY plane.
gl.glTranslatef(0, 0, torsoHeight / 2 + legLength + footHeight);
+ // calculate rotation angles and positions for movements.
+ walkAnim.updatePosition(robot_pos_meters);
+
// Draw the robot, everything is relative to the center of torso.
// Static parts (that do not animate):
@@ -132,11 +138,11 @@ class Robot extends BetterBase {
// Parts that should be animated:
// draw left and right legs
- drawLeg(false);
- drawLeg(true);
+ drawLeg(false, walkAnim.getLegAngleLeft(), walkAnim.getKneeAngleLeft());
+ drawLeg(true, walkAnim.getLegAngleRight(), walkAnim.getKneeAngleRight());
// draw left and right arms
- drawArm(false);
- drawArm(true);
+ drawArm(false, walkAnim.getArmAngleLeft());
+ drawArm(true, walkAnim.getArmAngleRight());
//<editor-fold>
// The following function call exist to make a point clear. Adding
@@ -369,8 +375,10 @@ class Robot extends BetterBase {
/**
* Draws the upper and lower legs and feet of the robot.
* @param isRight True if at the robot's right (from the robot POV).
+ * @param hip_angle Angle at the hip in degrees.
+ * @param knee_angle Angle behind knee in degrees.
*/
- private void drawLeg(boolean isRight) {
+ private void drawLeg(boolean isRight, double hip_angle, double knee_angle) {
// save center position
gl.glPushMatrix();
@@ -382,6 +390,9 @@ class Robot extends BetterBase {
gl.glTranslatef(leg_top_x, 0f, -torsoHeight / 2);
drawJoint();
+ // rotate upper leg around hips
+ gl.glRotated(hip_angle, 1, 0, 0);
+
// upper leg half
gl.glTranslatef(0, 0, -legLength / 4);
drawBeam(legWidth, legWidth, legLength / 2, Direction.Z, Color.DARK_GRAY, false);
@@ -390,6 +401,9 @@ class Robot extends BetterBase {
gl.glTranslatef(0, 0, -legLength / 4);
drawJoint();
+ // rotate lower leg around back of knee (clock-wise "180 - knee angle")
+ gl.glRotated(knee_angle - 180, 1, 0, 0);
+
// lower leg half
gl.glTranslatef(0, 0, -legLength / 4);
drawBeam(legWidth, legWidth, legLength / 2, Direction.Z, Color.DARK_GRAY, false);
@@ -410,10 +424,11 @@ class Robot extends BetterBase {
}
/**
- * Draw both arms and both hands of the robot.
+ * Draw both arms and both hands of the robot.
* @param isRight True if at the robot's right (from the robot POV).
+ * @param armAngle angle of the arm in degrees.
*/
- private void drawArm(boolean isRight) {
+ private void drawArm(boolean isRight, double armAngle) {
// Push the translation matrix so we can return to the origin
gl.glPushMatrix();
@@ -426,6 +441,9 @@ class Robot extends BetterBase {
gl.glTranslatef(arm_x, 0, torsoHeight / 2);
drawJoint();
+ // rotate arm around shoulder
+ gl.glRotated(armAngle, 1, 0, 0);
+
// here is your arm (start drawing from the elbow)
gl.glTranslatef(0, 0, -armLength / 2);
drawBeam(armWidth, armWidth, armLength, Direction.Z, Colors.ARM_GRAY_COLOR, false);