/* 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 java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector3f;
/**
* A point light
*/
public class Light {
private int id;
private FloatBuffer position;
public Light(int id, Vector3f position, float[] ambient, float[] diffuse, float[] specular) {
this.id = id;
this.position = BufferUtils.createFloatBuffer(4);
this.position.put(new float[] { position.x, position.y, position.z, 1.0f }).flip();
GL11.glLight(id, GL11.GL_POSITION, this.position);
setColor(ambient, diffuse, specular);
}
/**
* Sets light to current position; does not change position vector
*/
public void updatePosition() {
GL11.glLight(id, GL11.GL_POSITION, position);
}
/**
* Only sets position attribute, does not actually set the light. Call
* updatePosition afterwards to do that
*/
public void setPosition(Vector3f position) {
this.position.put(new float[] { position.x, position.y, position.z, 1.0f }).flip();
}
public int getId() {
return id;
}
public void setColor(float[] ambient, float[] diffuse, float[] specular) {
FloatBuffer lightColor = BufferUtils.createFloatBuffer(4);
lightColor.put(ambient).flip();
GL11.glLight(id, GL11.GL_AMBIENT, lightColor);
lightColor.put(diffuse).flip();
GL11.glLight(id, GL11.GL_DIFFUSE, lightColor);
lightColor.put(specular).flip();
GL11.glLight(id, GL11.GL_SPECULAR, lightColor);
}
}