use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class TileEntityBoatChair method getTorqueInGlobal.
@Nullable
public Vector3dc getTorqueInGlobal(PhysicsCalculations physicsCalculations) {
// Don't add force if theres no pilot
if (getPilotEntity() == null) {
return null;
}
final PhysicsObject physicsObject = physicsCalculations.getParent();
final ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentPhysicsTransform();
final Vector3dc idealAngularVelocity = shipTransform.transformDirectionNew(new Vector3d(targetAngularVelocity), TransformType.SUBSPACE_TO_GLOBAL);
final Vector3dc currentAngularVelocity = physicsCalculations.getAngularVelocity();
final Vector3dc velocityDifference = idealAngularVelocity.sub(currentAngularVelocity, new Vector3d());
final Vector3d resultingTorque = physicsCalculations.getPhysMOITensor().transform(velocityDifference, new Vector3d());
resultingTorque.mul(physicsCalculations.getPhysicsTimeDeltaPerPhysTick());
resultingTorque.mul(ANGULAR_EMA_FILTER_CONSTANT);
// Only effect y axis
resultingTorque.x = 0;
resultingTorque.z = 0;
// Add a stabilization torque
final Vector3dc shipUp = shipTransform.transformDirectionNew(new Vector3d(0, 1, 0), TransformType.SUBSPACE_TO_GLOBAL);
final Vector3dc idealUp = new Vector3d(0, 1, 0);
final double angleBetween = shipUp.angle(idealUp);
if (angleBetween > .01) {
final Vector3dc stabilizationRotationAxisNormalized = shipUp.cross(idealUp, new Vector3d()).normalize();
final Vector3d stabilizationTorque = physicsCalculations.getPhysMOITensor().transform(stabilizationRotationAxisNormalized.mul(angleBetween, new Vector3d()));
stabilizationTorque.mul(physicsCalculations.getPhysicsTimeDeltaPerPhysTick());
stabilizationTorque.mul(STABILIZATION_TORQUE_CONSTANT);
resultingTorque.add(stabilizationTorque);
}
return resultingTorque;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class FixAccurateRain method getRainPosFromShips.
public static BlockPos getRainPosFromShips(final World world, final BlockPos originalHeight) {
if (VSConfig.accurateRain && Minecraft.getMinecraft().player != null) {
final AxisAlignedBB boundingBox = new AxisAlignedBB(originalHeight.getX() - .5, 0, originalHeight.getZ() - .5, originalHeight.getX() + .5, 255, originalHeight.getZ() + .5);
final List<PhysicsObject> physicsObjectList = ValkyrienUtils.getPhysObjWorld(world).getPhysObjectsInAABB(boundingBox);
final Vec3d traceStart = new Vec3d(originalHeight.getX() + .5, Minecraft.getMinecraft().player.posY + 50, originalHeight.getZ() + .5);
final Vec3d traceEnd = new Vec3d(originalHeight.getX() + .5, originalHeight.getY() + .5, originalHeight.getZ() + .5);
if (traceStart.y < traceEnd.y) {
return originalHeight;
}
for (final PhysicsObject physicsObject : physicsObjectList) {
final RayTraceResult result = ((IWorldVS) world).rayTraceBlocksInShip(traceStart, traceEnd, true, true, false, physicsObject);
// noinspection ConstantConditions
if (result != null && result.getBlockPos() != null && result.typeOfHit != RayTraceResult.Type.MISS) {
Vector3d blockPosVector = JOML.convertDouble(result.getBlockPos()).add(.5, .5, .5);
physicsObject.getShipTransformationManager().getCurrentTickTransform().getSubspaceToGlobal().transformPosition(blockPosVector);
return new BlockPos(originalHeight.getX(), blockPosVector.y(), originalHeight.getZ());
}
}
}
return originalHeight;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class VSDarknessLibAPILightProvider method apply.
@Override
public Integer apply(final EntityPlayer entityPlayer) {
final World world = entityPlayer.world;
final AxisAlignedBB searchBB = new AxisAlignedBB(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ, entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ).grow(8);
final List<PhysicsObject> nearbyShips = ValkyrienUtils.getPhysObjWorld(world).getPhysObjectsInAABB(searchBB);
final Vector3d temp0 = new Vector3d();
final BlockPos.MutableBlockPos temp1 = new BlockPos.MutableBlockPos();
int maxLight = 0;
for (final PhysicsObject physicsObject : nearbyShips) {
final Vector3dc positionInShip = physicsObject.getShipTransform().transformPositionNew(temp0.set(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ), TransformType.GLOBAL_TO_SUBSPACE);
final BlockPos blockPosInShip = temp1.setPos(positionInShip.x(), positionInShip.y(), positionInShip.z());
final int blockLight = getLightFromNeighborsFor(world, EnumSkyBlock.BLOCK, blockPosInShip);
maxLight = Math.max(blockLight, maxLight);
}
return maxLight;
}
use of org.valkyrienskies.mod.common.ships.ship_world.PhysicsObject in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class VSWorldPhysicsLoop method physicsTick.
private void physicsTick(double delta) {
// Update the immutable ship list.
immutableShipsList = ((IHasShipManager) hostWorld).getManager().getAllLoadedThreadSafe();
// Run tasks queued to run on physics thread
recurringTasks.forEach(t -> t.runTask(delta));
taskQueue.forEach(Runnable::run);
taskQueue.clear();
// Make a sublist of physics objects to process physics on.
List<PhysicsObject> physicsEntitiesToDoPhysics = new ArrayList<>();
for (PhysicsObject physicsObject : immutableShipsList) {
if (physicsObject.isPhysicsReady() && physicsObject.isPhysicsEnabled() && physicsObject.getCachedSurroundingChunks() != null) {
physicsEntitiesToDoPhysics.add(physicsObject);
}
}
// Finally, actually process the physics tick
tickThePhysicsAndCollision(physicsEntitiesToDoPhysics, delta);
// Send ship position update packets around 20 times a second
final long currentTimeMillis = System.currentTimeMillis();
final double secondsSinceLastPacket = (currentTimeMillis - lastPacketSendTime) / 1000.0;
// Use .04 to guarantee we're always sending at least 20 packets per second
if (secondsSinceLastPacket > .04) {
// Update the last update time
lastPacketSendTime = currentTimeMillis;
try {
// At the end, send the transform update packets
final ShipTransformUpdateMessage shipTransformUpdateMessage = new ShipTransformUpdateMessage();
final int dimensionID = hostWorld.provider.getDimension();
shipTransformUpdateMessage.setDimensionID(dimensionID);
for (final PhysicsObject physicsObject : immutableShipsList) {
final UUID shipUUID = physicsObject.getUuid();
final ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentPhysicsTransform();
final AxisAlignedBB shipBB = physicsObject.getPhysicsTransformAABB();
shipTransformUpdateMessage.addData(shipUUID, shipTransform, shipBB);
}
ValkyrienSkiesMod.physWrapperTransformUpdateNetwork.sendToDimension(shipTransformUpdateMessage, shipTransformUpdateMessage.getDimensionID());
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations