Search in sources :

Example 1 with Vector4f

use of au.gov.asd.tac.constellation.utilities.graphics.Vector4f in project constellation by constellation-app.

the class AxesRenderable method calcProjectionScale.

private float calcProjectionScale(final int[] viewport) {
    // calculate the number of pixels a scene object of y-length 1 projects to.
    final Vector3f unitPosition = new Vector3f(0, 1, 0);
    final Vector4f proj1 = new Vector4f();
    Graphics3DUtilities.project(ZERO_3F, IDENTITY_44F, viewport, proj1);
    final Vector4f proj2 = new Vector4f();
    Graphics3DUtilities.project(unitPosition, IDENTITY_44F, viewport, proj2);
    final float yScale = proj2.a[1] - proj1.a[1];
    return 25.0F / yScale;
}
Also used : Vector4f(au.gov.asd.tac.constellation.utilities.graphics.Vector4f) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f)

Example 2 with Vector4f

use of au.gov.asd.tac.constellation.utilities.graphics.Vector4f in project constellation by constellation-app.

the class ShaderManager method useStockShader.

/**
 * Use one of the provided shaders and set the shader-specific uniforms.
 *
 * @param gl the current OpenGL context.
 * @param shaderId The id of the shader.
 * @param args The shader-specific uniform arguments.
 *
 * @return the id of the shader.
 */
public int useStockShader(final GL3 gl, final int shaderId, final Object... args) {
    if (shaderId >= SHADER_LAST) {
        throw new RenderException("Invalid shader id.");
    }
    // Bind to the correct shader.
    gl.glUseProgram(stockShaders[shaderId]);
    // Set up the uniforms.
    if (shaderId == SHADER_IDENTITY) {
        // Just the color.
        int colorLoc = gl.glGetUniformLocation(stockShaders[shaderId], V_COLOR);
        float[] color = (float[]) args[0];
        gl.glUniform4fv(colorLoc, 1, color, 0);
    } else if (shaderId == SHADER_FLAT) {
        // The modelview projection matrix and the color.
        int transformLoc = gl.glGetUniformLocation(stockShaders[shaderId], "mvpMatrix");
        Matrix44f mvpMatrix = (Matrix44f) args[0];
        gl.glUniformMatrix4fv(transformLoc, 1, false, mvpMatrix.a, 0);
        int colorLoc = gl.glGetUniformLocation(stockShaders[shaderId], V_COLOR);
        float[] color = (float[]) args[1];
        gl.glUniform4fv(colorLoc, 1, color, 0);
    } else if (shaderId == SHADER_POINT_LIGHT_DIFF) {
        int modelMatrix = gl.glGetUniformLocation(stockShaders[shaderId], "mvMatrix");
        Matrix44f mvMatrix = (Matrix44f) args[0];
        gl.glUniformMatrix4fv(modelMatrix, 1, false, mvMatrix.a, 0);
        int projMatrix = gl.glGetUniformLocation(stockShaders[shaderId], "pMatrix");
        Matrix44f pMatrix = (Matrix44f) args[1];
        gl.glUniformMatrix4fv(projMatrix, 1, false, pMatrix.a, 0);
        int light = gl.glGetUniformLocation(stockShaders[shaderId], "vLightPos");
        Vector3f vLightPos = (Vector3f) args[2];
        gl.glUniform3fv(light, 1, vLightPos.a, 0);
        int colorLoc = gl.glGetUniformLocation(stockShaders[shaderId], V_COLOR);
        float[] color = (float[]) args[3];
        gl.glUniform4fv(colorLoc, 1, color, 0);
    } else if (shaderId == SHADER_TEXTURE_POINT_LIGHT_DIFF) {
        int modelMatrix = gl.glGetUniformLocation(stockShaders[shaderId], "mvMatrix");
        Matrix44f mvMatrix = (Matrix44f) args[0];
        gl.glUniformMatrix4fv(modelMatrix, 1, false, mvMatrix.a, 0);
        int projMatrix = gl.glGetUniformLocation(stockShaders[shaderId], "pMatrix");
        Matrix44f pMatrix = (Matrix44f) args[1];
        gl.glUniformMatrix4fv(projMatrix, 1, false, pMatrix.a, 0);
        int light = gl.glGetUniformLocation(stockShaders[shaderId], "vLightPos");
        Vector3f lightPos = (Vector3f) args[2];
        gl.glUniform3fv(light, 1, lightPos.a, 0);
        int colorLoc = gl.glGetUniformLocation(stockShaders[shaderId], V_COLOR);
        Vector4f color = (Vector4f) args[3];
        gl.glUniform4fv(colorLoc, 1, color.a, 0);
        int textureUnit = gl.glGetUniformLocation(stockShaders[shaderId], "textureUnit0");
        int i = (Integer) args[4];
        gl.glUniform1i(textureUnit, i);
    } else {
        throw new RenderException("Unimplemented shader.");
    }
    return stockShaders[shaderId];
}
Also used : Matrix44f(au.gov.asd.tac.constellation.utilities.graphics.Matrix44f) Vector4f(au.gov.asd.tac.constellation.utilities.graphics.Vector4f) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f)

Example 3 with Vector4f

use of au.gov.asd.tac.constellation.utilities.graphics.Vector4f in project constellation by constellation-app.

the class FPSRenderable method calculateYProjectionScale.

private float calculateYProjectionScale(final int[] viewport) {
    // calculate the number of pixels a scene object of y-length 1 projects to.
    final Vector4f proj1 = new Vector4f();
    Graphics3DUtilities.project(ZERO_3F, IDENTITY_44F, viewport, proj1);
    final Vector4f proj2 = new Vector4f();
    final Vector3f unitPosition = new Vector3f(0, 1, 0);
    Graphics3DUtilities.project(unitPosition, IDENTITY_44F, viewport, proj2);
    final float yScale = proj2.getY() - proj1.getY();
    return (256.0F / 64) / yScale;
}
Also used : Vector4f(au.gov.asd.tac.constellation.utilities.graphics.Vector4f) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f)

Example 4 with Vector4f

use of au.gov.asd.tac.constellation.utilities.graphics.Vector4f in project constellation by constellation-app.

the class Graphics3DUtilities method screenToWorldCoordinates.

/**
 * Converts the supplied point from screen coordinates to world coordinates,
 * placing it on the plane through the supplied position (in world
 * coordinates) normal to the direction the camera is looking
 *
 * @param screenPosition The point in screen coordinates (the z component is
 * ignored as screen coordinates are 2D)
 * @param throughPoint A point on the plane to place the screen position
 * onto.
 * @param modelViewProjectionMatrix The matrix which defines the mapping
 * from screen to world coordinates.
 * @param viewport
 * @param worldPosition
 */
public static void screenToWorldCoordinates(final Vector3f screenPosition, final Vector3f throughPoint, final Matrix44f modelViewProjectionMatrix, final int[] viewport, final Vector3f worldPosition) {
    // Need to screenToWorld the window location into 3D space
    // To screenToWorld, we need Z and W. Instead of making them up, generate them by projecting the throughPoint.
    final Vector4f proj = new Vector4f();
    Graphics3DUtilities.project(throughPoint, modelViewProjectionMatrix, viewport, proj);
    final Vector4f screenLocation = new Vector4f(screenPosition.getX(), viewport[3] - screenPosition.getY(), proj.getZ(), proj.getW());
    Graphics3DUtilities.unproject(screenLocation, modelViewProjectionMatrix, viewport, worldPosition);
}
Also used : Vector4f(au.gov.asd.tac.constellation.utilities.graphics.Vector4f)

Example 5 with Vector4f

use of au.gov.asd.tac.constellation.utilities.graphics.Vector4f in project constellation by constellation-app.

the class Graphics3DUtilitiesNGTest method testProject.

/**
 * Can project a position to the viewing plane.
 */
@Test
public void testProject() {
    final Vector4f v = new Vector4f();
    assertTrue(Graphics3DUtilities.project(new Vector3f(V3_1), copyMatrix(M1), new int[] { 7, 3, 4, 14 }, v));
    assertEquals(v.toString(), new Vector4f(10.976173F, 16.944405F, 0.998015F, 1158.400024F).toString());
}
Also used : Vector4f(au.gov.asd.tac.constellation.utilities.graphics.Vector4f) Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f) Test(org.testng.annotations.Test)

Aggregations

Vector4f (au.gov.asd.tac.constellation.utilities.graphics.Vector4f)9 Vector3f (au.gov.asd.tac.constellation.utilities.graphics.Vector3f)7 Matrix44f (au.gov.asd.tac.constellation.utilities.graphics.Matrix44f)2 Test (org.testng.annotations.Test)2