Search in sources :

Example 6 with Vector3f

use of org.joml.Vector3f in project chunkstories-core by Hugobros3.

the class DefaultSkyRenderer method setupShader.

public void setupShader(Shader shaderInterface) {
    float fogFactor = Math.min(Math.max(0.0f, world.getWeather() - 0.4f) / 0.1f, 1.0f);
    shaderInterface.setUniform1f("fogStartDistance", Math2.mix(192, 32, fogFactor));
    shaderInterface.setUniform1f("fogEndDistance", Math2.mix(1024, 384, fogFactor));
    Vector3f sunPos = this.getSunPosition();
    shaderInterface.setUniform3f("sunPos", sunPos.x(), sunPos.y(), sunPos.z());
    shaderInterface.setUniform1f("dayTime", this.dayTime);
    shaderInterface.setUniform1f("overcastFactor", world.getWeather());
}
Also used : Vector3f(org.joml.Vector3f)

Example 7 with Vector3f

use of org.joml.Vector3f in project IDEProgram by Itay2805.

the class GLContext method end.

/**
 * Finish specification of vertices;
 */
public void end() {
    if (this.beginMode == -1) {
        this.err = INVALID_OPERATION;
        return;
    }
    // Transform vertices and map them to window coordinates
    for (int i = 0; i < beginVertices.size(); i++) {
        Vertex vertex = beginVertices.get(i);
        // Transform vertex into eye space
        Vector4f vec = new Vector4f(vertex.coord.x, vertex.coord.y, vertex.coord.z, 1.0f);
        vec.mul(matModelView);
        // Perform backface culling - if enabled
        if (this.cullingEnabled && ((this.beginMode == GL.QUADS && i % 4 == 0) || (this.beginMode == GL.TRIANGLES && i % 3 == 0))) {
            Vector3f side1 = new Vector3f();
            beginVertices.get(i).coord.sub(beginVertices.get(i + 1).coord, side1);
            Vector3f side2 = new Vector3f();
            beginVertices.get(i).coord.sub(beginVertices.get(i + 2).coord, side2);
            Vector3f normal = new Vector3f();
            side1.cross(side2, normal);
            float dot = normal.dot(beginVertices.get(i).coord);
            // If dot > 0, then the face is facing away from the camera
            vertex.cull = dot <= 0;
        }
        // Transform vertex into clip space
        vec.mul(matProj);
        // Calculate normalized device coordinates
        Vector3f norm = new Vector3f();
        norm.x = vec.x / vec.w;
        norm.y = vec.y / vec.w;
        norm.z = vec.z / vec.w;
        vertex.coord.x = (norm.x + 1) / 2 * this.w;
        vertex.coord.y = (1 - norm.y) / 2 * this.h;
        vertex.coord.z = norm.z;
    // beginVertices.set(i, vertex);
    }
    // Assemble primitives
    if (beginMode == POINTS) {
        for (int i = 0; i < this.beginVertices.size(); i++) {
            drawPoint(beginVertices.get(i), this.bufColor, this.bufDepth, this);
        }
    } else if (beginMode == LINES && beginVertices.size() >= 2) {
    } else if (beginMode == TRIANGLES && beginVertices.size() >= 3) {
        for (int i = 0; i < this.beginVertices.size(); i += 3) {
            drawTriangle(new Vertex[] { beginVertices.get(i + 0), beginVertices.get(i + 1), beginVertices.get(i + 2) }, this.bufColor, this.bufDepth, this);
        }
    } else if (beginMode == QUADS && beginVertices.size() >= 4) {
        for (int i = 0; i < this.beginVertices.size(); i += 4) {
            drawQuad(new Vertex[] { beginVertices.get(i + 0), beginVertices.get(i + 1), beginVertices.get(i + 2), beginVertices.get(i + 3) }, this.bufColor, this.bufDepth, this);
        }
    }
    this.beginMode = -1;
    this.beginVertices.clear();
}
Also used : Vector4f(org.joml.Vector4f) Vector3f(org.joml.Vector3f)

Example 8 with Vector3f

use of org.joml.Vector3f in project chunkstories-api by Hugobros3.

the class Math2 method mix.

public static Vector3f mix(Vector3f a, Vector3f b, double f) {
    Vector3f vec = new Vector3f();
    vec.x = (mix(a.x, b.x, f));
    vec.y = (mix(a.y, b.y, f));
    vec.z = (mix(a.z, b.z, f));
    return vec;
}
Also used : Vector3f(org.joml.Vector3f)

Example 9 with Vector3f

use of org.joml.Vector3f in project chunkstories by Hugobros3.

the class Camera method computeFrustrumPlanes.

private void computeFrustrumPlanes() {
    Vector3f temp = new Vector3f();
    // Init values
    float tang = (float) Math.tan(toRad(fov / 2.0));
    float ratio = (float) viewportWidth / (float) viewportHeight;
    float nh = 0.1f * tang;
    float nw = nh * ratio;
    float fh = 3000f * tang;
    float fw = fh * ratio;
    float rotH = rotationY;
    float rotV = rotationX;
    float a = (float) ((180 - rotH) / 180f * Math.PI);
    float b = (float) ((-rotV) / 180f * Math.PI);
    Vector3f lookAt = new Vector3f((float) (Math.sin(a) * Math.cos(b)), (float) (Math.sin(b)), (float) (Math.cos(a) * Math.cos(b)));
    Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
    lookAt.cross(up, up);
    up.cross(lookAt, up);
    lookAt.add(new Vector3f((float) this.position.x, (float) this.position.y, (float) this.position.z));
    // Create the 6 frustrum planes
    Vector3f Z = new Vector3f((float) this.position.x, (float) this.position.y, (float) this.position.z);
    Z.sub(lookAt);
    Z.normalize();
    Vector3f X = new Vector3f();
    up.cross(Z, X);
    X.normalize();
    Vector3f Y = new Vector3f();
    Z.cross(X, Y);
    Vector3f nearCenterPoint = new Vector3f((float) this.position.x, (float) this.position.y, (float) this.position.z);
    temp = new Vector3f(Z);
    temp.mul(0.1f);
    nearCenterPoint.sub(temp);
    Vector3f farCenterPoint = new Vector3f((float) this.position.x, (float) this.position.y, (float) this.position.z);
    temp = new Vector3f(Z);
    temp.mul(3000f);
    farCenterPoint.sub(temp);
    // Eventually the fucking points
    Vector3f nearTopLeft = vadd(nearCenterPoint, vsub(smult(Y, nh), smult(X, nw)));
    Vector3f nearTopRight = vadd(nearCenterPoint, vadd(smult(Y, nh), smult(X, nw)));
    Vector3f nearBottomLeft = vsub(nearCenterPoint, vadd(smult(Y, nh), smult(X, nw)));
    Vector3f nearBottomRight = vsub(nearCenterPoint, vsub(smult(Y, nh), smult(X, nw)));
    Vector3f farTopLeft = vadd(farCenterPoint, vsub(smult(Y, fh), smult(X, fw)));
    Vector3f farTopRight = vadd(farCenterPoint, vadd(smult(Y, fh), smult(X, fw)));
    Vector3f farBottomLeft = vsub(farCenterPoint, vadd(smult(Y, fh), smult(X, fw)));
    Vector3f farBottomRight = vsub(farCenterPoint, vsub(smult(Y, fh), smult(X, fw)));
    cameraPlanes[0] = new CollisionPlane(nearTopRight, nearTopLeft, farTopLeft);
    cameraPlanes[1] = new CollisionPlane(nearBottomLeft, nearBottomRight, farBottomRight);
    cameraPlanes[2] = new CollisionPlane(nearTopLeft, nearBottomLeft, farBottomLeft);
    cameraPlanes[3] = new CollisionPlane(nearBottomRight, nearTopRight, farBottomRight);
    cameraPlanes[4] = new CollisionPlane(nearTopLeft, nearTopRight, nearBottomRight);
    cameraPlanes[5] = new CollisionPlane(farTopRight, farTopLeft, farBottomLeft);
    // cache that
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                corners[i * 4 + j * 2 + k] = new Vector3f();
            }
        }
    }
}
Also used : Vector3f(org.joml.Vector3f) CollisionPlane(io.xol.chunkstories.physics.CollisionPlane)

Example 10 with Vector3f

use of org.joml.Vector3f in project chunkstories by Hugobros3.

the class Camera method alUpdate.

/**
 * Updates the sound engine position and listener orientation
 */
public void alUpdate() {
    float rotH = rotationY;
    float rotV = rotationX;
    float a = (float) ((180 - rotH) / 180f * Math.PI);
    float b = (float) ((-rotV) / 180f * Math.PI);
    Vector3f lookAt = new Vector3f((float) (Math.sin(a) * Math.cos(b)), (float) (Math.sin(b)), (float) (Math.cos(a) * Math.cos(b)));
    /*Vector3f up = new Vector3f(0.0f, 1.0f, 0.0f);
		
		lookAt.cross(up, up);		
		up.cross(lookAt, up);*/
    Client.getInstance().getSoundManager().setListenerPosition((float) (double) position.x(), (float) (double) position.y(), (float) (double) position.z(), lookAt, up);
}
Also used : Vector3f(org.joml.Vector3f)

Aggregations

Vector3f (org.joml.Vector3f)261 LocationComponent (org.terasology.engine.logic.location.LocationComponent)50 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)49 Matrix4f (org.joml.Matrix4f)34 Quaternionf (org.joml.Quaternionf)29 Test (org.junit.jupiter.api.Test)20 Vector3i (org.joml.Vector3i)19 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)18 FloatBuffer (java.nio.FloatBuffer)17 ClientComponent (org.terasology.engine.network.ClientComponent)17 ByteBuffer (java.nio.ByteBuffer)16 Vector3fc (org.joml.Vector3fc)15 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)15 Vector2f (org.joml.Vector2f)13 Vector4f (org.joml.Vector4f)13 ArrayList (java.util.ArrayList)10 HitResult (org.terasology.engine.physics.HitResult)10 IOException (java.io.IOException)8 Test (org.junit.Test)8 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)8