summaryrefslogtreecommitdiff
path: root/src/Robot.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Robot.java')
-rw-r--r--src/Robot.java59
1 files changed, 48 insertions, 11 deletions
diff --git a/src/Robot.java b/src/Robot.java
index cffbffc..51fad15 100644
--- a/src/Robot.java
+++ b/src/Robot.java
@@ -102,8 +102,14 @@ class Robot extends BetterBase {
// Draw the robot, everything is relative to the center of torso.
// Static parts (that do not animate):
+ race.getTorsoTexture().bind(gl);
drawTorso();
+
+ //race.getHeadTexture().bind(gl);
drawHead();
+
+ unbindTextures();
+
// only draw the shoulder parts in normal, full body mode
if (!asStickFigure) {
drawShoulderTop();
@@ -116,7 +122,7 @@ class Robot extends BetterBase {
// draw left and right arms
drawArm(false);
drawArm(true);
-
+
//<editor-fold>
// The following function call exist to make a point clear. Adding
// comments for the sake of having comments is silly, pointless and an
@@ -144,7 +150,8 @@ class Robot extends BetterBase {
* when drawing a stick figure, in that case the boneColor constant will
* be used.
*/
- private void drawBeam(float x, float y, float z, Direction dir, Color color) {
+ private void drawBeam(float x, float y, float z, Direction dir, Color color,
+ boolean isTextured) {
if (asStickFigure) {
// for a stick figure, draw a thin figure without colors
switch (dir) {
@@ -176,7 +183,13 @@ class Robot extends BetterBase {
// turn a cube into a small beam
gl.glScalef(x, y, z);
- drawCube();
+ // Depending on if it needs to be textured, use our own method
+ // or the glut solid cube.
+ if (isTextured) {
+ drawCube();
+ } else {
+ glut.glutSolidCube(1);
+ }
// return to previous scales
gl.glScalef(1 / x, 1 / y, 1 / z);
@@ -219,44 +232,68 @@ class Robot extends BetterBase {
gl.glBegin(GL_QUADS);
// Front face
glNormal(norm_towards);
+ gl.glTexCoord2f(0, 0);
glVertex(point_A);
+ gl.glTexCoord2f(1, 0);
glVertex(point_B);
+ gl.glTexCoord2f(0, 1);
glVertex(point_C);
+ gl.glTexCoord2f(1, 1);
glVertex(point_D);
// Right face
glNormal(norm_right);
+ gl.glTexCoord2f(0, 0);
glVertex(point_B);
+ gl.glTexCoord2f(1, 0);
glVertex(point_F);
+ gl.glTexCoord2f(0, 1);
glVertex(point_G);
+ gl.glTexCoord2f(1, 1);
glVertex(point_C);
// Back face
glNormal(norm_outwards);
+ gl.glTexCoord2f(0, 0);
glVertex(point_F);
+ gl.glTexCoord2f(1, 0);
glVertex(point_G);
+ gl.glTexCoord2f(0, 1);
glVertex(point_H);
+ gl.glTexCoord2f(1, 1);
glVertex(point_E);
// Left face
glNormal(norm_left);
+ gl.glTexCoord2f(0, 0);
glVertex(point_A);
+ gl.glTexCoord2f(1, 0);
glVertex(point_G);
+ gl.glTexCoord2f(0, 1);
glVertex(point_H);
+ gl.glTexCoord2f(1, 1);
glVertex(point_D);
// Top face
glNormal(norm_up);
+ gl.glTexCoord2f(0, 0);
glVertex(point_D);
+ gl.glTexCoord2f(1, 0);
glVertex(point_C);
+ gl.glTexCoord2f(0, 1);
glVertex(point_G);
+ gl.glTexCoord2f(1, 1);
glVertex(point_H);
// Bottom face
glNormal(norm_down);
+ gl.glTexCoord2f(0, 0);
glVertex(point_A);
+ gl.glTexCoord2f(1, 0);
glVertex(point_B);
+ gl.glTexCoord2f(0, 1);
glVertex(point_F);
+ gl.glTexCoord2f(1, 1);
glVertex(point_E);
gl.glEnd();
}
@@ -275,16 +312,16 @@ class Robot extends BetterBase {
*/
private void drawTorso() {
// Scale the torso to specified values
- drawBeam(torsoWidth, depth, torsoHeight, Direction.Z, Color.LIGHT_GRAY);
+ drawBeam(torsoWidth, depth, torsoHeight, Direction.Z, Color.LIGHT_GRAY, true);
if (asStickFigure) {
// draw the bone connecting the arms (visible for stick figure)
gl.glTranslatef(0, 0, torsoHeight / 2);
- drawBeam(torsoWidth + armWidth * 3, boneSize, boneSize, Direction.X, null);
+ drawBeam(torsoWidth + armWidth * 3, boneSize, boneSize, Direction.X, null, false);
gl.glTranslatef(0, 0, -torsoHeight);
// draw the bone connecting the legs (visible for stick figure)
- drawBeam(.5f * torsoWidth + legWidth / 2, boneSize, boneSize, Direction.X, null);
+ drawBeam(.5f * torsoWidth + legWidth / 2, boneSize, boneSize, Direction.X, null, false);
// return to torso center
gl.glTranslatef(0, 0, torsoHeight / 2);
@@ -332,7 +369,7 @@ class Robot extends BetterBase {
// upper leg half
gl.glTranslatef(0, 0, -legLength / 4);
- drawBeam(legWidth, legWidth, legLength / 2, Direction.Z, Color.DARK_GRAY);
+ drawBeam(legWidth, legWidth, legLength / 2, Direction.Z, Color.DARK_GRAY, false);
// knee
gl.glTranslatef(0, 0, -legLength / 4);
@@ -340,7 +377,7 @@ class Robot extends BetterBase {
// lower leg half
gl.glTranslatef(0, 0, -legLength / 4);
- drawBeam(legWidth, legWidth, legLength / 2, Direction.Z, Color.DARK_GRAY);
+ drawBeam(legWidth, legWidth, legLength / 2, Direction.Z, Color.DARK_GRAY, false);
// for the stick figure, the "foot" is just an extension of the leg line
// and therefore stays at the same y-position
@@ -351,7 +388,7 @@ class Robot extends BetterBase {
}
// draw foot!
gl.glTranslatef(0, foot_y, -legLength / 4 - footHeight / 2);
- drawBeam(footWidth, footLength, footHeight, Direction.Z, Colors.GRAYISH);
+ drawBeam(footWidth, footLength, footHeight, Direction.Z, Colors.GRAYISH, false);
// Restore position
gl.glPopMatrix();
@@ -376,7 +413,7 @@ class Robot extends BetterBase {
// 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);
+ drawBeam(armWidth, armWidth, armLength, Direction.Z, Colors.ARM_GRAY_COLOR, false);
if (!asStickFigure) {
// Give me a big hand!
@@ -398,7 +435,7 @@ class Robot extends BetterBase {
// position centered above the torso for the neck
gl.glTranslatef(0f, 0f, torsoHeight / 2 + neckHeight / 2);
float neckRadius = headRadius / 2.5f;
- drawBeam(neckRadius, neckRadius, neckHeight, Direction.Z, Colors.LAVENDER);
+ drawBeam(neckRadius, neckRadius, neckHeight, Direction.Z, Colors.LAVENDER, false);
// continue moving to the center of the head
gl.glTranslatef(0f, 0f, neckHeight / 2 + headRadius / 2);