From 58bfc1b0e0e69c521d60e05931fcc7852a109c24 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Thu, 21 Nov 2013 17:23:19 +0100 Subject: robot drawing --- src/RobotRace.java | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 139 insertions(+), 7 deletions(-) diff --git a/src/RobotRace.java b/src/RobotRace.java index 3e14212..9d6c9b4 100644 --- a/src/RobotRace.java +++ b/src/RobotRace.java @@ -197,7 +197,7 @@ public class RobotRace extends Base { terrain.draw(); // Unit box around origin. - glut.glutWireCube(1f); + //glut.glutWireCube(1f); // Move in x-direction. gl.glTranslatef(2f, 0f, 0f); @@ -209,7 +209,7 @@ public class RobotRace extends Base { gl.glScalef(1f, 1f, 2f); // Translated, rotated, scaled box. - glut.glutWireCube(1f); + //glut.glutWireCube(1f); } /** @@ -331,7 +331,7 @@ public class RobotRace extends Base { /** Relative lengths, widths and heights of robot model. */ private final float torsoHeight, torsoWidth, shoulderRadius, armLength, - legLength, armWidth, legWidth, neckHeight, headRadius; + legLength, armWidth, legWidth, neckHeight, headRadius, depth; /** * Constructs the robot with initial parameters. @@ -343,11 +343,12 @@ public class RobotRace extends Base { this.torsoWidth = 0.48f; this.shoulderRadius = 0.09f; this.armLength = 0.6f; - this.armWidth = 0.15f; + this.armWidth = 0.06f; this.legLength = 0.78f; - this.legWidth = 0.3f; - this.neckHeight = 0.3f; - this.headRadius = 0.18f; + this.legWidth = 0.06f; + this.neckHeight = 0.15f; + this.headRadius = 0.12f; + this.depth = 0.24f; } /** @@ -355,7 +356,138 @@ public class RobotRace extends Base { */ public void draw(boolean stickFigure) { // code goes here ... + if(!stickFigure) { + drawTorso(); + drawShoulders(); + drawLegs(); + drawArms(); + drawHead(); + } + + } + + private void drawTorso() { + gl.glPushMatrix(); + + gl.glScalef(torsoWidth, depth, torsoHeight); + + glut.glutWireCube(1f); + + gl.glPopMatrix(); + } + + private void drawShoulders() { + gl.glPushMatrix(); + + gl.glTranslatef(torsoWidth / 2 + shoulderRadius / 1.5f, 0f, torsoHeight / 2); + + gl.glColor3f(1.0f / 100f, 1.0f/130f, 1.0f/255f); + glut.glutWireSphere(shoulderRadius, 10, 10); + + gl.glPopMatrix(); + gl.glPushMatrix(); + + gl.glTranslatef(- torsoWidth / 2 - shoulderRadius / 1.5f, 0f, torsoHeight / 2); + + gl.glColor3f(1.0f / 100f, 1.0f/130f, 1.0f/255f); + glut.glutWireSphere(shoulderRadius, 10, 10); + + gl.glPopMatrix(); + } + + private void drawLegs() { + gl.glPushMatrix(); + + gl.glTranslatef(torsoWidth / 2 - legWidth * 2, 0f, + - legLength / 2 - torsoHeight / 2); + gl.glScalef(legWidth, legWidth, legLength); + + gl.glColor3f(1.0f / 150f, 1.0f/150f, 1.0f/150f); + glut.glutSolidCube(1f); + + gl.glScalef(1/legWidth, 1/legWidth, 1/legLength); + gl.glTranslatef(0f, 0f, - legLength / 2); + gl.glTranslatef(legWidth / 2, legWidth, 0f); + gl.glScalef(legWidth, legWidth * 2, 0.1f); + + gl.glColor3f(1.0f / 100f, 1.0f/100f, 1.0f/100f); + glut.glutSolidCube(1f); + + gl.glPopMatrix(); + gl.glPushMatrix(); + + gl.glTranslatef(-torsoWidth / 2 + legWidth * 2, 0f, + - legLength / 2 - torsoHeight / 2); + gl.glScalef(legWidth, legWidth, legLength); + + gl.glColor3f(1.0f / 150f, 1.0f/150f, 1.0f/150f); + glut.glutSolidCube(1f); + + gl.glScalef(1/legWidth, 1/legWidth, 1/legLength); + gl.glTranslatef(0f, 0f, - legLength / 2); + gl.glTranslatef(legWidth / 2, legWidth, 0f); + gl.glScalef(legWidth, legWidth * 2, 0.1f); + + gl.glColor3f(1.0f / 100f, 1.0f/100f, 1.0f/100f); + glut.glutSolidCube(1f); + + gl.glPopMatrix(); } + + private void drawArms() { + gl.glPushMatrix(); + + gl.glTranslatef(torsoWidth / 2 + armWidth * 1.5f, 0f, + torsoHeight / 2 - armLength / 2 - 0.05f); + gl.glScalef(armWidth, armWidth, armLength); + + gl.glColor3f(1.0f / 218f, 1.0f/218f, 1.0f/218f); + glut.glutWireCube(1f); + + gl.glScalef(1/armWidth, 1/armWidth, 1/armLength); + gl.glTranslatef(0f, 0f, - armLength / 2); + + gl.glColor3f(1.0f / 100f, 1.0f/130f, 1.0f/255f); + glut.glutWireSphere(armWidth * 1.5f, 10, 10); + + gl.glPopMatrix(); + gl.glPushMatrix(); + + gl.glTranslatef(-(torsoWidth / 2 + armWidth * 1.5f), 0f, + torsoHeight / 2 - armLength / 2 - 0.05f); + gl.glScalef(armWidth, armWidth, armLength); + + gl.glColor3f(1.0f / 218f, 1.0f/218f, 1.0f/218f); + glut.glutWireCube(1f); + + gl.glScalef(1/armWidth, 1/armWidth, 1/armLength); + gl.glTranslatef(0f, 0f, - armLength / 2); + + gl.glColor3f(1.0f / 100f, 1.0f/130f, 1.0f/255f); + glut.glutWireSphere(armWidth * 1.5f, 10, 10); + + gl.glPopMatrix(); + } + + private void drawHead() { + gl.glPushMatrix(); + + gl.glTranslatef(0f, 0f, torsoHeight / 2 + neckHeight / 2); + gl.glScalef(headRadius / 2.5f, headRadius / 2.5f, neckHeight); + + glut.glutWireCube(1f); + + gl.glPopMatrix(); + gl.glPushMatrix(); + + gl.glTranslatef(0f, 0f, torsoHeight / 2 + neckHeight + + headRadius / 2); + + glut.glutWireSphere(headRadius, 10, 10); + + gl.glPopMatrix(); + } + } /** -- cgit v1.2.1