Skip to content
Snippets Groups Projects
Commit ab5b002e authored by Florian Hölzl's avatar Florian Hölzl
Browse files

some more light

refs 881
parent 1af6131f
No related branches found
No related tags found
No related merge requests found
......@@ -19,17 +19,13 @@ package org.fortiss.tooling.graphicsGL.ui.light;
import static org.fortiss.tooling.graphicsGL.ui.util.FloatBufferUtils.toFloatBuffer;
import static org.fortiss.tooling.graphicsGL.util.Graphics3DModelElementFactory.color;
import static org.lwjgl.opengl.GL11.GL_DIFFUSE;
import static org.lwjgl.opengl.GL11.GL_LIGHT0;
import static org.lwjgl.opengl.GL11.GL_POSITION;
import static org.lwjgl.opengl.GL11.GL_SPECULAR;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glEnable;
import static org.lwjgl.opengl.GL11.glLight;
import java.nio.FloatBuffer;
import org.fortiss.tooling.graphicsGL.model.Color3D;
import org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives;
/**
* Class representing a light source. It is initialized with a GL light number (GL_LIGHT0, ...,
......@@ -48,8 +44,13 @@ public class Light {
/** Constructor. */
public Light(int glLight, Color3D color) {
this(glLight, color, color, color);
}
/** Constructor. */
public Light(int glLight, Color3D ambient, Color3D diffuse, Color3D specular) {
glLightNumber = glLight;
setLightColor(color);
setLightColor(ambient, diffuse, specular);
setPosition(10.0f, 10.0f, 10.0f);
}
......@@ -64,13 +65,17 @@ public class Light {
}
/** Sets the light color. */
public final void setLightColor(Color3D color) {
diffuseColor = toFloatBuffer(color.getRed(), color.getGreen(), color.getBlue(), 1.0f);
specularColor = toFloatBuffer(1.0f, 1.0f, 1.0f, 1.0f);
public final void setLightColor(Color3D ambient, Color3D diffuse, Color3D specular) {
ambientColor = toFloatBuffer(ambient.getRed(), ambient.getGreen(), ambient.getBlue(), 1.0f);
diffuseColor = toFloatBuffer(diffuse.getRed(), diffuse.getGreen(), diffuse.getBlue(), 1.0f);
specularColor =
toFloatBuffer(specular.getRed(), specular.getGreen(), specular.getBlue(), 1.0f);
}
/** The position. */
private FloatBuffer lightPosition;
/** The ambient color. */
private FloatBuffer ambientColor;
/** The diffuse color. */
private FloatBuffer diffuseColor;
/** The specular color. */
......@@ -78,10 +83,8 @@ public class Light {
/** Enables the light in GL. */
public void enableLight() {
glEnable(glLightNumber);
glLight(glLightNumber, GL_POSITION, lightPosition);
glLight(glLightNumber, GL_DIFFUSE, diffuseColor);
glLight(glLightNumber, GL_SPECULAR, specularColor);
GLPrimitives.enableLight(glLightNumber, lightPosition, ambientColor, diffuseColor,
specularColor);
}
/** Disables the light in GL. */
......
......@@ -182,8 +182,8 @@ public class GLPrimitives {
public static void drawMaterialGroups(List<MaterialGroup3D> groups) {
for(MaterialGroup3D g : groups) {
Material3D mat = g.getMaterial() == null ? DEFAULT_MATERIAL : g.getMaterial();
setMaterial(mat);
setSmoothShading(g.isSmoothShading());
setMaterial(mat);
drawTriangleFaces(g.getFacesList());
}
}
......
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Ns 100.000000
Ka 0.200000 0.200000 0.200000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
......
# Blender MTL File: 'None'
# Material Count: 1
newmtl Material.001
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Ns 100.000000
Ka 0.200000 0.200000 0.200000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
......
......@@ -66,10 +66,21 @@ public class Scene3DModelElementFactory {
return l;
}
/** Creates a 3D light at the given position and the given light component colors. */
public static Light3D light3D(float x, float y, float z, Color3D ambient, Color3D diffuse,
Color3D specular) {
Light3D l = SceneFactory.eINSTANCE.createLight3D();
l.setPosition(vector(x, y, z));
l.setAmbient(copy(ambient));
l.setDiffuse(copy(diffuse));
l.setSpecular(copy(specular));
return l;
}
/** Creates a named 3D light at the given position and the given diffuse color. */
public static Light3D light3D(String name, String comment, float x, float y, float z,
Color3D color) {
Light3D l = light3D(x, y, z, color);
Color3D ambient, Color3D diffuse, Color3D specular) {
Light3D l = light3D(x, y, z, ambient, diffuse, specular);
l.setName(name);
l.setComment(comment);
return l;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment