use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class IBlockForceProvider method getBlockForceInWorldSpace.
/**
* The World space version of the force vector, calculated by default from the Ship space
* vector, do not override unless you have a good reason to.
*/
@Nullable
default Vector3dc getBlockForceInWorldSpace(World world, BlockPos pos, IBlockState state, PhysicsObject physicsObject, double secondsToApply) {
Vector3dc toReturn = getBlockForceInShipSpace(world, pos, state, physicsObject, secondsToApply);
if (toReturn == null) {
return null;
}
if (shouldLocalForceBeRotated(world, pos, state, secondsToApply)) {
ShipTransform shipTransform = physicsObject.getShipTransformationManager().getCurrentTickTransform();
Vector3d rotated = new Vector3d(toReturn);
shipTransform.transformDirection(rotated, TransformType.SUBSPACE_TO_GLOBAL);
return rotated;
}
return toReturn;
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysObjectRenderManager method renderDebugInfo.
/**
* Renders bounding boxes for this ship's AABB and center of mass relative to the offset
* (probably the negative player's position). Used in F3+D
*/
public void renderDebugInfo(double offsetX, double offsetY, double offsetZ) {
GlStateManager.pushMatrix();
AxisAlignedBB shipBB = parent.getShipBB().offset(offsetX, offsetY, offsetZ);
ShipTransform renderTransform = parent.getShipTransformationManager().getRenderTransform();
Vector3dc centerOfMass = parent.getShipData().getInertiaData().getGameTickCenterOfMass();
Vector3d centerOfMassPos = new Vector3d(centerOfMass);
parent.getShipTransformationManager().getRenderTransform().transformPosition(centerOfMassPos, TransformType.SUBSPACE_TO_GLOBAL);
AxisAlignedBB centerOfMassBB = new AxisAlignedBB(JOML.toMinecraft(centerOfMassPos), JOML.toMinecraft(centerOfMassPos)).grow(.1).offset(offsetX, offsetY, offsetZ);
GlStateManager.depthMask(false);
GlStateManager.disableTexture2D();
GlStateManager.disableLighting();
GlStateManager.disableCull();
GlStateManager.disableBlend();
// Draw the bounding box for the ship.
RenderGlobal.drawSelectionBoundingBox(shipBB, 1.0F, 1.0F, 1.0F, 1.0F);
// region Render claimed chunks
if (VSConfig.renderShipChunkClaimsInDebug) {
GlStateManager.pushMatrix();
GlStateManager.translate((float) renderTransform.getPosX() + offsetX, (float) renderTransform.getPosY() + offsetY, (float) renderTransform.getPosZ() + offsetZ);
Vector3dc angles = renderTransform.getSubspaceToGlobal().getEulerAnglesZYX(new Vector3d());
GlStateManager.rotate((float) Math.toDegrees(angles.z()), 0, 0, 1);
GlStateManager.rotate((float) Math.toDegrees(angles.y()), 0, 1, 0);
GlStateManager.rotate((float) Math.toDegrees(angles.x()), 1, 0, 0);
for (ChunkPos claimedChunk : parent.getChunkClaim()) {
AxisAlignedBB claimBB = new AxisAlignedBB(claimedChunk.getXStart() + .1, renderTransform.getCenterCoord().y() - 8 + 0.1, claimedChunk.getZStart() + .1, claimedChunk.getXEnd() + .9, renderTransform.getCenterCoord().y() + 8 - .1, claimedChunk.getZEnd() + .9);
claimBB = claimBB.offset(-renderTransform.getCenterCoord().x(), -renderTransform.getCenterCoord().y(), -renderTransform.getCenterCoord().z());
RenderGlobal.drawSelectionBoundingBox(claimBB, 0, 1.0F, 0, 1.0F);
}
GlStateManager.popMatrix();
}
// endregion
// Draw the center of mass bounding box.
GlStateManager.disableDepth();
RenderGlobal.drawSelectionBoundingBox(centerOfMassBB, 0, 0, 1.0F, 1.0F);
GlStateManager.enableDepth();
GlStateManager.enableTexture2D();
GlStateManager.enableLighting();
GlStateManager.enableCull();
GlStateManager.disableBlend();
GlStateManager.depthMask(true);
// Draw a text box that shows the numerical value of the center of mass.
String centerOfMassStr = "Center of Mass: " + (new Vector3d(centerOfMass)).toString(new DecimalFormat("############.##"));
renderTextBox(centerOfMassStr, renderTransform.getPosX(), renderTransform.getPosY() + .5, renderTransform.getPosZ(), offsetX, offsetY, offsetZ);
String massStr = String.format("Mass: %.2f", parent.getShipData().getInertiaData().getGameTickMass());
renderTextBox(massStr, renderTransform.getPosX(), renderTransform.getPosY() + 1, renderTransform.getPosZ(), offsetX, offsetY, offsetZ);
GlStateManager.popMatrix();
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class MainCommand method teleportShipToPosition.
private static void teleportShipToPosition(final ShipData ship, final Vec3d position, final ICommandSender sender) {
try {
final World world = sender.getEntityWorld();
final WorldServerShipManager shipManager = ValkyrienUtils.getServerShipManager(world);
final PhysicsObject shipObject = shipManager.getPhysObjectFromUUID(ship.getUuid());
// Create the new ship transform that moves the ship to this position
final ShipTransform shipTransform = ship.getShipTransform();
final ShipTransform newTransform = new ShipTransform(JOML.convert(position), shipTransform.getCenterCoord());
if (shipObject != null) {
// The ship already exists in the world, so we need to update the physics transform as well
final PhysicsCalculations physicsCalculations = shipObject.getPhysicsCalculations();
physicsCalculations.setForceToUseGameTransform(true);
// Also update the transform in the ShipTransformationManager
shipObject.setForceToUseShipDataTransform(true);
shipObject.setTicksSinceShipTeleport(0);
}
// Update the ship transform of the ship data.
ship.setPhysicsEnabled(false);
ship.setPrevTickShipTransform(newTransform);
ship.setShipTransform(newTransform);
System.out.println(String.format("Teleporting ship %s to %s", ship.getName(), position.toString()));
} catch (final Exception e) {
e.printStackTrace();
}
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysicsCalculations method generatePhysicsTransform.
public void generatePhysicsTransform() {
// Create a new physics transform.
ShipTransform parentTransform = getParent().getShipData().getShipTransform();
physRotation = parentTransform.getSubspaceToGlobal().getNormalizedRotation(new Quaterniond());
physX = parentTransform.getPosX();
physY = parentTransform.getPosY();
physZ = parentTransform.getPosZ();
physCenterOfMass = parentTransform.getCenterCoord();
ShipTransform physicsTransform = new ShipTransform(physX, physY, physZ, physRotation, physCenterOfMass);
getParent().getShipTransformationManager().setCurrentPhysicsTransform(physicsTransform);
// We're doing this afterwards to prevent from prevPhysicsTransform being null.
getParent().getShipTransformationManager().updatePreviousPhysicsTransform();
}
use of org.valkyrienskies.mod.common.ships.ship_transform.ShipTransform in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class ShipCollisionTask method checkPosition.
public void checkPosition(int x, int y, int z, int positionHash) {
if (!toTask.getParent().getChunkClaim().containsChunk(x >> 4, z >> 4)) {
return;
}
final Chunk chunkIn = toTask.getParent().getChunkAt(x >> 4, z >> 4);
y = Math.max(0, Math.min(y, 255));
ExtendedBlockStorage storage = chunkIn.storageArrays[y >> 4];
if (storage != null) {
ITerrainOctreeProvider provider = (ITerrainOctreeProvider) storage.data;
IBitOctree octree = provider.getSolidOctree();
if (octree.get(x & 15, y & 15, z & 15)) {
IBlockState inLocalState = chunkIn.getBlockState(x, y, z);
inLocalPos.setPos(x, y, z);
final ShipTransform shipTransform = toTask.getParent().getShipTransformationManager().getCurrentPhysicsTransform();
final Vector3dc shipBlockInGlobal = shipTransform.transformPositionNew(temp0.set(inLocalPos.getX() + .5, inLocalPos.getY() + .5, inLocalPos.getZ() + .5), TransformType.SUBSPACE_TO_GLOBAL);
final double distanceSq = shipBlockInGlobal.distanceSquared(mutablePos.getX() + .5, mutablePos.getY() + .5, mutablePos.getZ() + .5);
// If it is less than sqrt(3) then collision is possible.
if (distanceSq < 3) {
CollisionInformationHolder holder = new CollisionInformationHolder(mutablePos.getX(), mutablePos.getY(), mutablePos.getZ(), inLocalPos.getX(), inLocalPos.getY(), inLocalPos.getZ(), inWorldState, inLocalState);
collisionInformationGenerated.add(holder);
}
}
}
}
Aggregations