Search in sources :

Example 76 with Vector3d

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

the class HitBoxImpl method lineIntersection.

/**
 * Tricky maths; transforms the inbound ray so the hitbox would be at 0.0.0 and axis-aligned
 */
public Vector3dc lineIntersection(Vector3dc lineStart, Vector3dc lineDirection) {
    Matrix4f fromAABBToWorld = new Matrix4f(entity.getAnimatedSkeleton().getBoneHierarchyTransformationMatrix(skeletonPart, System.currentTimeMillis() % 1000000));
    Matrix4f worldPositionTransformation = new Matrix4f();
    Location entityLoc = entity.getLocation();
    Vector3f pos = new Vector3f((float) entityLoc.x, (float) entityLoc.y, (float) entityLoc.z);
    worldPositionTransformation.translate(pos);
    // Creates from AABB space to worldspace
    worldPositionTransformation.mul(fromAABBToWorld, fromAABBToWorld);
    // Invert it.
    Matrix4f fromWorldToAABB = new Matrix4f();
    fromAABBToWorld.invert(fromWorldToAABB);
    // Transform line start into AABB space
    Vector4f lineStart4 = new Vector4f((float) lineStart.x(), (float) lineStart.y(), (float) lineStart.z(), 1.0f);
    Vector4f lineDirection4 = new Vector4f((float) lineDirection.x(), (float) lineDirection.y(), (float) lineDirection.z(), 0.0f);
    fromWorldToAABB.transform(lineStart4);
    fromWorldToAABB.transform(lineDirection4);
    Vector3d lineStartTransformed = new Vector3d(lineStart4.x(), lineStart4.y(), lineStart4.z());
    Vector3d lineDirectionTransformed = new Vector3d(lineDirection4.x(), lineDirection4.y(), lineDirection4.z());
    // Actual computation
    Vector3dc hitPoint = box.lineIntersection(lineStartTransformed, lineDirectionTransformed);
    if (hitPoint == null)
        return null;
    // Transform hitPoint back into world
    Vector4f hitPoint4 = new Vector4f((float) hitPoint.x(), (float) hitPoint.y(), (float) hitPoint.z(), 1.0f);
    fromAABBToWorld.transform(hitPoint4);
    return new Vector3d((double) (float) hitPoint4.x(), (double) (float) hitPoint4.y(), (double) (float) hitPoint4.z());
}
Also used : Vector3dc(org.joml.Vector3dc) Matrix4f(org.joml.Matrix4f) Vector4f(org.joml.Vector4f) Vector3d(org.joml.Vector3d) Vector3f(org.joml.Vector3f) Location(io.xol.chunkstories.api.Location)

Example 77 with Vector3d

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

the class HitBoxImpl method draw.

/**
 * Debug method to figure out if the hitbox match with the model
 */
public void draw(RenderingInterface context) {
    if (!context.currentShader().getShaderName().equals("overlay")) {
        context.useShader("overlay");
        context.getCamera().setupShader(context.currentShader());
    }
    context.currentShader().setUniform1i("doTransform", 1);
    Matrix4f boneTransormation = new Matrix4f(entity.getAnimatedSkeleton().getBoneHierarchyTransformationMatrix(skeletonPart, System.currentTimeMillis() % 1000000));
    Matrix4f worldPositionTransformation = new Matrix4f();
    Location loc = entity.getLocation();
    Vector3f pos = new Vector3f((float) loc.x, (float) loc.y, (float) loc.z);
    worldPositionTransformation.translate(pos);
    worldPositionTransformation.mul(boneTransormation, boneTransormation);
    // Scales/moves the identity box to reflect collisionBox shape
    boneTransormation.translate(new Vector3f((float) box.xpos, (float) box.ypos, (float) box.zpos));
    boneTransormation.scale(new Vector3f((float) box.xw, (float) box.h, (float) box.zw));
    context.currentShader().setUniformMatrix4f("transform", boneTransormation);
    context.unbindAttributes();
    context.bindAttribute("vertexIn", context.meshes().getIdentityCube().asAttributeSource(VertexFormat.FLOAT, 3));
    context.currentShader().setUniform4f("colorIn", 0.0, 1.0, 0.0, 1.0);
    // Check for intersection with player
    EntityControllable ec = ((WorldClient) entity.getWorld()).getClient().getPlayer().getControlledEntity();
    if (ec != null) {
        if (lineIntersection((Vector3d) context.getCamera().getCameraPosition(), ((EntityPlayer) ec).getDirectionLookingAt()) != null)
            context.currentShader().setUniform4f("colorIn", 1.0, 0.0, 0.0, 1.0);
    }
    context.draw(Primitive.LINE, 0, 24);
    context.currentShader().setUniform1i("doTransform", 0);
}
Also used : Matrix4f(org.joml.Matrix4f) Vector3d(org.joml.Vector3d) Vector3f(org.joml.Vector3f) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) WorldClient(io.xol.chunkstories.api.world.WorldClient) Location(io.xol.chunkstories.api.Location)

Example 78 with Vector3d

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

the class EntityGroundItem method tick.

@Override
public void tick() {
    // this.moveWithCollisionRestrain(0, -0.05, 0);
    Vector3d velocity = velocityComponent.getVelocity();
    if (world instanceof WorldMaster) {
        Voxel voxelIn = world.peekSafely(positionComponent.getLocation()).getVoxel();
        boolean inWater = voxelIn.getDefinition().isLiquid();
        double terminalVelocity = inWater ? -0.25 : -0.5;
        if (velocity.y() > terminalVelocity && !this.isOnGround())
            velocity.y = (velocity.y() - 0.016);
        if (velocity.y() < terminalVelocity)
            velocity.y = (terminalVelocity);
        Vector3dc remainingToMove = moveWithCollisionRestrain(velocity.x(), velocity.y(), velocity.z());
        if (remainingToMove.y() < -0.02 && this.isOnGround()) {
            if (remainingToMove.y() < -0.01) {
                // Bounce
                double originalDownardsVelocity = velocity.y();
                double bounceFactor = 0.15;
                velocity.mul(bounceFactor);
                velocity.y = (-originalDownardsVelocity * bounceFactor);
            // world.getSoundManager().playSoundEffect("./sounds/dogez/weapon/grenades/grenade_bounce.ogg", Mode.NORMAL, getLocation(), 1, 1, 10, 35);
            } else
                velocity.mul(0d);
        }
        if (Math.abs(velocity.x()) < 0.02)
            velocity.x = (0.0);
        if (Math.abs(velocity.z()) < 0.02)
            velocity.z = (0.0);
        if (Math.abs(velocity.y()) < 0.01)
            velocity.y = (0.0);
        velocityComponent.setVelocity(velocity);
    }
    if (world instanceof WorldClient) {
        if (this.isOnGround()) {
            rotation += 1.0f;
            rotation %= 360;
        }
    }
    super.tick();
}
Also used : Vector3dc(org.joml.Vector3dc) Vector3d(org.joml.Vector3d) Voxel(io.xol.chunkstories.api.voxel.Voxel) WorldClient(io.xol.chunkstories.api.world.WorldClient) WorldMaster(io.xol.chunkstories.api.world.WorldMaster)

Example 79 with Vector3d

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

the class EntityHumanoid method handleWalkingEtcSounds.

protected void handleWalkingEtcSounds() {
    // This is strictly a clientside hack
    if (!(getWorld() instanceof WorldClient))
        return;
    // When the entities are too far from the player, don't play any sounds
    if (((WorldClient) getWorld()).getClient().getPlayer().getControlledEntity() != null)
        if (((WorldClient) getWorld()).getClient().getPlayer().getControlledEntity().getLocation().distance(this.getLocation()) > 25f)
            return;
    // Sound stuff
    if (isOnGround() && !lastTickOnGround) {
        justLanded = true;
        metersWalked = 0.0;
    }
    // Used to trigger landing sound
    lastTickOnGround = this.isOnGround();
    // Bobbing
    Vector3d horizontalSpeed = new Vector3d(this.getVelocityComponent().getVelocity());
    horizontalSpeed.y = 0d;
    if (isOnGround())
        metersWalked += Math.abs(horizontalSpeed.length());
    boolean inWater = isInWater();
    Voxel voxelStandingOn = world.peekSafely(new Vector3d(this.getLocation()).add(0.0, -0.01, 0.0)).getVoxel();
    if (voxelStandingOn == null || !voxelStandingOn.getDefinition().isSolid() && !voxelStandingOn.getDefinition().isLiquid())
        return;
    VoxelMaterial material = voxelStandingOn.getMaterial();
    if (justJumped && !inWater) {
        justJumped = false;
        getWorld().getSoundManager().playSoundEffect(material.resolveProperty("jumpingSounds"), Mode.NORMAL, getLocation(), (float) (0.9f + Math.sqrt(getVelocityComponent().getVelocity().x() * getVelocityComponent().getVelocity().x() + getVelocityComponent().getVelocity().z() * getVelocityComponent().getVelocity().z()) * 0.1f), 1f).setAttenuationEnd(10);
    }
    if (justLanded) {
        justLanded = false;
        getWorld().getSoundManager().playSoundEffect(material.resolveProperty("landingSounds"), Mode.NORMAL, getLocation(), (float) (0.9f + Math.sqrt(getVelocityComponent().getVelocity().x() * getVelocityComponent().getVelocity().x() + getVelocityComponent().getVelocity().z() * getVelocityComponent().getVelocity().z()) * 0.1f), 1f).setAttenuationEnd(10);
    }
    if (metersWalked > 0.2 * Math.PI * 2) {
        metersWalked %= 0.2 * Math.PI * 2;
        if (horizontalSpeed.length() <= 0.06)
            getWorld().getSoundManager().playSoundEffect(material.resolveProperty("walkingSounds"), Mode.NORMAL, getLocation(), (float) (0.9f + Math.sqrt(getVelocityComponent().getVelocity().x() * getVelocityComponent().getVelocity().x() + getVelocityComponent().getVelocity().z() * getVelocityComponent().getVelocity().z()) * 0.1f), 1f).setAttenuationEnd(10);
        else
            getWorld().getSoundManager().playSoundEffect(material.resolveProperty("runningSounds"), Mode.NORMAL, getLocation(), (float) (0.9f + Math.sqrt(getVelocityComponent().getVelocity().x() * getVelocityComponent().getVelocity().x() + getVelocityComponent().getVelocity().z() * getVelocityComponent().getVelocity().z()) * 0.1f), 1f).setAttenuationEnd(10);
    }
}
Also used : Vector3d(org.joml.Vector3d) ItemVoxel(io.xol.chunkstories.api.item.ItemVoxel) Voxel(io.xol.chunkstories.api.voxel.Voxel) VoxelMaterial(io.xol.chunkstories.api.voxel.materials.VoxelMaterial) WorldClient(io.xol.chunkstories.api.world.WorldClient)

Example 80 with Vector3d

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

the class ItemFirearm method drawItemOverlay.

@Override
public void drawItemOverlay(RenderingInterface renderingInterface, ItemPile pile) {
    EntityLiving clientControlledEntity = (EntityLiving) renderingInterface.getClient().getPlayer().getControlledEntity();
    if (clientControlledEntity != null && pile.getInventory() != null && pile.getInventory().getHolder() != null && pile.getInventory().getHolder().equals(clientControlledEntity)) {
        if (isScoped())
            drawScope(renderingInterface);
        Vector3d eyeLocation = new Vector3d(clientControlledEntity.getLocation());
        if (clientControlledEntity instanceof EntityPlayer)
            eyeLocation.add(new Vector3d(0.0, ((EntityPlayer) clientControlledEntity).eyePosition, 0.0));
        Vector3d direction = new Vector3d(clientControlledEntity.getDirectionLookingAt());
        direction.add(new Vector3d(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5).normalize().mul(accuracy / 100d));
        direction.normalize();
        // display reload cooldownt text
        if (cooldownEnd > System.currentTimeMillis()) {
            String reloadText = "Reloading weapon, please wait";
            Font font = renderingInterface.getFontRenderer().defaultFont();
            // TrueTypeFont.arial11px.getWidth(reloadText);
            int cooldownLength = font.getWidth(reloadText);
            renderingInterface.getFontRenderer().drawString(font, -cooldownLength + renderingInterface.getWindow().getWidth() / 2, renderingInterface.getWindow().getHeight() / 2, reloadText, 2);
        }
    }
}
Also used : EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) Vector3d(org.joml.Vector3d) EntityPlayer(io.xol.chunkstories.core.entity.EntityPlayer) Font(io.xol.chunkstories.api.rendering.text.FontRenderer.Font)

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