summaryrefslogtreecommitdiff
path: root/src/Tree.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Tree.java')
-rw-r--r--src/Tree.java74
1 files changed, 37 insertions, 37 deletions
diff --git a/src/Tree.java b/src/Tree.java
index a773b9b..43e45c5 100644
--- a/src/Tree.java
+++ b/src/Tree.java
@@ -18,31 +18,31 @@ public class Tree extends BetterBase {
* are set with the values 0 and 1.
*/
private final int treeVariation;
-
+
/**
- * Defines the position where the tree is placed on the terrain.
- *
+ * Defines the position where the tree is placed on the terrain.
+ *
* The position is defined from in both x and y direction as [-20, 20]
- * so position transformations are based on the origin.
+ * so position transformations are based on the origin.
*/
private Vector treePosition;
-
+
/**
- * The display list containing the tree.
+ * The display list containing the tree.
*/
private int treeDisplayList;
-
- private final float treeTrunkHeight;
+
+ private final float treeTrunkHeight;
private final float treeTrunkRadius;
private final Terrain terrain;
/**
* Initialize a tree.
- *
+ *
* @param terrain
* @param position
* @param scale
- * @param variation
+ * @param variation
*/
public Tree(Terrain terrain, Vector position, float scale, int variation) {
// Set up variables
@@ -50,50 +50,50 @@ public class Tree extends BetterBase {
this.treeVariation = variation;
this.treeScale = scale;
this.treeDisplayList = 0;
-
+
// Set properties of a tree
this.treeTrunkHeight = 2.5f;
this.treeTrunkRadius = 0.25f;
-
-
+
+
// Set the height based on the terrains height
- this.treePosition = position;
+ this.treePosition = position;
}
- public void createTree() {
+ public void createTree() {
// Create display list
this.treeDisplayList = gl.glGenLists(1);
// Initialize display list
gl.glNewList(treeDisplayList, GL2.GL_COMPILE);
-
+
// Push matrix so we can restore the state after drawing
gl.glPushMatrix();
-
- // Set the position of the tree and the right height
- gl.glTranslatef((float) treePosition.x(), (float) treePosition.y(),
+
+ // Set the position of the tree and the right height
+ gl.glTranslatef((float) treePosition.x(), (float) treePosition.y(),
(float) treePosition.z() - 0.2f);
-
+
// Translate so the tree appears on the right place
- gl.glTranslatef(-treeTrunkRadius / 2, -treeTrunkRadius / 2,
+ gl.glTranslatef(-treeTrunkRadius / 2, -treeTrunkRadius / 2,
0);
-
+
// Now draw the trunk
drawTrunk();
-
+
// Translate to trunk height and draw the leaves
drawLeaves();
-
+
// Restore drawing state
gl.glPopMatrix();
-
+
/** End the list, everything in the list can be easily drawed by using
- * this display list. This is more efficient then just drawing
+ * this display list. This is more efficient then just drawing
* everything every time.
*/
gl.glEndList();
}
-
+
/**
* Draw this tree, this method will be called from the Terrain class
* that will contain all trees in an array.
@@ -107,16 +107,16 @@ public class Tree extends BetterBase {
setColor(new Color(83, 53, 10));
glut.glutSolidCylinder(treeTrunkRadius, treeTrunkHeight + treeScale, 6, 6);
}
-
+
/**
- * Draw the leaves of the tree, based on the variation.
+ * Draw the leaves of the tree, based on the variation.
*/
private void drawLeaves() {
-
+
float totalHeight = treeScale + treeTrunkHeight;
-
+
if(treeVariation == 0) {
- // Draw the christmas tree
+ // Draw the christmas tree
setColor(new Color(20, 51, 6));
gl.glTranslatef(0, 0, totalHeight - 0.5f);
glut.glutSolidCone(4f * treeTrunkRadius, totalHeight / 1.2f, 6, 6);
@@ -134,12 +134,12 @@ public class Tree extends BetterBase {
glut.glutSolidSphere(radius / 1.25f, 6, 6);
}
}
-
+
public Vector getPosition() {
return treePosition;
}
-
-
-
-
+
+
+
+
}