use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class TileEntityCaptainsChair method processCalculationsForControlMessageAndApplyCalculations.
private void processCalculationsForControlMessageAndApplyCalculations(PhysicsObject controlledShip, PilotControlsMessage message, IBlockState state) {
BlockPos chairPosition = getPos();
if (controlledShip.isShipAligningToGrid()) {
return;
}
double pilotPitch = 0D;
double pilotYaw = ((BlockCaptainsChair) state.getBlock()).getChairYaw(state, chairPosition);
double pilotRoll = 0D;
Matrix3d pilotRotationMatrix = new Matrix3d();
pilotRotationMatrix.rotateXYZ(Math.toRadians(pilotPitch), Math.toRadians(pilotYaw), Math.toRadians(pilotRoll));
Vector3d playerDirection = new Vector3d(1, 0, 0);
pilotRotationMatrix.transform(playerDirection);
Vector3d upDirection = new Vector3d(0, 1, 0);
Vector3d downDirection = new Vector3d(0, -1, 0);
Vector3d idealAngularDirection = new Vector3d();
Vector3d idealLinearVelocity = new Vector3d();
Vector3d shipUp = new Vector3d(0, 1, 0);
Vector3d shipUpPosIdeal = new Vector3d(0, 1, 0);
if (message.airshipForward_KeyDown) {
idealLinearVelocity.add(playerDirection);
}
if (message.airshipBackward_KeyDown) {
idealLinearVelocity.sub(playerDirection);
}
controlledShip.getShipTransformationManager().getCurrentTickTransform().transformDirection(idealLinearVelocity, TransformType.SUBSPACE_TO_GLOBAL);
controlledShip.getShipTransformationManager().getCurrentTickTransform().transformDirection(shipUp, TransformType.SUBSPACE_TO_GLOBAL);
if (message.airshipUp_KeyDown) {
idealLinearVelocity.add(upDirection.mul(.5, new Vector3d()));
}
if (message.airshipDown_KeyDown) {
idealLinearVelocity.add(downDirection.mul(.5, new Vector3d()));
}
double sidePitch = 0;
if (message.airshipRight_KeyDown) {
idealAngularDirection.sub(shipUp);
sidePitch -= 10;
}
if (message.airshipLeft_KeyDown) {
idealAngularDirection.add(shipUp);
sidePitch += 10;
}
Vector3d sidesRotationAxis = new Vector3d(playerDirection);
controlledShip.getShipTransformationManager().getCurrentTickTransform().transformDirection(sidesRotationAxis, TransformType.SUBSPACE_TO_GLOBAL);
AxisAngle4d rotationSidesTransform = new AxisAngle4d(Math.toRadians(sidePitch), sidesRotationAxis.x, sidesRotationAxis.y, sidesRotationAxis.z);
rotationSidesTransform.transform(shipUpPosIdeal);
idealAngularDirection.mul(2);
// The vector that points in the direction of the normal of the plane that
// contains shipUp and shipUpPos. This is our axis of rotation.
Vector3d shipUpRotationVector = shipUp.cross(shipUpPosIdeal, new Vector3d());
// This isnt quite right, but it handles the cases quite well.
double shipUpTheta = shipUp.angle(shipUpPosIdeal) + Math.PI;
shipUpRotationVector.mul(shipUpTheta);
idealAngularDirection.add(shipUpRotationVector);
idealLinearVelocity.mul(20);
// Move the ship faster if the player holds the sprint key.
if (message.airshipSprinting) {
idealLinearVelocity.mul(2);
}
double lerpFactor = .2;
Vector3d linearMomentumDif = controlledShip.getPhysicsCalculations().getLinearVelocity().sub(idealLinearVelocity, new Vector3d());
Vector3d angularVelocityDif = controlledShip.getPhysicsCalculations().getAngularVelocity().sub(idealAngularDirection, new Vector3d());
linearMomentumDif.mul(lerpFactor);
angularVelocityDif.mul(lerpFactor);
controlledShip.getPhysicsCalculations().getLinearVelocity().sub(linearMomentumDif);
controlledShip.getPhysicsCalculations().getAngularVelocity().sub(angularVelocityDif);
}
use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ValkyrienNBTUtils method readVectorFromNBT.
public static Vector3d readVectorFromNBT(String name, NBTTagCompound compound) {
Vector3d vector = new Vector3d();
vector.x = compound.getDouble(name + "X");
vector.y = compound.getDouble(name + "Y");
vector.z = compound.getDouble(name + "Z");
return vector;
}
use of org.joml.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class TileEntityBoatChair method processControlMessage.
@Override
public void processControlMessage(PilotControlsMessage message, EntityPlayerMP sender) {
final IBlockState state = getWorld().getBlockState(getPos());
final double pilotYaw = ((BlockBoatChair) state.getBlock()).getChairYaw(state);
// 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;
}
use of org.joml.Vector3d 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.Vector3d in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class TileEntityBoatChair method onStopTileUsage.
@Override
public void onStopTileUsage() {
targetLinearVelocity = new Vector3d();
targetAngularVelocity = new Vector3d();
}
Aggregations