From b62e2e535989a9a22dcb534f4fe1555d3ca09e40 Mon Sep 17 00:00:00 2001 From: Florian Hoelzl <hoelzl@fortiss.org> Date: Mon, 9 Apr 2018 12:40:05 +0000 Subject: [PATCH] YELLOW. refs 3373 --- .../tooling/graphicsGL/ui/light/.ratings | 2 +- .../tooling/graphicsGL/ui/light/Light.java | 10 ++- .../tooling/graphicsGL/ui/objects/.ratings | 9 +-- .../ui/objects/Graph3DViewObject.java | 3 - .../tooling/graphicsGL/ui/util/.ratings | 5 +- .../graphicsGL/ui/util/GLPrimitives.java | 73 ++++++++----------- .../graphicsGL/ui/util/Graph3DUtil.java | 4 +- 7 files changed, 45 insertions(+), 61 deletions(-) diff --git a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/light/.ratings b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/light/.ratings index 7c64f00d4..424dae935 100644 --- a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/light/.ratings +++ b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/light/.ratings @@ -1,2 +1,2 @@ -Light.java f82af2c1972b1a9d6119450a71e539a17748183d RED +Light.java c8f4ab5999b0e1b4bae3af58dff50fd2b5374521 YELLOW Light3DLight.java 8471120e5c7c1f19f52e4052e324884d8d8a01f4 GREEN diff --git a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/light/Light.java b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/light/Light.java index d5b3b26d3..1d9a1c263 100644 --- a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/light/Light.java +++ b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/light/Light.java @@ -35,6 +35,10 @@ import org.fortiss.tooling.graphicsGL.ui.util.GLPrimitives; * @author hoelzl */ public class Light { + /** W coordinate for point lights. */ + private static final float POINT_LIGHT_W = 1.0f; + /** W coordinate for directional lights. */ + private static final float DIRECTIONAL_LIGHT_W = 0.0f; /** The GL_LIGHTx to be used. */ private final int glLightNumber; @@ -97,15 +101,15 @@ public class Light { /** Sets the light position. */ public void setPosition(float x, float y, float z) { - // TODO (SB, 14) + // copy light type from current light => get(3) returns W coordinate lightPosition = toFloatBuffer(new float[] {x, y, z, lightPosition.get(3)}); } /** Switches between directional and point light source. */ public void setDirectional(boolean directional) { - // TODO (SB, 14) + // copy light position from current light => get() return XYZ coordinates lightPosition = toFloatBuffer(new float[] {lightPosition.get(0), lightPosition.get(1), - lightPosition.get(2), directional ? 0.0f : 1.0f}); + lightPosition.get(2), directional ? DIRECTIONAL_LIGHT_W : POINT_LIGHT_W}); } } diff --git a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/objects/.ratings b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/objects/.ratings index efe35e5f1..4a7d8eec3 100644 --- a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/objects/.ratings +++ b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/objects/.ratings @@ -1,9 +1,2 @@ - -CompositeViewObject.java 879fc2f6979666d0aee80dce656b488589fed9d1 GREEN -Graph3DViewObject.java 2ab8d5c1f3ed2212351b873c58157b8815a02969 GREEN -Object3DViewObject.java 2479550fe19cc64cd6ea28585bb1f75840b06109 GREEN -PickableObjectBase.java 8bc5f3b543b26fa0e6b28a63ca9520589bad252b GREEN -RotatedObject.java f2e75c5aea9d128371c86fa3a449052390c76d54 GREEN -ScaledObject.java 59fa121e54e5b4be689714b2ee6f0972ae5d6497 GREEN +Graph3DViewObject.java c427f056f46f71175b180d490cd7f7d299156db2 YELLOW ViewObjectBase.java 2fbcf09f17655c06abffaeb00dbc558e711404eb GREEN -WrappedViewObjectBase.java bb499adfc59ecb43c59f8f3b8ed88505688e2beb GREEN diff --git a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/objects/Graph3DViewObject.java b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/objects/Graph3DViewObject.java index c79571960..4c327532c 100644 --- a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/objects/Graph3DViewObject.java +++ b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/objects/Graph3DViewObject.java @@ -127,7 +127,6 @@ public class Graph3DViewObject extends ViewObjectBase { } setColor(WHITE); - } /** Renders objects as billboards at the given position */ @@ -154,7 +153,6 @@ public class Graph3DViewObject extends ViewObjectBase { } renderText(camera, toRender, pos); - } /** Renders objects as billboards at the given position */ @@ -196,7 +194,6 @@ public class Graph3DViewObject extends ViewObjectBase { } restoreMatrix(); - } /** {@inheritDoc} */ diff --git a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/util/.ratings b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/util/.ratings index 105eb90ef..be510a215 100644 --- a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/util/.ratings +++ b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/util/.ratings @@ -1,5 +1,4 @@ - ColorUtil.java 0eced71852172ba1bb4b3ab9c2a0371665ac209b GREEN FloatBufferUtils.java c1b35aa2e32d25d12780d7b552333cfb7d84c4d8 GREEN -GLPrimitives.java b5d93a42e4e31c77d24c7e1bcd712dd44ec0ba95 RED -Graph3DUtil.java 98c5fbfb65ef4322e0d5bc73654168cb9b57deb2 RED +GLPrimitives.java 098d95dc842de55e17c0f43d674845a5862c927a YELLOW +Graph3DUtil.java 22455f060d5f0866d0fd0e1ba512bf3d4139495b YELLOW diff --git a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/util/GLPrimitives.java b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/util/GLPrimitives.java index 982fbca9c..9404d153d 100644 --- a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/util/GLPrimitives.java +++ b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/util/GLPrimitives.java @@ -135,8 +135,9 @@ public class GLPrimitives { /** Initializes basic GL properties for 3D rendering. */ public static void initializeGLfor3D(int width, int height, float fieldOfViewAngle, float aspect, float nearDistance, float farDistance) { - // TODO (SB, 13): Introduce constants, or add a short comment about what this section does. + // set RGBA clear (i.e. background) color to 100% black glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + // set RGBA color (i.e. foreground) to 100% white glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glClearDepth(1.0); @@ -171,7 +172,6 @@ public class GLPrimitives { glOrtho(0, width, height, 0, 1, -1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - } /** @@ -179,14 +179,16 @@ public class GLPrimitives { * object picker. This method returns the hits counted during picking render run. The results of * the picking run are stored. */ - // TODO(SB, 13,14): get(0), get(1), ... public static int startPickingModeAndCountHits(int x, int y, Vector3f perspective, IntBuffer viewport, ViewObjectBase scene, ModelObjectPicker picker, IntBuffer selectBuffer, Camera c) { glGetIntegerv(GL_VIEWPORT, viewport); - float aspect = - (float)(viewport.get(2) - viewport.get(0)) / - (float)(viewport.get(3) - viewport.get(1)); + // viewport buffer is four coordinates: lower left XY and upper right XY + float llx = viewport.get(0); + float lly = viewport.get(1); + float urx = viewport.get(2); + float ury = viewport.get(3); + float aspect = (urx - llx) / (ury - lly); glSelectBuffer(selectBuffer); glRenderMode(GL_SELECT); @@ -196,7 +198,7 @@ public class GLPrimitives { glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - GLU.gluPickMatrix(x, viewport.get(3) - y, 5.0f, 5.0f, viewport); + GLU.gluPickMatrix(x, ury - y, 5.0f, 5.0f, viewport); GLU.gluPerspective(perspective.x, aspect, perspective.y, perspective.z); // render objects in picking mode @@ -216,18 +218,21 @@ public class GLPrimitives { } /** Returns the current transformed origin in model view coordinates. */ - // TODO(SB, 13,14): get(0), get(1), ... public static Vector3f getTransformedOrigin() { + // load 4x4 model-view matrix from GL context FloatBuffer fb = createFloatBuffer(16); glGetFloatv(GL_MODELVIEW_MATRIX, fb); + // return the transformed zero vector, i.e., first three elements + // of the fourth column of the matrix return new Vector3f(fb.get(12), fb.get(13), fb.get(14)); } /** Returns the given vector in model view coordinates. */ - // TODO(SB, 13,14): get(0), get(1), ... public static Vector3f getTransformedVector(Vector3D v) { + // load 4x4 model-view matrix from GL context FloatBuffer fb = createFloatBuffer(16); glGetFloatv(GL_MODELVIEW_MATRIX, fb); + // perform matrix multiplication with the given vector float x = fb.get(0) * v.getX() + fb.get(4) * v.getY() + fb.get(8) * v.getZ() + fb.get(12); float y = fb.get(1) * v.getX() + fb.get(5) * v.getY() + fb.get(9) * v.getZ() + fb.get(13); float z = fb.get(2) * v.getX() + fb.get(6) * v.getY() + fb.get(10) * v.getZ() + fb.get(14); @@ -373,9 +378,6 @@ public class GLPrimitives { /** Sets the current material data for GL_FRONT faces. */ public static void setMaterial(FloatBuffer ambient, FloatBuffer diffuse, FloatBuffer specular, float specularCoeff) { - // TODO (SB, 1) - // glDisable(GL_COLOR_MATERIAL); - // glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glMaterialfv(GL_FRONT, GL_AMBIENT, ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, specular); @@ -424,10 +426,26 @@ public class GLPrimitives { glLoadIdentity(); } - /** Creates a transformation matrix for billboards. Result is stored in bbmat */ + /** + * Creates a transformation matrix for billboards (rectangular shape that always faces towards + * the camera. Result is stored in {@code bbmat} and can be provided directly to + * {@link #multiplyCurrentMatrixWith(float[])}. + * + * @param bbmat + * the return value 4x4 matrix (MUST be of size 16) + * @param right + * the vector to the right of the {@code look} vector (usually cross product of + * {@code look} and {@code up}. + * @param up + * the vector to up from the {@code look} vector, i.e., camera up (usually Z axis) + * @param look + * the vector from camera location to {@code pos} + * @param pos + * the vector of the billboard object location + */ + // TODO: https://af3-developer.fortiss.org/issues/3372 public static void createBillboardMatrix(float[] bbmat, Vector3f right, Vector3f up, Vector3f look, Vector3f pos) { - // TODO(SB, 13): Add pointer to documentation? bbmat[0] = right.x; bbmat[1] = right.y; bbmat[2] = right.z; @@ -445,31 +463,6 @@ public class GLPrimitives { bbmat[13] = pos.y; bbmat[14] = pos.z; bbmat[15] = 1; - - } - - /** Creates a transformation matrix for billboards. Result is stored in bbmat */ - public static void createBillboardMatrix2(float[] bbmat, Vector3f right, Vector3f up, - Vector3f look, Vector3f pos) { - // TODO(SB, 13): Add pointer to documentation? - bbmat[0] = right.x; - bbmat[1] = right.y; - bbmat[2] = right.z; - bbmat[3] = 0; - bbmat[4] = up.x; - bbmat[5] = up.y; - bbmat[6] = up.z; - bbmat[7] = 0; - bbmat[8] = look.x; - bbmat[9] = look.y; - bbmat[10] = look.z; - bbmat[11] = 0; - // Add the translation in as well. - bbmat[12] = pos.x; - bbmat[13] = pos.y; - bbmat[14] = pos.z; - bbmat[15] = 0; - } /** Prepare a name for the given object and picker. */ @@ -544,7 +537,5 @@ public class GLPrimitives { v.y /= length; v.z /= length; return v; - } - } diff --git a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/util/Graph3DUtil.java b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/util/Graph3DUtil.java index 2a0c430c1..57515eb22 100644 --- a/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/util/Graph3DUtil.java +++ b/org.fortiss.tooling.graphicsGL.ui/trunk/src/org/fortiss/tooling/graphicsGL/ui/util/Graph3DUtil.java @@ -135,8 +135,8 @@ public class Graph3DUtil { try { List<String> objData = getStringContentFromResource(PLUGIN_ID, modelPath + ".obj"); List<String> mtlData = getStringContentFromResource(PLUGIN_ID, modelPath + ".mtl"); - - // TODO (SB, 14) + // we assume that the object file contains at least one object and and all but the + // first one are ignored return new OBJLoaderUtil(objData, mtlData).getLoadedObjects().get(0); } catch(Exception ex) { error(getDefault(), ex.getMessage(), ex); -- GitLab