use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipPilot method getTorqueInGlobal.
public Vector3dc getTorqueInGlobal(PhysicsCalculations physicsCalculations) {
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_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ItemShipTracker method onItemRightClick.
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand hand) {
if (!worldIn.isRemote) {
final ItemStack heldItemStack = player.getHeldItem(hand);
final NBTTagCompound stackTagCompound;
if (heldItemStack.hasTagCompound()) {
stackTagCompound = heldItemStack.stackTagCompound;
} else {
stackTagCompound = new NBTTagCompound();
}
if (stackTagCompound.hasKey(NBT_DATA_KEY)) {
// Tell the player the ship location
final UUID shipUUID = UUID.fromString(stackTagCompound.getString(NBT_DATA_KEY));
final Optional<ShipData> shipDataOptional = ValkyrienUtils.getQueryableData(worldIn).getShip(shipUUID);
if (shipDataOptional.isPresent()) {
final ShipData shipData = shipDataOptional.get();
final ShipTransform currentTransform = shipData.getShipTransform();
final Vector3d shipPosition = new Vector3d(currentTransform.getPosX(), currentTransform.getPosY(), currentTransform.getPosZ());
// Only print up to 2 digits after the decimal place
final String shipPositionString = shipPosition.toString(new DecimalFormat("############.##"));
player.sendMessage(new TextComponentString(String.format("The ship %s is currently at %s.", shipData.getName(), shipPositionString)));
} else {
player.sendMessage(new TextComponentString(String.format("No ship with UUID %s found! Maybe it was destroyed.", shipUUID.toString())));
}
} else {
player.sendMessage(new TextComponentString("Not tracking any ships. Right click on a ship to track it."));
}
}
return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PlayerMovementDataGenerator method generatePlayerMovementDataForClient.
/**
* Only works on the client.
*/
public static PlayerMovementData generatePlayerMovementDataForClient() {
final EntityPlayerSP entityPlayer = Minecraft.getMinecraft().player;
final EntityShipMovementData entityShipMovementData = ValkyrienUtils.getEntityShipMovementDataFor(entityPlayer);
final ShipData lastTouchedShip = entityShipMovementData.getLastTouchedShip();
final UUID lastTouchedShipId = lastTouchedShip != null ? lastTouchedShip.getUuid() : null;
final Vector3d playerPosInLocal = new Vector3d(entityPlayer.posX, entityPlayer.posY, entityPlayer.posZ);
final Vector3d playerLookInLocal = JOML.convert(entityPlayer.getLook(1));
final boolean onGround = entityPlayer.onGround;
if (lastTouchedShip != null) {
final ShipTransform shipTransform = lastTouchedShip.getShipTransform();
shipTransform.transformPosition(playerPosInLocal, TransformType.GLOBAL_TO_SUBSPACE);
shipTransform.transformDirection(playerLookInLocal, TransformType.GLOBAL_TO_SUBSPACE);
}
return new PlayerMovementData(lastTouchedShipId, entityShipMovementData.getTicksSinceTouchedShip(), entityShipMovementData.getTicksPartOfGround(), playerPosInLocal, playerLookInLocal, onGround);
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipTransformUpdateMessage method fromBytes.
@Override
public void fromBytes(ByteBuf buf) {
PacketBuffer packetBuffer = new PacketBuffer(buf);
int numberOfShips = packetBuffer.readInt();
for (int i = 0; i < numberOfShips; i++) {
UUID shipID = null;
ShipTransform shipTransform = null;
AxisAlignedBB axisAlignedBB = null;
// Read the UUID
{
int bytesSize = packetBuffer.readInt();
byte[] bytes = new byte[bytesSize];
packetBuffer.readBytes(bytes);
try {
shipID = serializer.readValue(bytes, UUID.class);
} catch (IOException e) {
e.printStackTrace();
}
}
// Read the ship transform
{
int bytesSize = packetBuffer.readInt();
byte[] bytes = new byte[bytesSize];
packetBuffer.readBytes(bytes);
try {
shipTransform = serializer.readValue(bytes, ShipTransform.class);
} catch (IOException e) {
e.printStackTrace();
}
}
// Read the ship aabb
{
int bytesSize = packetBuffer.readInt();
byte[] bytes = new byte[bytesSize];
packetBuffer.readBytes(bytes);
try {
axisAlignedBB = serializer.readValue(bytes, AxisAlignedBB.class);
} catch (IOException e) {
e.printStackTrace();
}
}
if (shipID == null || shipTransform == null || axisAlignedBB == null) {
// corrupt packet
shipTransforms.clear();
return;
}
shipTransforms.put(shipID, new Tuple<>(shipTransform, axisAlignedBB));
}
dimensionID = packetBuffer.readInt();
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipTransformUpdateMessageHandler method onMessage.
@Override
@SuppressWarnings("Convert2Lambda")
public // errors. DON'T USE A LAMBDA
IMessage onMessage(final ShipTransformUpdateMessage message, final MessageContext ctx) {
IThreadListener mainThread = Minecraft.getMinecraft();
mainThread.addScheduledTask(new Runnable() {
@Override
public void run() {
World world = Minecraft.getMinecraft().world;
IPhysObjectWorld physObjectWorld = ValkyrienUtils.getPhysObjWorld(world);
QueryableShipData worldData = QueryableShipData.get(world);
for (Map.Entry<UUID, Tuple<ShipTransform, AxisAlignedBB>> transformUpdate : message.shipTransforms.entrySet()) {
final UUID shipID = transformUpdate.getKey();
final ShipTransform shipTransform = transformUpdate.getValue().getFirst();
final AxisAlignedBB shipBB = transformUpdate.getValue().getSecond();
final PhysicsObject physicsObject = ValkyrienUtils.getPhysObjWorld(world).getPhysObjectFromUUID(shipID);
if (physicsObject != null) {
// Do not update the transform in ShipData, that will be done by PhysicsObject.tick()
ITransformInterpolator interpolator = physicsObject.getTransformInterpolator();
interpolator.onNewTransformPacket(shipTransform, shipBB);
}
}
}
});
return null;
}
Aggregations