/* 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.util.vector.Matrix4f;
import org.lwjgl.util.vector.Vector3f;
/**
* GraphicsObject with 3D coordinates
*/
public abstract class WorldObject implements GraphicsObject {
protected Appearance appearance;
private float zDepth;
private boolean visible;
public WorldObject(Appearance appearance, boolean visible, GraphicsObjectsManager goManager) {
this.appearance = appearance;
setVisibility(visible);
goManager.addWorldObject(this);
}
public WorldObject(Appearance appearance, GraphicsObjectsManager goManager) {
this(appearance, true, goManager);
}
@Override
public abstract void draw();
public abstract Vector3f getPosition();
public boolean isOpaque() {
return appearance.isOpaque();
}
/**
* Calculates Z-position in eye coordinates. Call getZDepth to get result.
*/
public void updateZDepth() {
Matrix4f transformation = Camera.getTransformation();
transformation.translate(getPosition());
zDepth = transformation.m32;
}
/**
* updateZDepth must be called beforehand if position or camera has changed.
*
* @return Z-position in eye coordinates
*/
public float getZDepth() {
return zDepth;
}
@Override
public boolean isVisible() {
return visible;
}
@Override
public void setVisibility(boolean visible) {
this.visible = visible;
}
}