use of org.joml.Vector3dc in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PlayerMovementData method readData.
/**
* Reads the raw packet data from the data stream.
*/
public static PlayerMovementData readData(final PacketBuffer packetBuffer) {
final boolean hasLastTouchShipId = packetBuffer.readBoolean();
final UUID lastTouchedShipId = hasLastTouchShipId ? packetBuffer.readUniqueId() : null;
final int ticksSinceTouchedLastShip = packetBuffer.readInt();
final int ticksPartOfGround = packetBuffer.readInt();
final Vector3dc playerPosInShip = JOML.readFromByteBuf(packetBuffer);
final Vector3dc playerLookInShip = JOML.readFromByteBuf(packetBuffer);
final boolean onGround = packetBuffer.readBoolean();
return new PlayerMovementData(lastTouchedShipId, ticksSinceTouchedLastShip, ticksPartOfGround, playerPosInShip, playerLookInShip, onGround);
}
use of org.joml.Vector3dc in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class BlockPhysicsDetails method getForceFromState.
/**
* Assigns the output parameter of toSet to be the force Vector for the given IBlockState.
*/
static void getForceFromState(IBlockState state, BlockPos pos, World world, double secondsToApply, PhysicsObject obj, Vector3d toSet) {
Block block = state.getBlock();
if (block instanceof IBlockForceProvider) {
Vector3dc forceVector = ((IBlockForceProvider) block).getBlockForceInWorldSpace(world, pos, state, obj, secondsToApply);
if (forceVector == null) {
toSet.zero();
} else {
toSet.x = forceVector.x();
toSet.y = forceVector.y();
toSet.z = forceVector.z();
}
}
}
use of org.joml.Vector3dc in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsCalculations method updatePhysCenterOfMass.
/**
* Updates the physics center of mass to the game center of mass; does not do any transformation
* updates on its own.
*/
private void updatePhysCenterOfMass() {
Vector3dc gameTickCM = parent.getInertiaData().getGameTickCenterOfMass();
if (!physCenterOfMass.equals(gameTickCM)) {
Vector3d CMDif = gameTickCM.sub(physCenterOfMass, new Vector3d());
getParent().getShipTransformationManager().getCurrentPhysicsTransform().transformDirection(CMDif, TransformType.SUBSPACE_TO_GLOBAL);
physX += CMDif.x;
physY += CMDif.y;
physZ += CMDif.z;
physCenterOfMass = gameTickCM;
}
}
use of org.joml.Vector3dc in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class TileEntityBoatChair method getBlockForceInShipSpace.
@Nullable
public Vector3dc getBlockForceInShipSpace(World world, BlockPos pos, IBlockState state, PhysicsObject physicsObject, double secondsToApply) {
// Don't add force if theres no pilot
if (getPilotEntity() == null) {
return null;
}
final ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentPhysicsTransform();
final Vector3dc idealLinearVelocity = shipTransform.transformDirectionNew(new Vector3d(targetLinearVelocity), TransformType.SUBSPACE_TO_GLOBAL);
final Vector3dc currentLinearVelocity = physicsObject.getPhysicsCalculations().getLinearVelocity();
final Vector3dc velocityDifference = idealLinearVelocity.sub(currentLinearVelocity, new Vector3d());
final Vector3d resultingBlockForce = new Vector3d(velocityDifference);
resultingBlockForce.mul(physicsObject.getInertiaData().getGameTickMass());
resultingBlockForce.mul(secondsToApply);
resultingBlockForce.mul(LINEAR_EMA_FILTER_CONSTANT);
// Do not affect y axis
resultingBlockForce.y = 0;
return resultingBlockForce;
}
use of org.joml.Vector3dc in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ValkyrienUtils method createNewShip.
/**
* Creates a new ShipIndexedData based on the inputs provided by the physics infuser block.
*/
public ShipData createNewShip(World world, BlockPos physInfuserPos) {
String name = NounListNameGenerator.getInstance().generateName();
UUID shipID = UUID.randomUUID();
// Create ship chunk claims
VSChunkClaim chunkClaim = ValkyrienUtils.getShipChunkAllocator(world).allocateNextChunkClaim();
Vector3dc centerOfMassInitial = VSMath.toVector3d(chunkClaim.getRegionCenter());
Vector3dc shipPosInitial = VSMath.toVector3d(physInfuserPos);
ShipTransform initial = new ShipTransform(shipPosInitial, centerOfMassInitial);
AxisAlignedBB axisAlignedBB = new AxisAlignedBB(shipPosInitial.x(), shipPosInitial.y(), shipPosInitial.z(), shipPosInitial.x(), shipPosInitial.y(), shipPosInitial.z());
return ShipData.createData(QueryableShipData.get(world).getAllShips(), name, chunkClaim, shipID, initial, axisAlignedBB);
}
Aggregations