use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class SimpleEMATransformInterpolator method tickTransformInterpolator.
@Override
public void tickTransformInterpolator() {
// First compute the new position
Vector3dc curPos = new Vector3d(curTickTransform.getPosX(), curTickTransform.getPosY(), curTickTransform.getPosZ());
// If the new center coord != current center coord, then offset the current position by the difference
if (!latestReceivedTransform.getCenterCoord().equals(curTickTransform.getCenterCoord(), DOUBLE_EQUALS_THRESHOLD)) {
// Add newCenter - oldCenter to the curPos
Vector3d offset = latestReceivedTransform.getCenterCoord().sub(curTickTransform.getCenterCoord(), new Vector3d());
curTickTransform.transformDirection(offset, TransformType.SUBSPACE_TO_GLOBAL);
curPos = curPos.add(offset, new Vector3d());
}
Vector3dc latestDataPos = new Vector3d(latestReceivedTransform.getPosX(), latestReceivedTransform.getPosY(), latestReceivedTransform.getPosZ());
Vector3dc newPos = curPos.lerp(latestDataPos, filterAlpha, new Vector3d());
// Then compute the new rotation
Quaterniondc curRot = curTickTransform.rotationQuaternion(TransformType.SUBSPACE_TO_GLOBAL);
Quaterniondc latestDataRot = latestReceivedTransform.rotationQuaternion(TransformType.SUBSPACE_TO_GLOBAL);
Quaterniondc newRot = curRot.slerp(latestDataRot, filterAlpha, new Quaterniond()).normalize();
// Then create the new transform using the new position and rotation (and center coord)
curTickTransform = new ShipTransform(newPos, newRot, latestReceivedTransform.getCenterCoord());
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform 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