summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank v/d Haterd <f.h.a.v.d.haterd@student.tue.nl>2014-01-08 15:07:33 +0100
committerFrank v/d Haterd <f.h.a.v.d.haterd@student.tue.nl>2014-01-08 15:07:33 +0100
commite83457cebe05c1fa7e6cc3ec32f0b849bbded195 (patch)
tree25189a2fec09d24761e4b8041399d39c2639e198
parent4910928e236a4a2e783934952cce74eb58872f9e (diff)
download2iv60-robots-e83457cebe05c1fa7e6cc3ec32f0b849bbded195.tar.gz
Replace glut by gl
-rw-r--r--src/Robot.java84
1 files changed, 83 insertions, 1 deletions
diff --git a/src/Robot.java b/src/Robot.java
index aa6c539..cffbffc 100644
--- a/src/Robot.java
+++ b/src/Robot.java
@@ -3,6 +3,7 @@ import java.awt.Color;
import javax.media.opengl.GL;
import static javax.media.opengl.GL2.*;
import javax.media.opengl.fixedfunc.GLLightingFunc;
+import robotrace.Vector;
/**
* Represents a Robot, to be implemented according to the Assignments.
@@ -174,12 +175,93 @@ class Robot extends BetterBase {
}
// turn a cube into a small beam
gl.glScalef(x, y, z);
- glut.glutSolidCube(1);
+
+ drawCube();
+
// return to previous scales
gl.glScalef(1 / x, 1 / y, 1 / z);
}
/**
+ * Draw a cube with our own defined method with quads, to support
+ * texturing.
+ */
+ private void drawCube() {
+ /* Define the points of the cube, our cube is defined as follows:
+ *
+ * H ------------ G
+ * /| /|
+ * / | / |
+ * D ------------ C |
+ * | E ---------|-- F
+ * | / | /
+ * | / | /
+ * A ------------ B
+ */
+ Vector point_A = new Vector(-0.5f, -.5f, -.5f);
+ Vector point_B = new Vector(0.5f, -.5f, -.5f);
+ Vector point_C = new Vector(0.5f, -.5f, 0.5f);
+ Vector point_D = new Vector(-0.5f, -.5f, 0.5f);
+ Vector point_E = new Vector(-0.5f, 0.5f, -.5f);
+ Vector point_F = new Vector(.5f, 0.5f, -.5f);
+ Vector point_G = new Vector(.5f, 0.5f, 0.5f);
+ Vector point_H = new Vector(-0.5f, 0.5f, 0.5f);
+
+ // Define the six normals
+ Vector norm_up = new Vector(0, 0, 1);
+ Vector norm_right = new Vector(0, 1, 0);
+ Vector norm_towards = new Vector(1, 0, 0);
+ Vector norm_down = norm_up.scale(-1);
+ Vector norm_left = norm_right.scale(-1);
+ Vector norm_outwards = norm_towards.scale(-1);
+
+ // Start drawing the points of the cube
+ gl.glBegin(GL_QUADS);
+ // Front face
+ glNormal(norm_towards);
+ glVertex(point_A);
+ glVertex(point_B);
+ glVertex(point_C);
+ glVertex(point_D);
+
+ // Right face
+ glNormal(norm_right);
+ glVertex(point_B);
+ glVertex(point_F);
+ glVertex(point_G);
+ glVertex(point_C);
+
+ // Back face
+ glNormal(norm_outwards);
+ glVertex(point_F);
+ glVertex(point_G);
+ glVertex(point_H);
+ glVertex(point_E);
+
+ // Left face
+ glNormal(norm_left);
+ glVertex(point_A);
+ glVertex(point_G);
+ glVertex(point_H);
+ glVertex(point_D);
+
+ // Top face
+ glNormal(norm_up);
+ glVertex(point_D);
+ glVertex(point_C);
+ glVertex(point_G);
+ glVertex(point_H);
+
+ // Bottom face
+ glNormal(norm_down);
+ glVertex(point_A);
+ glVertex(point_B);
+ glVertex(point_F);
+ glVertex(point_E);
+ gl.glEnd();
+ }
+
+ /**
* Draws a joint for stick figure model.
*/
private void drawJoint() {