use of org.valkyrienskies.mod.common.collision.Polygon in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsObject method getPhysicsTransformAABB.
public AxisAlignedBB getPhysicsTransformAABB() {
AxisAlignedBB subspaceBB = getBlockPositions().makeAABB();
if (subspaceBB == null) {
// The aabbMaker didn't know what the aabb was, just don't update the aabb for now.
return null;
}
// Expand subspaceBB by 1 to fit the block grid.
subspaceBB = subspaceBB.expand(1, 1, 1);
// Now transform the subspaceBB to world coordinates
Polygon largerPoly = new Polygon(subspaceBB, getShipTransformationManager().getCurrentPhysicsTransform(), TransformType.SUBSPACE_TO_GLOBAL);
// Set the ship AABB to that of the polygon.
AxisAlignedBB worldBB = largerPoly.getEnclosedAABB();
return worldBB;
}
use of org.valkyrienskies.mod.common.collision.Polygon in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ValkyrienUtils method transformEntity.
/**
* Applies the given transform matrix to the position/velocity/look of the given entity.
* @param transform The transform matrix to be applied.
* @param entity The entity that will be transformed.
*/
public void transformEntity(final Matrix4dc transform, final Entity entity, final boolean transformEntityBoundingBox) {
Vec3d entityLookMc = entity.getLook(1.0F);
Vector3d entityPos = new Vector3d(entity.posX, entity.posY, entity.posZ);
Vector3d entityLook = new Vector3d(entityLookMc.x, entityLookMc.y, entityLookMc.z);
Vector3d entityMotion = new Vector3d(entity.motionX, entity.motionY, entity.motionZ);
if (entity instanceof EntityFireball) {
EntityFireball ball = (EntityFireball) entity;
entityMotion.x = ball.accelerationX;
entityMotion.y = ball.accelerationY;
entityMotion.z = ball.accelerationZ;
}
transform.transformPosition(entityPos);
transform.transformDirection(entityLook);
transform.transformDirection(entityMotion);
entityLook.normalize();
// This is correct, works properly when tested with cows
if (entity instanceof EntityLiving) {
EntityLiving living = (EntityLiving) entity;
living.rotationYawHead = entity.rotationYaw;
living.prevRotationYawHead = entity.rotationYaw;
}
// Get the player pitch/yaw from the look vector
final Tuple<Double, Double> pitchYawTuple = VSMath.getPitchYawFromVector(new Vector3d(entityLook.x, entityLook.y, entityLook.z));
entity.rotationPitch = pitchYawTuple.getFirst().floatValue();
entity.rotationYaw = pitchYawTuple.getSecond().floatValue();
if (entity instanceof EntityFireball) {
EntityFireball ball = (EntityFireball) entity;
ball.accelerationX = entityMotion.x;
ball.accelerationY = entityMotion.y;
ball.accelerationZ = entityMotion.z;
}
entity.motionX = entityMotion.x;
entity.motionY = entityMotion.y;
entity.motionZ = entityMotion.z;
if (transformEntityBoundingBox) {
// Transform the bounding box too
final AxisAlignedBB oldBB = entity.getEntityBoundingBox();
final Polygon newBBPoly = new Polygon(oldBB, transform);
final AxisAlignedBB newBB = newBBPoly.getEnclosedAABB();
final double oldBBSize = (oldBB.maxX - oldBB.minX) * (oldBB.maxY - oldBB.minY) * (oldBB.maxZ - oldBB.minZ);
final double newBBSize = (newBB.maxX - newBB.minX) * (newBB.maxY - newBB.minY) * (newBB.maxZ - newBB.minZ);
final double scaleFactor = Math.pow(oldBBSize / newBBSize, 1.0 / 3.0);
// Scale the bounding box such that the new bounding box is the same size as the old bounding box.
final AxisAlignedBB newBBScaled = newBB.grow((scaleFactor - 1) * (newBB.maxX - newBB.minX) / 2.0, (scaleFactor - 1) * (newBB.maxY - newBB.minY) / 2.0, (scaleFactor - 1) * (newBB.maxZ - newBB.minZ) / 2.0);
entity.setPosition(entityPos.x, entityPos.y, entityPos.z);
entity.setEntityBoundingBox(newBBScaled);
} else {
// Just use the regular bounding box
entity.setPosition(entityPos.x, entityPos.y, entityPos.z);
}
}
Aggregations