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

added directional flag to light source

refs 930
parent 57dd44b7
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,7 @@ import org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: AC7E1A73FC5F9AAAD349EA38CF463FA9
* @ConQAT.Rating YELLOW Hash: 1DD1C61E561842EF307189371D011749
*/
public class Light {
......@@ -55,7 +55,7 @@ public class Light {
Vector3D attenuation) {
glLightNumber = glLight;
setLightColor(ambient, diffuse, specular);
setPosition(10.0f, 10.0f, 10.0f);
lightPosition = toFloatBuffer(new float[] {1.0f, 1.0f, 1.0f, 1.0f});
this.attenuation = attenuation;
}
......@@ -101,6 +101,13 @@ public class Light {
/** Sets the light position. */
public void setPosition(float x, float y, float z) {
lightPosition = toFloatBuffer(new float[] {x, y, z, 1.0f});
lightPosition = toFloatBuffer(new float[] {x, y, z, lightPosition.get(3)});
}
/** Switches between directional and point light source. */
public void setDirectional(boolean directional) {
lightPosition =
toFloatBuffer(new float[] {lightPosition.get(0), lightPosition.get(1),
lightPosition.get(2), directional ? 1.0f : 0.0f});
}
}
......@@ -38,6 +38,7 @@ import static org.lwjgl.opengl.GL11.GL_LINES;
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_MODELVIEW_MATRIX;
import static org.lwjgl.opengl.GL11.GL_NICEST;
import static org.lwjgl.opengl.GL11.GL_NORMALIZE;
import static org.lwjgl.opengl.GL11.GL_ONE_MINUS_SRC_ALPHA;
import static org.lwjgl.opengl.GL11.GL_PERSPECTIVE_CORRECTION_HINT;
import static org.lwjgl.opengl.GL11.GL_POSITION;
......@@ -108,7 +109,7 @@ import org.newdawn.slick.Color;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: FD36B29479F2CA453A2A0F7399F2AB2E
* @ConQAT.Rating YELLOW Hash: 2B6E5427FE0DE1E18DBA831CC97BECA6
*/
public class GLPrimitives {
/** The X unit vector. */
......@@ -326,7 +327,8 @@ public class GLPrimitives {
/** Enables the given light with the given number and model data. */
public static void enableLight(int glLightNumber, Light3D light) {
enableLight(glLightNumber, toFloatBuffer(light.getPosition(), 1.0f),
enableLight(glLightNumber,
toFloatBuffer(light.getPosition(), light.isDirectional() ? 0.0f : 1.0f),
toFloatBuffer(light.getAmbient(), 1.0f), toFloatBuffer(light.getDiffuse(), 1.0f),
toFloatBuffer(light.getSpecular(), 1.0f), light.getConstantAttenuation(),
light.getLinearAttenuation(), light.getQuadraticAttenuation());
......@@ -362,6 +364,11 @@ public class GLPrimitives {
glCullFace(GL_BACK);
}
/** Enables the normlization for provided normals. */
public static void enableNormalization() {
glEnable(GL_NORMALIZE);
}
/** Enables lighting with the given ambient intensity. */
public static void enableLighting(Color3D col) {
glEnable(GL_LIGHTING);
......
......@@ -111,6 +111,7 @@
</eOperations>
<eStructuralFeatures xsi:type="ecore:EReference" name="attenuation" eType="#//Vector3D"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="directional" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Scene3D" eSuperTypes="platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//IIdLabeled">
<eStructuralFeatures xsi:type="ecore:EReference" name="cameras" upperBound="-1"
......
......@@ -87,6 +87,7 @@
<genClasses ecoreClass="graphics3D.ecore#//scene/Light3D">
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference graphics3D.ecore#//scene/Light3D/attenuation"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute graphics3D.ecore#//scene/Light3D/directional"/>
<genOperations ecoreOperation="graphics3D.ecore#//scene/Light3D/getConstantAttenuation"/>
<genOperations ecoreOperation="graphics3D.ecore#//scene/Light3D/getLinearAttenuation"/>
<genOperations ecoreOperation="graphics3D.ecore#//scene/Light3D/getQuadraticAttenuation"/>
......
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