Search in sources :

Example 81 with Vector3d

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

the class ItemsLogicListener method onDroppedItem.

@EventHandler
public void onDroppedItem(EventItemDroppedToWorld event) {
    // Create an EntityGroundItem and add it to the event
    Location throwLocation = event.getLocation();
    Vector3d throwForce = new Vector3d(0.0);
    // Throw it when dropping it from a player's inventory ?
    System.out.println(event.getInventoryFrom());
    if (event.getInventoryFrom() != null && event.getInventoryFrom().getHolder() != null && event.getInventoryFrom().getHolder() instanceof Entity) {
        System.out.println("from som 1");
        EntityWithInventory entity = ((EntityWithInventory) event.getInventoryFrom().getHolder());
        Location pos = entity.getLocation();
        if (entity instanceof EntityLiving) {
            System.out.println("he l i v e s");
            EntityLiving owner = (EntityLiving) entity;
            throwLocation = new Location(pos.getWorld(), pos.x(), pos.y() + ((EntityPlayer) owner).eyePosition, pos.z());
            throwForce = new Vector3d(((EntityPlayer) owner).getDirectionLookingAt()).mul(0.15 - Math2.clampd(((EntityPlayer) owner).getEntityRotationComponent().getVerticalRotation(), -45, 20) / 45f * 0.0f);
            throwForce.add(((EntityPlayer) owner).getVelocityComponent().getVelocity());
        }
    }
    EntityGroundItem thrownItem = (EntityGroundItem) core.getPluginExecutionContext().getContent().entities().getEntityDefinition("groundItem").create(throwLocation);
    thrownItem.positionComponent.setPosition(throwLocation);
    thrownItem.velocityComponent.setVelocity(throwForce);
    thrownItem.setItemPile(event.getItemPile());
    // EntityGroundItem entity = new EntityGroundItem(core.getPluginExecutionContext().getContent().entities().getEntityDefinitionByName("groundItem"), event.getLocation(), event.getItemPile());
    event.setItemEntity(thrownItem);
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) EntityGroundItem(io.xol.chunkstories.core.entity.EntityGroundItem) Vector3d(org.joml.Vector3d) EntityWithInventory(io.xol.chunkstories.api.entity.interfaces.EntityWithInventory) EntityPlayer(io.xol.chunkstories.core.entity.EntityPlayer) Location(io.xol.chunkstories.api.Location) EventHandler(io.xol.chunkstories.api.events.EventHandler)

Example 82 with Vector3d

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

Example 83 with Vector3d

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

Aggregations

Vector3d (org.joml.Vector3d)117 Vector3dc (org.joml.Vector3dc)33 PhysicsObject (org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject)20 BlockPos (net.minecraft.util.math.BlockPos)19 ShipTransform (org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform)18 Location (io.xol.chunkstories.api.Location)12 Entity (io.xol.chunkstories.api.entity.Entity)11 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)9 World (net.minecraft.world.World)9 ShipData (org.valkyrienskies.mod.common.ships.ShipData)9 WorldClient (io.xol.chunkstories.api.world.WorldClient)8 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 EntityShipMovementData (org.valkyrienskies.mod.common.entity.EntityShipMovementData)7 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)6 IBlockState (net.minecraft.block.state.IBlockState)6 Vec3d (net.minecraft.util.math.Vec3d)6 Vector3f (org.joml.Vector3f)6 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)5 CellData (io.xol.chunkstories.api.world.cell.CellData)5