/* 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.Vector3f;
import ponkOut.graphics.resources.Texture;
public class Sprite extends WorldObject {
private Texture texture;
private static int displayList;
private Vector3f position;
private float rotX;
private float rotY;
private float rotZ;
public Sprite(Texture texture, Color color, Vector3f position, float width, float height, float texX0, float texX1,
float texY0, float texY1, float rotX, float rotY, float rotZ, GraphicsObjectsManager goManager) {
super(color, goManager);
this.texture = texture;
this.position = new Vector3f(position);
this.rotX = rotX;
this.rotY = rotY;
this.rotZ = rotZ;
displayList = GL11.glGenLists(1);
// create display list
GL11.glNewList(displayList, GL11.GL_COMPILE);
GL11.glBegin(GL11.GL_QUADS);
// bottom left
GL11.glTexCoord2f(texX0, texY0);
GL11.glVertex2f(0.0f, -height);
// bottom right
GL11.glTexCoord2f(texX1, texY0);
GL11.glVertex2f(width, -height);
// top right
GL11.glTexCoord2f(texX1, texY1);
GL11.glVertex2f(width, 0.0f);
// top left
GL11.glTexCoord2f(texX0, texY1);
GL11.glVertex2f(0.0f, 0.0f);
GL11.glEnd();
GL11.glEndList();
}
@Override
public void draw() {
// store current transformation matrix
GL11.glPushMatrix();
// translate to text position
GL11.glTranslatef(position.x, position.y, position.z);
// rotate
GL11.glRotatef(rotZ, 0.0f, 0.0f, 1.0f);
GL11.glRotatef(rotY, 0.0f, 1.0f, 0.0f);
GL11.glRotatef(rotX, 1.0f, 0.0f, 0.0f);
// set color
appearance.use();
texture.bind();
// draw it
GL11.glCallList(displayList);
// restore transformation matrix
GL11.glPopMatrix();
}
@Override
public Vector3f getPosition() {
return new Vector3f(position);
}
}