Search in sources :

Example 11 with Vector3d

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

the class EntityBase method moveWithoutCollisionRestrain.

@Override
public void moveWithoutCollisionRestrain(Vector3dc delta) {
    Vector3d pos = new Vector3d(positionComponent.getLocation());
    pos.add(delta);
    positionComponent.setPosition(pos);
}
Also used : Vector3d(org.joml.Vector3d)

Example 12 with Vector3d

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

the class PhysicsWireframeDebugger method render.

public void render(RenderingInterface renderer) {
    Vector3dc cameraPosition = renderer.getCamera().getCameraPosition();
    // int id, data;
    int drawDebugDist = 6;
    // Iterate over nearby voxels
    for (int i = ((int) (double) cameraPosition.x()) - drawDebugDist; i <= ((int) (double) cameraPosition.x()) + drawDebugDist; i++) for (int j = ((int) (double) cameraPosition.y()) - drawDebugDist; j <= ((int) (double) cameraPosition.y()) + drawDebugDist; j++) for (int k = ((int) (double) cameraPosition.z()) - drawDebugDist; k <= ((int) (double) cameraPosition.z()) + drawDebugDist; k++) {
        // data = world.peekSimple(i, j, k);
        // id = VoxelFormat.id(data);
        CellData cell = world.peekSafely(i, j, k);
        // System.out.println(i+":"+j+":"+k);
        // System.out.println(cell.getX() + ":"+cell.getY()+":"+cell.getZ());
        CollisionBox[] tboxes = cell.getTranslatedCollisionBoxes();
        // System.out.println(tboxes.length);
        if (tboxes != null) {
            // Draw all their collision boxes
            for (CollisionBox box : tboxes) {
                if (cell.getVoxel().getDefinition().isSolid())
                    // Red if solid
                    FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(1, 0, 0, 1.0f));
                else
                    // Yellow otherwise
                    FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(1, 1, 0, 0.25f));
            }
        }
    }
    // Iterate over each entity
    Iterator<Entity> ie = world.getAllLoadedEntities();
    while (ie.hasNext()) {
        Entity e = ie.next();
        // Entities with hitboxes see all of those being drawn
        if (e instanceof EntityLiving) {
            EntityLiving eli = (EntityLiving) e;
            for (HitBox hitbox : eli.getHitBoxes()) {
                hitbox.draw(renderer);
            }
        }
        // Get the entity bounding box
        if (e.getTranslatedBoundingBox().lineIntersection(cameraPosition, new Vector3d(renderer.getCamera().getViewDirection())) != null)
            FakeImmediateModeDebugRenderer.renderCollisionBox(e.getTranslatedBoundingBox(), new Vector4f(0, 0, 0.5f, 1.0f));
        else
            FakeImmediateModeDebugRenderer.renderCollisionBox(e.getTranslatedBoundingBox(), new Vector4f(0, 1f, 1f, 1.0f));
        // And the collision box
        for (CollisionBox box : e.getCollisionBoxes()) {
            box.translate(e.getLocation());
            FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(0, 1, 0.5f, 1.0f));
        }
    }
}
Also used : Vector3dc(org.joml.Vector3dc) Entity(io.xol.chunkstories.api.entity.Entity) HitBox(io.xol.chunkstories.api.entity.EntityLiving.HitBox) Vector4f(org.joml.Vector4f) EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) Vector3d(org.joml.Vector3d) CellData(io.xol.chunkstories.api.world.cell.CellData) CollisionBox(io.xol.chunkstories.api.physics.CollisionBox)

Example 13 with Vector3d

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

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

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

the class PacketParticle method process.

@Override
public void process(PacketSender sender, DataInputStream in, PacketReceptionContext processor) throws IOException, PacketProcessingException {
    particleName = in.readUTF();
    Vector3d position = new Vector3d();
    position.x = (in.readDouble());
    position.y = (in.readDouble());
    position.z = (in.readDouble());
    Vector3d velocity = new Vector3d();
    if (in.readBoolean()) {
        velocity.x = (in.readDouble());
        velocity.y = (in.readDouble());
        velocity.z = (in.readDouble());
    }
    if (processor instanceof ClientPacketsProcessor) {
        ClientPacketsProcessor cpp = (ClientPacketsProcessor) processor;
        cpp.getContext().getParticlesManager().spawnParticleAtPositionWithVelocity(particleName, position, velocity);
    }
}
Also used : ClientPacketsProcessor(io.xol.chunkstories.api.client.net.ClientPacketsProcessor) Vector3d(org.joml.Vector3d)

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