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

fixed gl light

refs 995
parent b3123da8
No related branches found
No related tags found
No related merge requests found
......@@ -56,7 +56,7 @@ public class Light {
glLightNumber = glLight;
setLightColor(ambient, diffuse, specular);
// point light source at 1,1,1
lightPosition = toFloatBuffer(new float[] {1.0f, 1.0f, 1.0f, 0.0f});
lightPosition = toFloatBuffer(new float[] {1.0f, 1.0f, 1.0f, 1.0f});
this.attenuation = attenuation;
}
......
......@@ -59,7 +59,6 @@ import static org.lwjgl.opengl.GL11.glBlendFunc;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glClearColor;
import static org.lwjgl.opengl.GL11.glClearDepth;
import static org.lwjgl.opengl.GL11.glColor3f;
import static org.lwjgl.opengl.GL11.glColor4f;
import static org.lwjgl.opengl.GL11.glColorMaterial;
import static org.lwjgl.opengl.GL11.glCullFace;
......@@ -140,7 +139,7 @@ public class GLPrimitives {
public static void initializeGLfor3D(int width, int height, float fieldOfViewAngle,
float aspect, float nearDistance, float farDistance) {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glColor3f(1.0f, 1.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glClearDepth(1.0);
glLineWidth(2);
......@@ -315,6 +314,9 @@ public class GLPrimitives {
glBegin(GL_TRIANGLES);
for(Face3D f : faces) {
boolean useNormals = f.getNormalsLength() == 3;
if(!useNormals) {
System.out.println("normals length = " + f.getNormalsLength());
}
for(int i = 0; i < 3; i++) {
if(useNormals) {
Normal3D n = f.getNormals(i);
......@@ -350,7 +352,8 @@ public class GLPrimitives {
/** Sets the current material data for GL_FRONT faces. */
public static void setMaterial(FloatBuffer ambient, FloatBuffer diffuse, FloatBuffer specular,
float specularCoeff) {
glDisable(GL_COLOR_MATERIAL);
// glDisable(GL_COLOR_MATERIAL);
// glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glMaterial(GL_FRONT, GL_AMBIENT, ambient);
glMaterial(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterial(GL_FRONT, GL_SPECULAR, specular);
......@@ -367,7 +370,6 @@ public class GLPrimitives {
public static void enableLight(int glLightNumber, FloatBuffer lightPosition,
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);
......@@ -375,6 +377,7 @@ public class GLPrimitives {
glLightf(glLightNumber, GL_CONSTANT_ATTENUATION, constAtt);
glLightf(glLightNumber, GL_LINEAR_ATTENUATION, linAtt);
glLightf(glLightNumber, GL_QUADRATIC_ATTENUATION, quadAtt);
glEnable(glLightNumber);
}
/** Enables the given light with the given number and model data. */
......
......@@ -57,20 +57,16 @@
<eSubpackages name="mesh" nsURI="http://www.fortiss.org/tooling/graphics3D/mesh"
nsPrefix="org-fortiss-tooling-graphics3D-mesh">
<eClassifiers xsi:type="ecore:EClass" name="Mesh3D">
<eStructuralFeatures xsi:type="ecore:EReference" name="vertices" upperBound="-1"
eType="#//mesh/Vertex3D" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="normals" upperBound="-1"
eType="#//mesh/Normal3D" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="materialGroups" upperBound="-1"
eType="#//mesh/MaterialGroup3D" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Vertex3D" eSuperTypes="#//Vector3D"/>
<eClassifiers xsi:type="ecore:EClass" name="Normal3D" eSuperTypes="#//Vector3D"/>
<eClassifiers xsi:type="ecore:EClass" name="Face3D">
<eStructuralFeatures xsi:type="ecore:EReference" name="vertices" upperBound="-1"
eType="#//mesh/Vertex3D"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="normals" upperBound="-1"
eType="#//mesh/Normal3D"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="vertices" unique="false"
upperBound="-1" eType="#//mesh/Vertex3D" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="normals" unique="false"
upperBound="-1" eType="#//mesh/Normal3D" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Material3D" eSuperTypes="#//LightSystemEntity3DBase">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="specularCoeff" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EFloat"/>
......
......@@ -55,8 +55,6 @@
<nestedGenPackages prefix="Mesh" basePackage="org.fortiss.tooling.graphicsGL.model"
disposableProviderFactory="true" ecorePackage="graphics3D.ecore#//mesh">
<genClasses ecoreClass="graphics3D.ecore#//mesh/Mesh3D">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference graphics3D.ecore#//mesh/Mesh3D/vertices"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference graphics3D.ecore#//mesh/Mesh3D/normals"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference graphics3D.ecore#//mesh/Mesh3D/materialGroups"/>
</genClasses>
<genClasses ecoreClass="graphics3D.ecore#//mesh/Vertex3D"/>
......
......@@ -62,9 +62,9 @@ public class Mesh3DModelElementFactory {
/** Creates a triangular face without normals. */
public static Face3D triangleFace(Vertex3D v1, Vertex3D v2, Vertex3D v3) {
Face3D face = MeshFactory.eINSTANCE.createFace3D();
face.getVerticesList().add(v1);
face.getVerticesList().add(v2);
face.getVerticesList().add(v3);
face.getVerticesList().add(vertex(v1.getX(), v1.getY(), v1.getZ()));
face.getVerticesList().add(vertex(v2.getX(), v2.getY(), v2.getZ()));
face.getVerticesList().add(vertex(v3.getX(), v3.getY(), v3.getZ()));
return face;
}
......@@ -72,19 +72,19 @@ public class Mesh3DModelElementFactory {
public static Face3D triangleFace(Vertex3D v1, Vertex3D v2, Vertex3D v3, Normal3D n1,
Normal3D n2, Normal3D n3) {
Face3D f = triangleFace(v1, v2, v3);
f.getNormalsList().add(n1);
f.getNormalsList().add(n2);
f.getNormalsList().add(n3);
f.getNormalsList().add(normal(n1.getX(), n1.getY(), n1.getZ()));
f.getNormalsList().add(normal(n2.getX(), n2.getY(), n2.getZ()));
f.getNormalsList().add(normal(n3.getX(), n3.getY(), n3.getZ()));
return f;
}
/** Creates a quad face without normals. */
public static Face3D quadFace(Vertex3D v1, Vertex3D v2, Vertex3D v3, Vertex3D v4) {
Face3D face = MeshFactory.eINSTANCE.createFace3D();
face.getVerticesList().add(v1);
face.getVerticesList().add(v2);
face.getVerticesList().add(v3);
face.getVerticesList().add(v4);
face.getVerticesList().add(vertex(v1.getX(), v1.getY(), v1.getZ()));
face.getVerticesList().add(vertex(v2.getX(), v2.getY(), v2.getZ()));
face.getVerticesList().add(vertex(v3.getX(), v3.getY(), v3.getZ()));
face.getVerticesList().add(vertex(v4.getX(), v4.getY(), v4.getZ()));
return face;
}
......@@ -92,29 +92,20 @@ public class Mesh3DModelElementFactory {
public static Face3D quadFace(Vertex3D v1, Vertex3D v2, Vertex3D v3, Vertex3D v4, Normal3D n1,
Normal3D n2, Normal3D n3, Normal3D n4) {
Face3D f = quadFace(v1, v2, v3, v4);
f.getNormalsList().add(n1);
f.getNormalsList().add(n2);
f.getNormalsList().add(n3);
f.getNormalsList().add(n4);
f.getNormalsList().add(normal(n1.getX(), n1.getY(), n1.getZ()));
f.getNormalsList().add(normal(n2.getX(), n2.getY(), n2.getZ()));
f.getNormalsList().add(normal(n3.getX(), n3.getY(), n3.getZ()));
f.getNormalsList().add(normal(n4.getX(), n4.getY(), n4.getZ()));
return f;
}
/** Creates a mesh with the given vertices and faces. */
public static Mesh3D mesh(List<Vertex3D> vertices, List<MaterialGroup3D> groups) {
public static Mesh3D mesh(List<MaterialGroup3D> groups) {
Mesh3D m = MeshFactory.eINSTANCE.createMesh3D();
m.getVerticesList().addAll(vertices);
m.getMaterialGroupsList().addAll(groups);
return m;
}
/** Creates a mesh with the given vertices, normals, and faces. */
public static Mesh3D mesh(List<Vertex3D> vertices, List<Normal3D> normals,
List<MaterialGroup3D> groups) {
Mesh3D m = mesh(vertices, groups);
m.getNormalsList().addAll(normals);
return m;
}
/** The default material with 0.4 ambient, 0.8 diffuse and 1.0 specular property. */
public static final Material3D DEFAULT_MATERIAL = material(color(0.4f, 0.4f, 0.4f),
color(0.8f, 0.8f, 0.8f), color(1.0f, 1.0f, 1.0f), 1.0f);
......
......@@ -145,9 +145,7 @@ public class OBJLoaderUtil {
/** Adds an object if some faces exists and clear temporary data. */
private void addObject(List<Object3D> result) {
if(!matGroups.isEmpty()) {
Mesh3D mesh =
normals.isEmpty() ? mesh(vertices, matGroups) : mesh(vertices, normals,
matGroups);
Mesh3D mesh = mesh(matGroups);
result.add(object3D(objectName, "", 0, 0, 0, mesh));
objectName = null;
material = null;
......
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