/* Copyright 2010 Christian Matt
*
* This file is part of PonkOut.
*
* PonkOut is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PonkOut is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PonkOut. If not, see <http://www.gnu.org/licenses/>.
*/
package ponkOut.graphics;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.util.vector.Vector3f;
import ponkOut.logic.Block;
public class BlockGO extends WorldObject {
private Block block;
private int displayList;
public BlockGO(Block block, GraphicsObjectsManager goManager) {
super(Material.getPresetMaterial(Material.PresetMaterial.GOLD), goManager);
this.block = block;
Vector2f topLeft = block.getCornerPos(Block.CornerPlace.TOP_LEFT);
Vector2f bottomRight = block.getCornerPos(Block.CornerPlace.BOTTOM_RIGHT);
float left = topLeft.x;
float right = bottomRight.x;
float top = topLeft.y;
float bottom = bottomRight.y;
float front = -Board.surfaceZPosition;
float back = Board.surfaceZPosition;
// create display list
displayList = GL11.glGenLists(1);
GL11.glNewList(displayList, GL11.GL_COMPILE);
// draw a cuboid
GL11.glBegin(GL11.GL_QUADS);
// front
GL11.glNormal3f(0.0f, 0.0f, 1.0f);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(left, bottom, front);
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(right, bottom, front);
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(right, top, front);
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(left, top, front);
// back
GL11.glNormal3f(0.0f, 0.0f, -1.0f);
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(left, bottom, back);
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(left, top, back);
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(right, top, back);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(right, bottom, back);
// right
GL11.glNormal3f(1.0f, 0.0f, 0.0f);
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(right, bottom, back);
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(right, top, back);
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(right, top, front);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(right, bottom, front);
// left
GL11.glNormal3f(-1.0f, 0.0f, 0.0f);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(left, bottom, back);
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(left, bottom, front);
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(left, top, front);
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(left, top, back);
// top
GL11.glNormal3f(0.0f, 1.0f, 0.0f);
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(left, top, back);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(left, top, front);
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(right, top, front);
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(right, top, back);
// bottom
GL11.glNormal3f(0.0f, -1.0f, 0.0f);
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex3f(left, bottom, back);
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex3f(right, bottom, back);
GL11.glTexCoord2f(0.0f, 0.0f);
GL11.glVertex3f(right, bottom, front);
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex3f(left, bottom, front);
GL11.glEnd();
GL11.glEndList();
}
@Override
public void draw() {
// enable lighting
Lighting.enable(false);
// set material
appearance.use();
// draw block
GL11.glCallList(displayList);
// disable lighting
Lighting.disable();
}
@Override
public Vector3f getPosition() {
Vector2f pos = block.getPosition();
return new Vector3f(pos.x, pos.y, 0.0f);
}
}