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);
}
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();
}
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);
}
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;
}
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);
}
Aggregations