Search in sources :

Example 6 with Matrix4f

use of org.lwjgl.util.vector.Matrix4f in project j6dof-flight-sim by chris-ali.

the class TerrainRenderer method loadModelMatrix.

private void loadModelMatrix(Terrain terrain) {
    Matrix4f transformationMatrix = RenderingUtilities.createTransformationMatrix(new Vector3f(terrain.getX(), 0, terrain.getZ()), 0, 0, 0, 1);
    terrainShader.loadTransformationMatrix(transformationMatrix);
}
Also used : Matrix4f(org.lwjgl.util.vector.Matrix4f) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 7 with Matrix4f

use of org.lwjgl.util.vector.Matrix4f in project j6dof-flight-sim by chris-ali.

the class WaterRenderer method render.

public void render(List<WaterTile> water, Camera camera) {
    prepareRender(camera);
    for (WaterTile tile : water) {
        Matrix4f modelMatrix = RenderingUtilities.createTransformationMatrix(new Vector3f(tile.getX(), tile.getHeight(), tile.getZ()), 0, 0, 0, WaterTile.TILE_SIZE);
        shader.loadModelMatrix(modelMatrix);
        shader.loadFog(fogDensity, fogGradient);
        shader.loadSkyColor(MasterRenderer.getSkyColor().x, MasterRenderer.getSkyColor().y, MasterRenderer.getSkyColor().z);
        shader.connectTextures();
        GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, quad.getVertexCount());
    }
    unbind();
}
Also used : Matrix4f(org.lwjgl.util.vector.Matrix4f) Vector3f(org.lwjgl.util.vector.Vector3f) WaterTile(com.chrisali.javaflightsim.lwjgl.water.WaterTile)

Example 8 with Matrix4f

use of org.lwjgl.util.vector.Matrix4f in project j6dof-flight-sim by chris-ali.

the class ParticleSystem method generateRandomUnitVectorWithinCone.

private static Vector3f generateRandomUnitVectorWithinCone(Vector3f coneDirection, float angle) {
    float cosAngle = (float) Math.cos(angle);
    Random random = new Random();
    float theta = (float) (random.nextFloat() * 2f * Math.PI);
    float z = cosAngle + (random.nextFloat() * (1 - cosAngle));
    float rootOneMinusZSquared = (float) Math.sqrt(1 - z * z);
    float x = (float) (rootOneMinusZSquared * Math.cos(theta));
    float y = (float) (rootOneMinusZSquared * Math.sin(theta));
    Vector4f direction = new Vector4f(x, y, z, 1);
    if (coneDirection.x != 0 || coneDirection.y != 0 || (coneDirection.z != 1 && coneDirection.z != -1)) {
        Vector3f rotateAxis = Vector3f.cross(coneDirection, new Vector3f(0, 0, 1), null);
        rotateAxis.normalise();
        float rotateAngle = (float) Math.acos(Vector3f.dot(coneDirection, new Vector3f(0, 0, 1)));
        Matrix4f rotationMatrix = new Matrix4f();
        rotationMatrix.rotate(-rotateAngle, rotateAxis);
        Matrix4f.transform(rotationMatrix, direction, direction);
    } else if (coneDirection.z == -1) {
        direction.z *= -1;
    }
    return new Vector3f(direction);
}
Also used : Matrix4f(org.lwjgl.util.vector.Matrix4f) Random(java.util.Random) Vector4f(org.lwjgl.util.vector.Vector4f) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 9 with Matrix4f

use of org.lwjgl.util.vector.Matrix4f in project j6dof-flight-sim by chris-ali.

the class RenderingUtilities method createTransformationMatrix.

/**
 * Creates a transformation matrix for 2D interface items using a 2D Vector for translation and scale
 * and a float for rotation (degrees)
 *
 * @param translation
 * @param rotation
 * @param scale
 * @return 4D transformation matrix
 */
public static Matrix4f createTransformationMatrix(Vector2f translation, float rotation, Vector2f scale) {
    Matrix4f matrix = new Matrix4f();
    matrix.setIdentity();
    Matrix4f.translate(translation, matrix, matrix);
    Matrix4f.scale(new Vector3f(scale.x, scale.y * DisplayManager.getAspectRatio(), 1f), matrix, matrix);
    Matrix4f.rotate((float) Math.toRadians(rotation), new Vector3f(0, 0, 1), matrix, matrix);
    return matrix;
}
Also used : Matrix4f(org.lwjgl.util.vector.Matrix4f) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 10 with Matrix4f

use of org.lwjgl.util.vector.Matrix4f in project DynamicSurroundings by OreCruncher.

the class ShaderUtils method setMVPMatrix.

public static void setMVPMatrix(final String name, final ShaderProgram program) throws ShaderException {
    final Matrix4f mv = new Matrix4f();
    GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, SCRATCH);
    mv.load(SCRATCH);
    SCRATCH.clear();
    final Matrix4f p = new Matrix4f();
    GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, SCRATCH);
    p.load(SCRATCH);
    SCRATCH.clear();
    final Matrix4f mvp = new Matrix4f();
    Matrix4f.mul(p, mv, mvp);
    mvp.store(SCRATCH);
    SCRATCH.clear();
    program.setMatrix4(name, SCRATCH);
}
Also used : Matrix4f(org.lwjgl.util.vector.Matrix4f)

Aggregations

Matrix4f (org.lwjgl.util.vector.Matrix4f)29 Vector3f (org.lwjgl.util.vector.Vector3f)12 FloatBuffer (java.nio.FloatBuffer)4 Vector2f (org.lwjgl.util.vector.Vector2f)2 Vector4f (org.lwjgl.util.vector.Vector4f)2 GuiRectangle (betterquesting.api2.client.gui.misc.GuiRectangle)1 IGuiRect (betterquesting.api2.client.gui.misc.IGuiRect)1 InterfaceTexture (com.chrisali.javaflightsim.lwjgl.interfaces.ui.InterfaceTexture)1 Particle (com.chrisali.javaflightsim.lwjgl.particles.Particle)1 ParticleTexture (com.chrisali.javaflightsim.lwjgl.particles.ParticleTexture)1 WaterTile (com.chrisali.javaflightsim.lwjgl.water.WaterTile)1 ArabicShapingException (com.ibm.icu.text.ArabicShapingException)1 IOException (java.io.IOException)1 Random (java.util.Random)1 CelestialBodyRenderEvent (micdoodle8.mods.galacticraft.api.event.client.CelestialBodyRenderEvent)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1