use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipPilot method processControlMessage.
public void processControlMessage(PilotControlsMessage message, EntityPlayerMP sender) {
final double pilotYaw = -initialYaw - 90;
// Linear velocity
final Vector3d newTargetLinearVelocity = new Vector3d();
if (message.airshipForward_KeyDown) {
newTargetLinearVelocity.x += MAX_LINEAR_VELOCITY;
}
if (message.airshipBackward_KeyDown) {
newTargetLinearVelocity.x -= MAX_LINEAR_VELOCITY;
}
if (message.airshipSprinting) {
newTargetLinearVelocity.mul(2);
}
newTargetLinearVelocity.rotateAxis(Math.toRadians(pilotYaw), 0, 1, 0);
// Angular velocity
final Vector3d newTargetAngularVelocity = new Vector3d();
if (message.airshipLeft_KeyDown) {
newTargetAngularVelocity.y += MAX_ANGULAR_VELOCITY;
}
if (message.airshipRight_KeyDown) {
newTargetAngularVelocity.y -= MAX_ANGULAR_VELOCITY;
}
// Update the target velocities
targetLinearVelocity = newTargetLinearVelocity;
targetAngularVelocity = newTargetAngularVelocity;
// Check if we need to stop piloting
}
use of org.joml.Vector3d 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.joml.Vector3d 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.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsCalculations method rawPhysTickPostCol.
public void rawPhysTickPostCol() {
if (!isPhysicsBroken()) {
// This wasn't implemented very well at all! Maybe in the future I'll try again.
// enforceStaticFriction();
integrateAngularVelocity();
integrateLinearVelocity();
} else {
getParent().getShipData().setPhysicsEnabled(false);
getLinearVelocity().zero();
getAngularVelocity().zero();
}
// Keep track of the forced transform, if there is one
final boolean forceToUseGameTransformLocalCopy = this.forceToUseGameTransform;
// Reset the forced transform
this.forceToUseGameTransform = false;
if (forceToUseGameTransformLocalCopy) {
// Reset the physics transform to be the game tick transform
generatePhysicsTransform();
// Reset angular and linear velocities
angularVelocity.zero();
linearVelocity.zero();
}
ShipTransform finalPhysTransform = new ShipTransform(physX, physY, physZ, physRotation, physCenterOfMass);
getParent().getShipTransformationManager().updatePreviousPhysicsTransform();
getParent().getShipTransformationManager().setCurrentPhysicsTransform(finalPhysTransform);
// Save a copy of linear and angular velocity in parent's ShipData
getParent().getShipData().getPhysicsData().setAngularVelocity(new Vector3d(angularVelocity));
getParent().getShipData().getPhysicsData().setLinearVelocity(new Vector3d(linearVelocity));
}
use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsCalculations method convertTorqueToVelocity.
private void convertTorqueToVelocity() {
Vector3d torqueTransformed = new Vector3d(torque);
getPhysInvMOITensor().transform(torqueTransformed);
getAngularVelocity().add(torqueTransformed.x, torqueTransformed.y, torqueTransformed.z);
torque.zero();
}
Aggregations