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

fixed lighting system

added eCar model
refs 490
parent cf536da1
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ $Id$
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.X_UNIT_VECTOR;
import static org.fortiss.tooling.graphicsGL.util.Graphics3DModelElementFactory.color;
import static org.lwjgl.opengl.GL11.GL_LIGHT0;
import static org.lwjgl.opengl.GL11.glDisable;
......@@ -25,6 +26,7 @@ import static org.lwjgl.opengl.GL11.glDisable;
import java.nio.FloatBuffer;
import org.fortiss.tooling.graphicsGL.model.Color3D;
import org.fortiss.tooling.graphicsGL.model.Vector3D;
import org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives;
/**
......@@ -35,7 +37,7 @@ import org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 0CDD15394CBA85A529E6042BE9D98DB3
* @ConQAT.Rating YELLOW Hash: AC7E1A73FC5F9AAAD349EA38CF463FA9
*/
public class Light {
......@@ -44,14 +46,17 @@ public class Light {
/** Constructor. */
public Light(int glLight, Color3D color) {
this(glLight, color, color, color);
// use 1,0,0 for attenuation, e.g. constant attenuation only
this(glLight, color, color, color, X_UNIT_VECTOR);
}
/** Constructor. */
public Light(int glLight, Color3D ambient, Color3D diffuse, Color3D specular) {
public Light(int glLight, Color3D ambient, Color3D diffuse, Color3D specular,
Vector3D attenuation) {
glLightNumber = glLight;
setLightColor(ambient, diffuse, specular);
setPosition(10.0f, 10.0f, 10.0f);
this.attenuation = attenuation;
}
/** Constructor using GL_LIGHT0 and white light color. */
......@@ -80,11 +85,13 @@ public class Light {
private FloatBuffer diffuseColor;
/** The specular color. */
private FloatBuffer specularColor;
/** The attenuation. */
private Vector3D attenuation;
/** Enables the light in GL. */
public void enableLight() {
GLPrimitives.enableLight(glLightNumber, lightPosition, ambientColor, diffuseColor,
specularColor);
specularColor, attenuation.getX(), attenuation.getY(), attenuation.getZ());
}
/** Disables the light in GL. */
......
......@@ -25,6 +25,7 @@ import static org.lwjgl.opengl.GL11.GL_AMBIENT_AND_DIFFUSE;
import static org.lwjgl.opengl.GL11.GL_BACK;
import static org.lwjgl.opengl.GL11.GL_BLEND;
import static org.lwjgl.opengl.GL11.GL_COLOR_MATERIAL;
import static org.lwjgl.opengl.GL11.GL_CONSTANT_ATTENUATION;
import static org.lwjgl.opengl.GL11.GL_CULL_FACE;
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
import static org.lwjgl.opengl.GL11.GL_DIFFUSE;
......@@ -32,6 +33,7 @@ import static org.lwjgl.opengl.GL11.GL_FLAT;
import static org.lwjgl.opengl.GL11.GL_FRONT;
import static org.lwjgl.opengl.GL11.GL_LIGHTING;
import static org.lwjgl.opengl.GL11.GL_LIGHT_MODEL_AMBIENT;
import static org.lwjgl.opengl.GL11.GL_LINEAR_ATTENUATION;
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;
......@@ -40,6 +42,7 @@ 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;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.GL_QUADRATIC_ATTENUATION;
import static org.lwjgl.opengl.GL11.GL_SHININESS;
import static org.lwjgl.opengl.GL11.GL_SMOOTH;
import static org.lwjgl.opengl.GL11.GL_SPECULAR;
......@@ -62,6 +65,7 @@ import static org.lwjgl.opengl.GL11.glGetFloat;
import static org.lwjgl.opengl.GL11.glHint;
import static org.lwjgl.opengl.GL11.glLight;
import static org.lwjgl.opengl.GL11.glLightModel;
import static org.lwjgl.opengl.GL11.glLightf;
import static org.lwjgl.opengl.GL11.glLineWidth;
import static org.lwjgl.opengl.GL11.glLoadIdentity;
import static org.lwjgl.opengl.GL11.glMaterial;
......@@ -104,7 +108,7 @@ import org.newdawn.slick.Color;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 6F2D8EAA1CFCDD329905A23798CC07F5
* @ConQAT.Rating YELLOW Hash: FD36B29479F2CA453A2A0F7399F2AB2E
*/
public class GLPrimitives {
/** The X unit vector. */
......@@ -308,19 +312,24 @@ public class GLPrimitives {
/** Enables the light with the given number and properties. */
public static void enableLight(int glLightNumber, FloatBuffer lightPosition,
FloatBuffer ambient, FloatBuffer diffuse, FloatBuffer specular) {
FloatBuffer ambient, FloatBuffer diffuse, FloatBuffer specular, float constAtt,
float linAtt, float quadAtt) {
glEnable(glLightNumber);
glLight(glLightNumber, GL_POSITION, lightPosition);
glLight(glLightNumber, GL_AMBIENT, ambient);
glLight(glLightNumber, GL_DIFFUSE, diffuse);
glLight(glLightNumber, GL_SPECULAR, specular);
glLightf(glLightNumber, GL_CONSTANT_ATTENUATION, constAtt);
glLightf(glLightNumber, GL_LINEAR_ATTENUATION, linAtt);
glLightf(glLightNumber, GL_QUADRATIC_ATTENUATION, quadAtt);
}
/** 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),
toFloatBuffer(light.getAmbient(), 1.0f), toFloatBuffer(light.getDiffuse(), 1.0f),
toFloatBuffer(light.getSpecular(), 1.0f));
toFloatBuffer(light.getSpecular(), 1.0f), light.getConstantAttenuation(),
light.getLinearAttenuation(), light.getQuadraticAttenuation());
}
/** Clears the canvas with the given RGB color. */
......
......@@ -93,7 +93,25 @@
<eStructuralFeatures xsi:type="ecore:EReference" name="lookAtLocation" eType="#//Vector3D"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Light3D" eSuperTypes="#//LightSystemEntity3DBase #//Positioned3DBase platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedCommentedElement"/>
<eClassifiers xsi:type="ecore:EClass" name="Light3D" eSuperTypes="#//LightSystemEntity3DBase #//Positioned3DBase platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedCommentedElement">
<eOperations name="getConstantAttenuation" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="if (this.getAttenuation() != null) {&#xA;return this.getAttenuation().getX();&#xA;}&#xA;return 1.0f;"/>
</eAnnotations>
</eOperations>
<eOperations name="getLinearAttenuation" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="if (this.getAttenuation() != null) {&#xA;return this.getAttenuation().getY();&#xA;}&#xA;return 0.0f;"/>
</eAnnotations>
</eOperations>
<eOperations name="getQuadraticAttenuation" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="if (this.getAttenuation() != null) {&#xA;return this.getAttenuation().getZ();&#xA;}&#xA;return 0.0f;"/>
</eAnnotations>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EReference" name="attenuation" eType="#//Vector3D"
containment="true"/>
</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"
eType="#//scene/Camera3D" containment="true"/>
......
......@@ -84,7 +84,13 @@
<genClasses ecoreClass="graphics3D.ecore#//scene/Camera3D">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference graphics3D.ecore#//scene/Camera3D/lookAtLocation"/>
</genClasses>
<genClasses ecoreClass="graphics3D.ecore#//scene/Light3D"/>
<genClasses ecoreClass="graphics3D.ecore#//scene/Light3D">
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference graphics3D.ecore#//scene/Light3D/attenuation"/>
<genOperations ecoreOperation="graphics3D.ecore#//scene/Light3D/getConstantAttenuation"/>
<genOperations ecoreOperation="graphics3D.ecore#//scene/Light3D/getLinearAttenuation"/>
<genOperations ecoreOperation="graphics3D.ecore#//scene/Light3D/getQuadraticAttenuation"/>
</genClasses>
<genClasses ecoreClass="graphics3D.ecore#//scene/Scene3D">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference graphics3D.ecore#//scene/Scene3D/cameras"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference graphics3D.ecore#//scene/Scene3D/lights"/>
......
......@@ -37,7 +37,7 @@ import org.fortiss.tooling.graphicsGL.model.scene.ScenePackage;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: BC758CC15FA6D352DB611691B4B545FE
* @ConQAT.Rating YELLOW Hash: 5508CD6402B210EF8E4C20DBFFC04C2E
*/
public class Scene3DModelElementFactory {
......@@ -74,6 +74,7 @@ public class Scene3DModelElementFactory {
l.setAmbient(copy(ambient));
l.setDiffuse(copy(diffuse));
l.setSpecular(copy(specular));
l.setAttenuation(vector(1.0f, 0.0f, 0.0f));
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