com.jogamp.opengl.math.FloatUtil Java Examples

The following examples show how to use com.jogamp.opengl.math.FloatUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HelloTriangleSimple.java    From hello-triangle with MIT License 6 votes vote down vote up
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

    GL3 gl = drawable.getGL().getGL3();

    float[] ortho = new float[16];
    FloatUtil.makeOrtho(ortho, 0, false, -1, 1, -1, 1, 1, -1);
    for (int i = 0; i < 16; i++) {
        matBuffer.put(i, ortho[i]);
    }
    gl.glBindBuffer(GL_UNIFORM_BUFFER, bufferName.get(Buffer.GLOBAL_MATRICES));
    gl.glBufferSubData(GL_UNIFORM_BUFFER, 0, 16 * Float.BYTES, matBuffer);
    gl.glBindBuffer(GL_UNIFORM_BUFFER, 0);

    gl.glViewport(x, y, width, height);
}
 
Example #2
Source File: Glm.java    From jogl-samples with MIT License 6 votes vote down vote up
public static float[] project(float[] obj, float[] model, float[] proj, float[] viewport) {

        float[] tmp = {obj[0], obj[1], obj[2], 1};
        float[] partial = new float[tmp.length];
        FloatUtil.multMatrixVec(model, tmp, partial);
        FloatUtil.multMatrixVec(proj, partial, tmp);

        tmp[0] = tmp[0] / tmp[3] * 0.5f + 0.5f;
        tmp[1] = tmp[1] / tmp[3] * 0.5f + 0.5f;
        tmp[2] = tmp[2] / tmp[3] * 0.5f + 0.5f;
        tmp[3] = 1.0f;

        tmp[0] = tmp[0] * (viewport[2]) + viewport[0];
        tmp[1] = tmp[1] * (viewport[3]) + viewport[1];

        return new float[]{tmp[0], tmp[1], tmp[2]};
    }
 
Example #3
Source File: Glm.java    From jogl-samples with MIT License 6 votes vote down vote up
private static float[] saturation(float s) {

        float[] rgbw = {0.2126f, 0.7152f, 0.0722f};

        float col0 = (1 - s) * rgbw[0];
        float col1 = (1 - s) * rgbw[1];
        float col2 = (1 - s) * rgbw[2];

        float[] result = FloatUtil.makeIdentity(new float[16]);
        result[0 * 4 + 0] = col0 + s;
        result[0 * 4 + 1] = col0;
        result[0 * 4 + 2] = col0;
        result[1 * 4 + 0] = col1;
        result[1 * 4 + 1] = col1 + s;
        result[1 * 4 + 2] = col1;
        result[2 * 4 + 0] = col2;
        result[2 * 4 + 1] = col2;
        result[2 * 4 + 2] = col2 + s;
        return result;
    }
 
Example #4
Source File: GPUUISceneGLListener0A.java    From jogl-samples with MIT License 6 votes vote down vote up
@Override
public void mouseWheelMoved(final MouseEvent e) {
    final Object attachment = e.getAttachment();
    if( attachment instanceof UIShape.PointerEventInfo ) {
        final UIShape.PointerEventInfo shapeEvent = (UIShape.PointerEventInfo)attachment;
        final boolean isOnscreen = PointerClass.Onscreen == e.getPointerType(0).getPointerClass();
        if( 0 == ( ~InputEvent.BUTTONALL_MASK & e.getModifiers() ) && !isOnscreen ) {
            // offscreen vertical mouse wheel zoom
            final float tz = 8f*e.getRotation()[1]; // vertical: wheel
            System.err.println("Rotate.Zoom.W: "+tz);
            shapeEvent.shape.translate(0f, 0f, tz);
        } else if( isOnscreen || e.isControlDown() ) {
            final float[] rot =  VectorUtil.scaleVec3(e.getRotation(), e.getRotation(), FloatUtil.PI / 180.0f);
            if( isOnscreen ) {
                System.err.println("XXX: "+e);
                // swap axis for onscreen rotation matching natural feel
                final float tmp = rot[0]; rot[0] = rot[1]; rot[1] = tmp;
                VectorUtil.scaleVec3(rot, rot, 2f);
            }
            shapeEvent.shape.getRotation().rotateByEuler( rot );
        }
    }
}
 
Example #5
Source File: HelloTriangleSimple.java    From CPE552-Java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

    GL4 gl = drawable.getGL().getGL4();

    // ortho matrix
    float[] ortho = FloatUtil.makeOrtho(new float[16], 0, false, -1f, 1f, -1f, 1f, 1f, -1f);
    globalMatricesPointer.asFloatBuffer().put(ortho);

    gl.glViewport(x, y, width, height);
}
 
Example #6
Source File: HelloTriangleSimple.java    From hello-triangle with MIT License 5 votes vote down vote up
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {

    GL4 gl = drawable.getGL().getGL4();

    // ortho matrix
    float[] ortho = FloatUtil.makeOrtho(new float[16], 0, false, -1f, 1f, -1f, 1f, 1f, -1f);
    globalMatricesPointer.asFloatBuffer().put(ortho);

    gl.glViewport(x, y, width, height);
}
 
Example #7
Source File: SceneUIController.java    From jogl-samples with MIT License 5 votes vote down vote up
private void transformShape(final PMVMatrix pmv, final UIShape uiShape) {
    final float[] uiTranslate = uiShape.getTranslate();
    pmv.glTranslatef(uiTranslate[0], uiTranslate[1], uiTranslate[2]);
    // final float dz = 100f;

    final Quaternion quat = uiShape.getRotation();
    final boolean rotate = !quat.isIdentity();
    final float[] uiScale = uiShape.getScale();
    final boolean scale = !VectorUtil.isVec3Equal(uiScale, 0, VectorUtil.VEC3_ONE, 0, FloatUtil.EPSILON);
    if( rotate || scale ) {
        final float[] rotOrigin = uiShape.getRotationOrigin();
        final boolean pivot = !VectorUtil.isVec3Zero(rotOrigin, 0, FloatUtil.EPSILON);
        // pmv.glTranslatef(0f, 0f, dz);
        if( pivot ) {
            pmv.glTranslatef(rotOrigin[0], rotOrigin[1], rotOrigin[2]);
        }
        if( scale ) {
            pmv.glScalef(uiScale[0], uiScale[1], uiScale[2]);
        }
        if( rotate ) {
            pmv.glRotate(quat);
        }
        if( pivot ) {
            pmv.glTranslatef(-rotOrigin[0], -rotOrigin[1], -rotOrigin[2]);
        }
        // pmv.glTranslatef(0f, 0f, -dz);
    }
}
 
Example #8
Source File: SceneUIController.java    From jogl-samples with MIT License 5 votes vote down vote up
@Override
public int compare(final UIShape s1, final UIShape s2) {
    final float s1Z = s1.getBounds().getMinZ()+s1.getTranslate()[2];
    final float s2Z = s2.getBounds().getMinZ()+s2.getTranslate()[2];
    if( FloatUtil.isEqual(s1Z, s2Z, FloatUtil.EPSILON) ) {
        return 0;
    } else if( s1Z < s2Z ){
        return -1;
    } else {
        return 1;
    }
}
 
Example #9
Source File: SceneUIController.java    From jogl-samples with MIT License 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
private UIShape pickShapeImpl(final int glWinX, final int glWinY, final float[] objPos) {
    final float winZ0 = 0f;
    final float winZ1 = 0.3f;
    /**
        final FloatBuffer winZRB = Buffers.newDirectFloatBuffer(1);
        gl.glReadPixels( x, y, 1, 1, GL2ES2.GL_DEPTH_COMPONENT, GL.GL_FLOAT, winZRB);
        winZ1 = winZRB.get(0); // dir
    */
    final PMVMatrix pmv = renderer.getMatrix();
    pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);

    final Ray ray = new Ray();

    final Object[] shapesS = shapes.toArray();
    Arrays.sort(shapesS, (Comparator)shapeZAscComparator);

    for(int i=shapesS.length-1; i>=0; i--) {
        final UIShape uiShape = (UIShape)shapesS[i];

        if( uiShape.isEnabled() ) {
            pmv.glPushMatrix();
            transformShape(pmv, uiShape);
            final boolean ok = pmv.gluUnProjectRay(glWinX, glWinY, winZ0, winZ1, viewport, 0, ray);
            pmv.glPopMatrix();
            if( ok ) {
                final AABBox sbox = uiShape.getBounds();
                if( sbox.intersectsRay(ray) ) {
                    // System.err.printf("Pick.0: shape %d, [%d, %d, %f/%f] -> %s%n", i, glWinX, glWinY, winZ0, winZ1, ray);
                    if( null == sbox.getRayIntersection(objPos, ray, FloatUtil.EPSILON, true, dpyTmp1V3, dpyTmp2V3, dpyTmp3V3) ) {
                        throw new InternalError("Ray "+ray+", box "+sbox);
                    }
                    // System.err.printf("Pick.1: shape %d @ [%f, %f, %f], within %s%n", i, objPos[0], objPos[1], objPos[2], uiShape.getBounds());
                    return uiShape;
                }
            }
        }
    }
    return null;
}
 
Example #10
Source File: SceneUIController.java    From jogl-samples with MIT License 5 votes vote down vote up
public static void mapWin2ObjectCoords(final PMVMatrix pmv, final int[] view,
                                       final float zNear, final float zFar,
                                       final float orthoX, final float orthoY, final float orthoDist,
                                       final float[] winZ, final float[] objPos) {
    winZ[0] = FloatUtil.getOrthoWinZ(orthoDist, zNear, zFar);
    pmv.gluUnProject(orthoX, orthoY, winZ[0], view, 0, objPos, 0);
}
 
Example #11
Source File: GPUUISceneGLListener0A.java    From jogl-samples with MIT License 4 votes vote down vote up
private void rotateButtons(float[] angdeg) {
    angdeg = VectorUtil.scaleVec3(angdeg, angdeg, FloatUtil.PI / 180.0f);
    for(int i=0; i<buttons.size(); i++) {
        buttons.get(i).getRotation().rotateByEuler( angdeg );
    }
}
 
Example #12
Source File: Glm.java    From jogl-samples with MIT License 2 votes vote down vote up
public static float[] saturation(float s, float[] color) {

        float[] result = FloatUtil.multMatrixVec(saturation(s), new float[]{color[0], color[1], color[2], 0}, new float[4]);

        return new float[]{result[0], result[1], result[2]};
    }