From e83457cebe05c1fa7e6cc3ec32f0b849bbded195 Mon Sep 17 00:00:00 2001 From: Frank v/d Haterd Date: Wed, 8 Jan 2014 15:07:33 +0100 Subject: Replace glut by gl --- src/Robot.java | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) 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,11 +175,92 @@ 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. */ -- cgit v1.2.1