/* Copyright 2010, 2012 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;
public class WorldText extends WorldObject {
private String string;
private Vector3f position;
private float rotX;
private float rotY;
private float rotZ;
private float size;
private boolean lit;
private Font font;
private WorldText(String string, float size, Appearance appearance, Vector3f position, float rotX, float rotY,
float rotZ, boolean lit, GraphicsObjectsManager goManager) {
super(appearance, goManager);
this.string = string;
this.size = size;
this.font = new Font();
this.position = new Vector3f(position);
this.rotX = rotX;
this.rotY = rotY;
this.rotZ = rotZ;
this.lit = lit;
}
public WorldText(String string, float size, Color color, Vector3f position, float rotX, float rotY, float rotZ,
GraphicsObjectsManager goManager) {
this(string, size, color, position, rotX, rotY, rotZ, false, goManager);
}
public WorldText(String string, float size, Material material, Vector3f position, float rotX, float rotY,
float rotZ, GraphicsObjectsManager goManager) {
this(string, size, material, position, rotX, rotY, rotZ, true, goManager);
}
public String getString() {
return string;
}
public void setText(String string) {
this.string = string;
}
@Override
public Vector3f getPosition() {
return new Vector3f(position);
}
@Override
public boolean isOpaque() {
return false;
}
@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);
// scale
GL11.glScalef(size, size, size);
if (lit)
Lighting.enableBumpMapped();
// set color
appearance.use();
// draw it
font.drawString(string, true, lit);
if (lit)
Lighting.disable();
// restore transformation matrix
GL11.glPopMatrix();
}
public float getWidth() {
return size * string.length() * font.getCharacterWidth();
}
public float getHeight() {
return size * font.getCharacterHeight();
}
public void translate(float x, float y, float z) {
position.x += x;
position.y += y;
position.z += z;
}
public void setPosition(Vector3f position) {
this.position = new Vector3f(position);
}
}