Search in sources :

Example 26 with Matrix4f

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

the class RenderingUtilities method createViewMatrix.

/**
 * Creates a 4D view matrix using the camera's current view angles
 *
 * @param camera
 * @return 4D view matrix
 */
public static Matrix4f createViewMatrix(Camera camera) {
    Matrix4f viewMatrix = new Matrix4f();
    viewMatrix.setIdentity();
    Matrix4f.rotate((float) Math.toRadians(camera.getPitch()), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate((float) Math.toRadians(camera.getYaw()), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
    Matrix4f.rotate((float) Math.toRadians(camera.getRoll()), new Vector3f((float) Math.sin(Math.toRadians(camera.getYaw())), 0, (float) -Math.cos(Math.toRadians(camera.getYaw()))), viewMatrix, // Rotation of unit vector with yaw to ensure camera "rolls" regardless of yaw angle
    viewMatrix);
    Vector3f cameraPos = camera.getPosition();
    Vector3f negativeCameraPos = new Vector3f(-cameraPos.x, -cameraPos.y, -cameraPos.z);
    Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
    return viewMatrix;
}
Also used : Matrix4f(org.lwjgl.util.vector.Matrix4f) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 27 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 particles using a 2D Vector for translation and scale
 *
 * @param translation
 * @param scale
 * @return 4D transformation matrix
 */
public static Matrix4f createTransformationMatrix(Vector2f translation, Vector2f scale) {
    Matrix4f matrix = new Matrix4f();
    matrix.setIdentity();
    Matrix4f.translate(translation, matrix, matrix);
    Matrix4f.scale(new Vector3f(scale.x, scale.y, 1f), matrix, matrix);
    return matrix;
}
Also used : Matrix4f(org.lwjgl.util.vector.Matrix4f) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 28 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 3D entities using a 3D vector for translation, and separate vales for rotation and scaling
 *
 * @param translation
 * @param rx
 * @param ry
 * @param rz
 * @param scale
 * @return 4D transformation matrix
 */
public static Matrix4f createTransformationMatrix(Vector3f translation, float rx, float ry, float rz, float scale) {
    Matrix4f matrix = new Matrix4f();
    matrix.setIdentity();
    Matrix4f.translate(translation, matrix, matrix);
    Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f((float) -Math.cos(Math.toRadians(ry)), 0, (float) Math.sin(Math.toRadians(ry))), matrix, // Rotation of unit vector with yaw to ensure entity "rolls" regardless of yaw angle
    matrix);
    Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0, 1, 0), matrix, matrix);
    Matrix4f.rotate((float) Math.toRadians(rz), new Vector3f(0, 0, 1), matrix, matrix);
    Matrix4f.scale(new Vector3f(scale, scale, scale), matrix, matrix);
    return matrix;
}
Also used : Matrix4f(org.lwjgl.util.vector.Matrix4f) Vector3f(org.lwjgl.util.vector.Vector3f)

Example 29 with Matrix4f

use of org.lwjgl.util.vector.Matrix4f in project BetterQuesting by Funwayguy.

the class RenderUtils method startScissor.

/**
 * Performs a OpenGL scissor based on Minecraft's resolution instead of display resolution and adds it to the stack of ongoing scissors.
 * Not using this method will result in incorrect scissoring and scaling of parent/child GUIs
 */
public static void startScissor(Minecraft mc, GuiRectangle rect) {
    if (scissorStack.size() >= 100) {
        BetterQuesting.logger.log(Level.ERROR, "More than 100 recursive scissor calls have been made!");
        return;
    }
    GL11.glEnable(GL11.GL_SCISSOR_TEST);
    ScaledResolution r = new ScaledResolution(mc);
    int f = r.getScaleFactor();
    // Have to do all this fancy crap because glScissor() isn't affected by glScale() and rather than try and convince devs to use some custom hack
    // we'll just deal with it by reading from the current MODELVIEW MATRIX to convert between screen spaces at their relative scales and translations.
    FloatBuffer fb = BufferUtils.createFloatBuffer(16);
    GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, fb);
    fb.rewind();
    Matrix4f fm = new Matrix4f();
    fm.load(fb);
    // GL screenspace rectangle
    GuiRectangle sRect = new GuiRectangle((int) (rect.getX() * f * fm.m00 + (fm.m30 * f)), (r.getScaledHeight() - (int) ((rect.getY() + rect.getHeight()) * fm.m11 + fm.m31)) * f, (int) (rect.getWidth() * f * fm.m00), (int) (rect.getHeight() * f * fm.m11));
    if (!scissorStack.empty()) {
        IGuiRect parentRect = scissorStack.peek();
        int x = Math.max(parentRect.getX(), sRect.getX());
        int y = Math.max(parentRect.getY(), sRect.getY());
        int w = Math.min(parentRect.getX() + parentRect.getWidth(), sRect.getX() + sRect.getWidth());
        int h = Math.min(parentRect.getY() + parentRect.getHeight(), sRect.getY() + sRect.getHeight());
        // Clamp to 0 to prevent OpenGL errors
        w = Math.max(0, w - x);
        // Clamp to 0 to prevent OpenGL errors
        h = Math.max(0, h - y);
        sRect = new GuiRectangle(x, y, w, h, 0);
    }
    // GL11.glScissor((int)(sRect.getX() * f * fm.m00), (r.getScaledHeight() - (int)((sRect.getY() + sRect.getHeight()) * fm.m11)) * f, (int)(sRect.getWidth() * f * fm.m00), (int)(sRect.getHeight() * f * fm.m11));
    GL11.glScissor(sRect.getX(), sRect.getY(), sRect.getWidth(), sRect.getHeight());
    scissorStack.add(sRect);
}
Also used : ScaledResolution(net.minecraft.client.gui.ScaledResolution) Matrix4f(org.lwjgl.util.vector.Matrix4f) IGuiRect(betterquesting.api2.client.gui.misc.IGuiRect) GuiRectangle(betterquesting.api2.client.gui.misc.GuiRectangle) FloatBuffer(java.nio.FloatBuffer)

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