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());
}
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);
}
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();
}
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);
}
}
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);
}
}
}
Aggregations