Search in sources :

Example 26 with Vector4f

use of org.joml.Vector4f in project Terasology by MovingBlocks.

the class ColorRangeGeneratorComponent method copyFrom.

@Override
public void copyFrom(ColorRangeGeneratorComponent other) {
    this.minColorComponents = new Vector4f(other.minColorComponents);
    this.maxColorComponents = new Vector4f(other.maxColorComponents);
}
Also used : Vector4f(org.joml.Vector4f)

Example 27 with Vector4f

use of org.joml.Vector4f in project Terasology by MovingBlocks.

the class SphereBuilder method build.

// refrence: https://github.com/caosdoar/spheres/blob/master/src/spheres.cpp
public StandardMeshData build() {
    StandardMeshData meshData = new StandardMeshData();
    Matrix4f mat = new Matrix4f().setRotationXYZ(0, 0, (float) (Math.PI / 2.0f));
    Vector4f pos = new Vector4f();
    Vector3f normal = new Vector3f();
    Vector2f uv0 = new Vector2f();
    Vector3f loc = new Vector3f();
    float s = 0.0f;
    float t = 1.0f;
    float ds = 1.0f / verticalCuts;
    float dt = 1.0f / horizontalCuts;
    for (int j = 0; j <= horizontalCuts; ++j) {
        double polar = (Math.PI * j) / horizontalCuts;
        double sp = Math.sin(polar);
        double cp = Math.cos(polar);
        s = 0.0f;
        for (int i = 0; i <= verticalCuts; ++i) {
            double azimuth = (2.0 * Math.PI * i) / verticalCuts;
            double sa = Math.sin(azimuth);
            double ca = Math.cos(azimuth);
            if (this.normals) {
                normal.set((float) (sp * ca), (float) cp, (float) (sp * sa));
                meshData.normal.put(normal);
            }
            if (this.textured) {
                uv0.set(s, t);
                meshData.uv0.put(uv0);
            }
            s += ds;
            pos.set((float) ((sp * ca) * radius), (float) (cp * radius), (float) ((sp * sa) * radius), 1.0f);
            mat.transform(pos);
            loc.set(pos.x, pos.y, pos.z);
            meshData.position.put(loc);
        }
        t -= dt;
    }
    for (int j = 0; j < horizontalCuts; ++j) {
        int aStart = (j * (verticalCuts + 1));
        int bStart = (j + 1) * (verticalCuts + 1);
        for (int i = 0; i < verticalCuts; ++i) {
            int a = aStart + i;
            int a1 = aStart + ((i + 1) % (verticalCuts + 1));
            int b = bStart + i;
            int b1 = bStart + ((i + 1) % (verticalCuts + 1));
            meshData.indices.putAll(a, b1, b);
            meshData.indices.putAll(a1, b1, a);
        }
    }
    return meshData;
}
Also used : Matrix4f(org.joml.Matrix4f) Vector4f(org.joml.Vector4f) Vector2f(org.joml.Vector2f) Vector3f(org.joml.Vector3f)

Example 28 with Vector4f

use of org.joml.Vector4f in project Terasology by MovingBlocks.

the class GLTFAttributeMapping method readColor4FBuffer.

public static void readColor4FBuffer(byte[] buffer, GLTFAccessor accessor, GLTFBufferView bufferView, VertexAttributeBinding<Colorc, Color> mapping) {
    if (accessor.getComponentType() != GLTFComponentType.FLOAT) {
        return;
    }
    ByteBuffer byteBuffer = ByteBuffer.wrap(buffer, bufferView.getByteOffset() + accessor.getByteOffset(), bufferView.getByteLength() - accessor.getByteOffset());
    byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
    int gap = 0;
    if (bufferView.getByteStride() > 0) {
        gap = bufferView.getByteStride() - accessor.getComponentType().getByteLength() * accessor.getType().getDimension();
    }
    Vector4f value = new Vector4f();
    Color c = new Color();
    if (byteBuffer.position() < byteBuffer.limit()) {
        for (int i = 0; i < accessor.getType().getDimension(); i++) {
            value.setComponent(i, byteBuffer.getFloat());
        }
        c.set(value);
        mapping.put(c);
    }
    while (byteBuffer.position() < byteBuffer.limit() - gap) {
        byteBuffer.position(byteBuffer.position() + gap);
        for (int i = 0; i < accessor.getType().getDimension(); i++) {
            value.setComponent(i, byteBuffer.getFloat());
        }
        c.set(value);
        mapping.put(c);
    }
}
Also used : Vector4f(org.joml.Vector4f) Color(org.terasology.nui.Color) ByteBuffer(java.nio.ByteBuffer)

Example 29 with Vector4f

use of org.joml.Vector4f in project Terasology by MovingBlocks.

the class OpenVRStereoCamera method updateMatrices.

@Override
public void updateMatrices(float fov) {
    prevViewProjectionMatrix.set(viewProjectionMatrix);
    Matrix4f leftEyeProjection = vrProvider.getState().getEyeProjectionMatrix(0);
    Matrix4f rightEyeProjection = vrProvider.getState().getEyeProjectionMatrix(1);
    Matrix4f leftEyePose = vrProvider.getState().getEyePose(0);
    Matrix4f rightEyePose = vrProvider.getState().getEyePose(1);
    float halfIPD = (float) Math.sqrt(Math.pow(leftEyePose.m30() - rightEyePose.m30(), 2) + Math.pow(leftEyePose.m31() - rightEyePose.m31(), 2) + Math.pow(leftEyePose.m32() - rightEyePose.m32(), 2)) / 2.0f;
    // set camera orientation
    Vector4f vecQuaternion = OpenVRUtil.convertToQuaternion(leftEyePose);
    Quaternionf quaternion = new Quaternionf(vecQuaternion.x, vecQuaternion.y, vecQuaternion.z, vecQuaternion.w);
    setOrientation(quaternion);
    // view matrix is inverse of pose matrix
    leftEyePose = leftEyePose.invert();
    rightEyePose = rightEyePose.invert();
    if (Math.sqrt(Math.pow(leftEyePose.m30(), 2) + Math.pow(leftEyePose.m31(), 2) + Math.pow(leftEyePose.m32(), 2)) < 0.25) {
        return;
    }
    projectionMatrixLeftEye.set(leftEyeProjection);
    projectionMatrixRightEye.set(rightEyeProjection);
    projectionMatrix = projectionMatrixLeftEye;
    viewMatrixLeftEye.set(leftEyePose);
    viewMatrixRightEye.set(rightEyePose);
    viewMatrix = viewMatrixLeftEye;
    normViewMatrix = viewMatrixLeftEye;
    reflectionMatrix.setRow(0, new Vector4f(1.0f, 0.0f, 0.0f, 0.0f));
    reflectionMatrix.setRow(1, new Vector4f(0.0f, -1.0f, 0.0f, 2f * (-position.y + 32f)));
    reflectionMatrix.setRow(2, new Vector4f(0.0f, 0.0f, 1.0f, 0.0f));
    reflectionMatrix.setRow(3, new Vector4f(0.0f, 0.0f, 0.0f, 1.0f));
    viewMatrix.mul(reflectionMatrix, viewMatrixReflected);
    reflectionMatrix.setRow(1, new Vector4f(0.0f, -1.0f, 0.0f, 0.0f));
    normViewMatrix.mul(reflectionMatrix, normViewMatrixReflected);
    viewTranslationLeftEye.identity();
    viewTranslationLeftEye.setTranslation(halfIPD, 0.0f, 0.0f);
    viewTranslationRightEye.identity();
    viewTranslationRightEye.setTranslation(-halfIPD, 0.0f, 0.0f);
    viewTranslationLeftEye.mul(viewMatrixReflected, viewMatrixReflectedLeftEye);
    viewTranslationRightEye.mul(viewMatrixReflected, viewMatrixReflectedRightEye);
    projectionMatrixLeftEye.mul(viewMatrixLeftEye, viewProjectionMatrixLeftEye);
    projectionMatrixRightEye.mul(viewMatrixRightEye, viewProjectionMatrixRightEye);
    viewProjectionMatrixLeftEye.invert(inverseViewProjectionMatrixLeftEye);
    viewProjectionMatrixRightEye.invert(inverseViewProjectionMatrixRightEye);
    projectionMatrixLeftEye.invert(inverseProjectionMatrixLeftEye);
    projectionMatrixRightEye.invert(inverseProjectionMatrixRightEye);
    updateFrustum();
}
Also used : Matrix4f(org.joml.Matrix4f) Vector4f(org.joml.Vector4f) Quaternionf(org.joml.Quaternionf)

Example 30 with Vector4f

use of org.joml.Vector4f in project Terasology by MovingBlocks.

the class PerspectiveCamera method updateMatrices.

@Override
public void updateMatrices(float fov) {
    // Nothing to do...
    if (cachedPosition.equals(getPosition()) && cachedViewigDirection.equals(viewingDirection) && cachedBobbingRotationOffsetFactor == bobbingRotationOffsetFactor && cachedBobbingVerticalOffsetFactor == bobbingVerticalOffsetFactor && cachedFov == fov && cachedZFar == getzFar() && cachedZNear == getzNear() && cachedReflectionHeight == getReflectionHeight()) {
        return;
    }
    viewingDirection.cross(up, tempRightVector);
    tempRightVector.mul(bobbingRotationOffsetFactor);
    float aspectRatio = (float) displayDevice.getWidth() / displayDevice.getHeight();
    float fovY = (float) (2 * Math.atan2(Math.tan(0.5 * fov * TeraMath.DEG_TO_RAD), aspectRatio));
    projectionMatrix.setPerspective(fovY, aspectRatio, getzNear(), getzFar());
    viewMatrix.setLookAt(0f, bobbingVerticalOffsetFactor * 2.0f, 0f, viewingDirection.x, viewingDirection.y + bobbingVerticalOffsetFactor * 2.0f, viewingDirection.z, up.x + tempRightVector.x, up.y + tempRightVector.y, up.z + tempRightVector.z);
    normViewMatrix.setLookAt(0f, bobbingVerticalOffsetFactor * 2.0f, 0f, viewingDirection.x, viewingDirection.y + bobbingVerticalOffsetFactor * 2.0f, viewingDirection.z, up.x + tempRightVector.x, up.y + tempRightVector.y, up.z + tempRightVector.z);
    reflectionMatrix.setRow(0, new Vector4f(1.0f, 0.0f, 0.0f, 0.0f));
    reflectionMatrix.setRow(1, new Vector4f(0.0f, -1.0f, 0.0f, 2f * (-position.y + getReflectionHeight())));
    reflectionMatrix.setRow(2, new Vector4f(0.0f, 0.0f, 1.0f, 0.0f));
    reflectionMatrix.setRow(3, new Vector4f(0.0f, 0.0f, 0.0f, 1.0f));
    viewMatrix.mul(reflectionMatrix, viewMatrixReflected);
    reflectionMatrix.setRow(1, new Vector4f(0.0f, -1.0f, 0.0f, 0.0f));
    normViewMatrix.mul(reflectionMatrix, normViewMatrixReflected);
    projectionMatrix.mul(viewMatrix, viewProjectionMatrix);
    projectionMatrix.invert(inverseProjectionMatrix);
    viewProjectionMatrix.invert(inverseViewProjectionMatrix);
    // Used for dirty checks
    cachedPosition.set(getPosition());
    cachedViewigDirection.set(viewingDirection);
    cachedBobbingVerticalOffsetFactor = bobbingVerticalOffsetFactor;
    cachedBobbingRotationOffsetFactor = bobbingRotationOffsetFactor;
    cachedFov = fov;
    cachedZNear = getzNear();
    cachedZFar = getzFar();
    cachedReflectionHeight = getReflectionHeight();
    updateFrustum();
}
Also used : Vector4f(org.joml.Vector4f)

Aggregations

Vector4f (org.joml.Vector4f)68 Vector3f (org.joml.Vector3f)13 Font (io.xol.chunkstories.api.rendering.text.FontRenderer.Font)12 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)6 Vector3d (org.joml.Vector3d)6 Shader (io.xol.chunkstories.api.rendering.shader.Shader)5 CellData (io.xol.chunkstories.api.world.cell.CellData)5 Vector2f (org.joml.Vector2f)5 Mouse (io.xol.chunkstories.api.input.Mouse)4 Texture2DGL (io.xol.chunkstories.renderer.opengl.texture.Texture2DGL)4 ByteBuffer (java.nio.ByteBuffer)4 Matrix4f (org.joml.Matrix4f)4 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)3 STBEasyFont.stb_easy_font_print (org.lwjgl.stb.STBEasyFont.stb_easy_font_print)3 Location (io.xol.chunkstories.api.Location)2 Entity (io.xol.chunkstories.api.entity.Entity)2 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)2 GuiRenderer (io.xol.chunkstories.api.gui.GuiRenderer)2 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)2 Voxel (io.xol.chunkstories.api.voxel.Voxel)2