Search in sources :

Example 66 with Vector4f

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

the class SpaceGame method drawShots.

private void drawShots() {
    shotsVertices.clear();
    int num = 0;
    for (int i = 0; i < projectilePositions.length; i++) {
        Vector3d projectilePosition = projectilePositions[i];
        Vector4f projectileVelocity = projectileVelocities[i];
        if (projectileVelocity.w > 0.0f) {
            float x = (float) (projectilePosition.x - cam.position.x);
            float y = (float) (projectilePosition.y - cam.position.y);
            float z = (float) (projectilePosition.z - cam.position.z);
            if (frustumIntersection.testPoint(x, y, z)) {
                float w = projectileVelocity.w;
                viewMatrix.transformPosition(tmp2.set(x, y, z));
                shotsVertices.put(tmp2.x - shotSize).put(tmp2.y - shotSize).put(tmp2.z).put(w).put(-1).put(-1);
                shotsVertices.put(tmp2.x + shotSize).put(tmp2.y - shotSize).put(tmp2.z).put(w).put(1).put(-1);
                shotsVertices.put(tmp2.x + shotSize).put(tmp2.y + shotSize).put(tmp2.z).put(w).put(1).put(1);
                shotsVertices.put(tmp2.x + shotSize).put(tmp2.y + shotSize).put(tmp2.z).put(w).put(1).put(1);
                shotsVertices.put(tmp2.x - shotSize).put(tmp2.y + shotSize).put(tmp2.z).put(w).put(-1).put(1);
                shotsVertices.put(tmp2.x - shotSize).put(tmp2.y - shotSize).put(tmp2.z).put(w).put(-1).put(-1);
                num++;
            }
        }
    }
    shotsVertices.flip();
    if (num > 0) {
        glUseProgram(shotProgram);
        glDepthMask(false);
        glEnable(GL_BLEND);
        glVertexPointer(4, GL_FLOAT, 6 * 4, shotsVertices);
        shotsVertices.position(4);
        glTexCoordPointer(2, GL_FLOAT, 6 * 4, shotsVertices);
        shotsVertices.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 : Vector4f(org.joml.Vector4f) Vector3d(org.joml.Vector3d) STBEasyFont.stb_easy_font_print(org.lwjgl.stb.STBEasyFont.stb_easy_font_print)

Example 67 with Vector4f

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

the class SpaceGame method shootFromShip.

private void shootFromShip(long thisTime, int index) {
    Ship ship = ships[index];
    if (ship == null)
        return;
    if (thisTime - ship.lastShotTime < 1E6 * shotOpponentMilliseconds) {
        return;
    }
    ship.lastShotTime = thisTime;
    Vector3d shotPos = tmp.set(ship.x, ship.y, ship.z).sub(cam.position).negate().normalize().mul(1.01f * shipRadius).add(ship.x, ship.y, ship.z);
    Vector3f icept = intercept(shotPos, shotVelocity, cam.position, cam.linearVel, tmp2);
    if (icept == null)
        return;
    // jitter the direction a bit
    GeometryUtils.perpendicular(icept, tmp3, tmp4);
    icept.fma(((float) Math.random() * 2.0f - 1.0f) * 0.01f, tmp3);
    icept.fma(((float) Math.random() * 2.0f - 1.0f) * 0.01f, tmp4);
    icept.normalize();
    for (int i = 0; i < projectilePositions.length; i++) {
        Vector3d projectilePosition = projectilePositions[i];
        Vector4f projectileVelocity = projectileVelocities[i];
        if (projectileVelocity.w <= 0.0f) {
            projectilePosition.set(shotPos);
            projectileVelocity.x = tmp2.x * shotVelocity;
            projectileVelocity.y = tmp2.y * shotVelocity;
            projectileVelocity.z = tmp2.z * shotVelocity;
            projectileVelocity.w = 0.01f;
            break;
        }
    }
}
Also used : Vector4f(org.joml.Vector4f) Vector3d(org.joml.Vector3d) Vector3f(org.joml.Vector3f) STBEasyFont.stb_easy_font_print(org.lwjgl.stb.STBEasyFont.stb_easy_font_print)

Example 68 with Vector4f

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

the class SpaceGame method shoot.

private void shoot() {
    boolean firstShot = false;
    for (int i = 0; i < projectilePositions.length; i++) {
        Vector3d projectilePosition = projectilePositions[i];
        Vector4f projectileVelocity = projectileVelocities[i];
        invViewProjMatrix.transformProject(tmp2.set(mouseX, -mouseY, 1.0f)).normalize();
        if (projectileVelocity.w <= 0.0f) {
            projectileVelocity.x = cam.linearVel.x + tmp2.x * shotVelocity;
            projectileVelocity.y = cam.linearVel.y + tmp2.y * shotVelocity;
            projectileVelocity.z = cam.linearVel.z + tmp2.z * shotVelocity;
            projectileVelocity.w = 0.01f;
            if (!firstShot) {
                projectilePosition.set(cam.right(tmp3)).mul(shotSeparation).add(cam.position);
                firstShot = true;
            } else {
                projectilePosition.set(cam.right(tmp3)).mul(-shotSeparation).add(cam.position);
                break;
            }
        }
    }
}
Also used : Vector4f(org.joml.Vector4f) Vector3d(org.joml.Vector3d) STBEasyFont.stb_easy_font_print(org.lwjgl.stb.STBEasyFont.stb_easy_font_print)

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