Search in sources :

Example 46 with Vector3d

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

the class SpaceGame method drawHudShotDirection.

private void drawHudShotDirection() {
    glUseProgram(0);
    Ship enemyShip = ships[shootingShip];
    if (enemyShip == null)
        return;
    Vector3d targetOrigin = tmp;
    targetOrigin.set(enemyShip.x, enemyShip.y, enemyShip.z);
    Vector3f interceptorDir = intercept(cam.position, shotVelocity, targetOrigin, tmp3.set(cam.linearVel).negate(), tmp2);
    viewMatrix.transformDirection(interceptorDir);
    if (interceptorDir.z > 0.0)
        return;
    projMatrix.transformProject(interceptorDir);
    float crosshairSize = 0.01f;
    float xs = crosshairSize * height / width;
    float ys = crosshairSize;
    crosshairVertices.clear();
    crosshairVertices.put(interceptorDir.x - xs).put(interceptorDir.y - ys);
    crosshairVertices.put(interceptorDir.x + xs).put(interceptorDir.y - ys);
    crosshairVertices.put(interceptorDir.x + xs).put(interceptorDir.y + ys);
    crosshairVertices.put(interceptorDir.x - xs).put(interceptorDir.y + ys);
    crosshairVertices.flip();
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glVertexPointer(2, GL_FLOAT, 0, crosshairVertices);
    glDrawArrays(GL_QUADS, 0, 4);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
Also used : Vector3d(org.joml.Vector3d) Vector3f(org.joml.Vector3f)

Example 47 with Vector3d

use of org.joml.Vector3d 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 48 with Vector3d

use of org.joml.Vector3d 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

Vector3d (org.joml.Vector3d)48 Location (io.xol.chunkstories.api.Location)12 Entity (io.xol.chunkstories.api.entity.Entity)11 Vector3dc (org.joml.Vector3dc)9 WorldClient (io.xol.chunkstories.api.world.WorldClient)8 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)8 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)6 Vector3f (org.joml.Vector3f)6 Vector4f (org.joml.Vector4f)6 STBEasyFont.stb_easy_font_print (org.lwjgl.stb.STBEasyFont.stb_easy_font_print)6 ClientPacketsProcessor (io.xol.chunkstories.api.client.net.ClientPacketsProcessor)5 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)5 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)5 CellData (io.xol.chunkstories.api.world.cell.CellData)5 EntityPlayer (io.xol.chunkstories.core.entity.EntityPlayer)5 Matrix4f (org.joml.Matrix4f)5 ItemPile (io.xol.chunkstories.api.item.inventory.ItemPile)4 Controller (io.xol.chunkstories.api.entity.Controller)3 HitBox (io.xol.chunkstories.api.entity.EntityLiving.HitBox)3 Voxel (io.xol.chunkstories.api.voxel.Voxel)3