Search in sources :

Example 1 with Vector4d

use of org.joml.Vector4d in project lwjgl3-demos by LWJGL.

the class SpaceGame method drawParticles.

private void drawParticles() {
    particleVertices.clear();
    int num = 0;
    for (int i = 0; i < particlePositions.length; i++) {
        Vector3d particlePosition = particlePositions[i];
        Vector4d particleVelocity = particleVelocities[i];
        if (particleVelocity.w > 0.0f) {
            float x = (float) (particlePosition.x - cam.position.x);
            float y = (float) (particlePosition.y - cam.position.y);
            float z = (float) (particlePosition.z - cam.position.z);
            if (frustumIntersection.testPoint(x, y, z)) {
                float w = (float) particleVelocity.w;
                viewMatrix.transformPosition(tmp2.set(x, y, z));
                particleVertices.put(tmp2.x - particleSize).put(tmp2.y - particleSize).put(tmp2.z).put(w).put(-1).put(-1);
                particleVertices.put(tmp2.x + particleSize).put(tmp2.y - particleSize).put(tmp2.z).put(w).put(1).put(-1);
                particleVertices.put(tmp2.x + particleSize).put(tmp2.y + particleSize).put(tmp2.z).put(w).put(1).put(1);
                particleVertices.put(tmp2.x + particleSize).put(tmp2.y + particleSize).put(tmp2.z).put(w).put(1).put(1);
                particleVertices.put(tmp2.x - particleSize).put(tmp2.y + particleSize).put(tmp2.z).put(w).put(-1).put(1);
                particleVertices.put(tmp2.x - particleSize).put(tmp2.y - particleSize).put(tmp2.z).put(w).put(-1).put(-1);
                num++;
            }
        }
    }
    particleVertices.flip();
    if (num > 0) {
        glUseProgram(particleProgram);
        glDepthMask(false);
        glEnable(GL_BLEND);
        glVertexPointer(4, GL_FLOAT, 6 * 4, particleVertices);
        particleVertices.position(4);
        glTexCoordPointer(2, GL_FLOAT, 6 * 4, particleVertices);
        particleVertices.position(0);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        glDrawArrays(GL_TRIANGLES, 0, num * 6);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        glDisable(GL_BLEND);
        glDepthMask(true);
    }
}
Also used : Vector4d(org.joml.Vector4d) Vector3d(org.joml.Vector3d) STBEasyFont.stb_easy_font_print(org.lwjgl.stb.STBEasyFont.stb_easy_font_print)

Example 2 with Vector4d

use of org.joml.Vector4d in project lwjgl3-demos by LWJGL.

the class SpaceGame method updateParticles.

private void updateParticles(float dt) {
    for (int i = 0; i < particlePositions.length; i++) {
        Vector4d particleVelocity = particleVelocities[i];
        if (particleVelocity.w <= 0.0f)
            continue;
        particleVelocity.w += dt;
        Vector3d particlePosition = particlePositions[i];
        newPosition.set(particleVelocity.x, particleVelocity.y, particleVelocity.z).mul(dt).add(particlePosition);
        if (particleVelocity.w > maxParticleLifetime) {
            particleVelocity.w = 0.0f;
            continue;
        }
        particlePosition.set(newPosition);
    }
}
Also used : Vector4d(org.joml.Vector4d) Vector3d(org.joml.Vector3d) STBEasyFont.stb_easy_font_print(org.lwjgl.stb.STBEasyFont.stb_easy_font_print)

Example 3 with Vector4d

use of org.joml.Vector4d in project lwjgl3-demos by LWJGL.

the class SpaceGame method emitExplosion.

private void emitExplosion(Vector3d p, Vector3f normal) {
    int c = explosionParticles;
    if (normal != null)
        GeometryUtils.perpendicular(normal, tmp4, tmp3);
    for (int i = 0; i < particlePositions.length; i++) {
        Vector3d particlePosition = particlePositions[i];
        Vector4d particleVelocity = particleVelocities[i];
        if (particleVelocity.w <= 0.0f) {
            if (normal != null) {
                float r1 = (float) Math.random() * 2.0f - 1.0f;
                float r2 = (float) Math.random() * 2.0f - 1.0f;
                particleVelocity.x = normal.x + r1 * tmp4.x + r2 * tmp3.x;
                particleVelocity.y = normal.y + r1 * tmp4.y + r2 * tmp3.y;
                particleVelocity.z = normal.z + r1 * tmp4.z + r2 * tmp3.z;
            } else {
                float x = (float) Math.random() * 2.0f - 1.0f;
                float y = (float) Math.random() * 2.0f - 1.0f;
                float z = (float) Math.random() * 2.0f - 1.0f;
                particleVelocity.x = x;
                particleVelocity.y = y;
                particleVelocity.z = z;
            }
            particleVelocity.normalize3();
            particleVelocity.mul(140);
            particleVelocity.w = 0.01f;
            particlePosition.set(p);
            if (c-- == 0)
                break;
        }
    }
}
Also used : Vector4d(org.joml.Vector4d) Vector3d(org.joml.Vector3d) STBEasyFont.stb_easy_font_print(org.lwjgl.stb.STBEasyFont.stb_easy_font_print)

Aggregations

Vector3d (org.joml.Vector3d)3 Vector4d (org.joml.Vector4d)3 STBEasyFont.stb_easy_font_print (org.lwjgl.stb.STBEasyFont.stb_easy_font_print)3