diff --git a/engine/src/main/java/org/terasology/logic/characters/CharacterMovementSystemUtility.java b/engine/src/main/java/org/terasology/logic/characters/CharacterMovementSystemUtility.java index 4398d7196c6..1054a558815 100644 --- a/engine/src/main/java/org/terasology/logic/characters/CharacterMovementSystemUtility.java +++ b/engine/src/main/java/org/terasology/logic/characters/CharacterMovementSystemUtility.java @@ -15,13 +15,12 @@ */ package org.terasology.logic.characters; +import org.joml.Quaternionf; +import org.joml.Vector3f; import org.terasology.entitySystem.entity.EntityRef; import org.terasology.logic.location.LocationComponent; +import org.terasology.math.JomlUtil; import org.terasology.math.TeraMath; -import org.terasology.math.geom.BaseQuat4f; -import org.terasology.math.geom.BaseVector3f; -import org.terasology.math.geom.Quat4f; -import org.terasology.math.geom.Vector3f; import org.terasology.physics.engine.CharacterCollider; import org.terasology.physics.engine.PhysicsEngine; @@ -63,27 +62,27 @@ public void setToState(EntityRef entity, CharacterStateEvent state) { movementComp.footstepDelta = state.getFootstepDelta(); entity.saveComponent(movementComp); - setPhysicsLocation(entity, state.getPosition()); + setPhysicsLocation(entity, JomlUtil.from(state.getPosition())); // set the pitch to the character's gaze entity - Quat4f rotation = new Quat4f(0f, TeraMath.DEG_TO_RAD * state.getPitch(), 0f); + Quaternionf rotation = new Quaternionf().rotationX(TeraMath.DEG_TO_RAD * state.getPitch()); EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(entity); if (!gazeEntity.equals(entity)) { // Only set the gaze entity rotation if it is not the same as the main entity. // The character is assumed to only rotate side to side, introducing pitch makes things act strangely LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class); - gazeLocation.setLocalRotation(rotation); + gazeLocation.setLocalRotation(JomlUtil.from(rotation)); gazeEntity.saveComponent(gazeLocation); } } public void setToInterpolateState(EntityRef entity, CharacterStateEvent a, CharacterStateEvent b, long time) { float t = (float) (time - a.getTime()) / (b.getTime() - a.getTime()); - Vector3f newPos = BaseVector3f.lerp(a.getPosition(), b.getPosition(), t); - Quat4f newRot = BaseQuat4f.interpolate(a.getRotation(), b.getRotation(), t); + Vector3f newPos = JomlUtil.from(a.getPosition()).lerp(JomlUtil.from(b.getPosition()),t); + Quaternionf newRot = JomlUtil.from(a.getRotation()).nlerp(JomlUtil.from(b.getRotation()),t); LocationComponent location = entity.getComponent(LocationComponent.class); - location.setWorldPosition(newPos); - location.setWorldRotation(newRot); + location.setWorldPosition(JomlUtil.from(newPos)); + location.setWorldRotation(JomlUtil.from(newRot)); entity.saveComponent(location); CharacterMovementComponent movementComponent = entity.getComponent(CharacterMovementComponent.class); @@ -105,9 +104,9 @@ public void setToInterpolateState(EntityRef entity, CharacterStateEvent a, Chara public void setToExtrapolateState(EntityRef entity, CharacterStateEvent state, long time) { float t = (time - state.getTime()) * 0.0001f; - Vector3f newPos = new Vector3f(state.getVelocity()); - newPos.scale(t); - newPos.add(state.getPosition()); + Vector3f newPos = new Vector3f(JomlUtil.from(state.getVelocity())); + newPos.mul(t); + newPos.add(JomlUtil.from(state.getPosition())); extrapolateLocationComponent(entity, state, newPos); extrapolateCharacterMovementComponent(entity, state); @@ -117,7 +116,7 @@ public void setToExtrapolateState(EntityRef entity, CharacterStateEvent state, l private void extrapolateLocationComponent(EntityRef entity, CharacterStateEvent state, Vector3f newPos) { LocationComponent location = entity.getComponent(LocationComponent.class); - location.setWorldPosition(newPos); + location.setWorldPosition(JomlUtil.from(newPos)); location.setWorldRotation(state.getRotation()); entity.saveComponent(location); } @@ -138,6 +137,6 @@ private void extrapolateCharacterMovementComponent(EntityRef entity, CharacterSt */ private void setPhysicsLocation(EntityRef entity, Vector3f newPos) { CharacterCollider collider = physics.getCharacterCollider(entity); - collider.setLocation(newPos); + collider.setLocation(JomlUtil.from(newPos)); } } diff --git a/engine/src/main/java/org/terasology/logic/characters/KinematicCharacterMover.java b/engine/src/main/java/org/terasology/logic/characters/KinematicCharacterMover.java index a9a7355447b..c865d68f115 100644 --- a/engine/src/main/java/org/terasology/logic/characters/KinematicCharacterMover.java +++ b/engine/src/main/java/org/terasology/logic/characters/KinematicCharacterMover.java @@ -15,6 +15,9 @@ */ package org.terasology.logic.characters; +import org.joml.Quaternionf; +import org.joml.Vector3f; +import org.joml.Vector3i; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.terasology.entitySystem.entity.EntityRef; @@ -25,12 +28,10 @@ import org.terasology.logic.characters.events.SwimStrokeEvent; import org.terasology.logic.characters.events.VerticalCollisionEvent; import org.terasology.logic.location.LocationComponent; +import org.terasology.math.JomlUtil; import org.terasology.math.TeraMath; -import org.terasology.math.Vector3fUtil; import org.terasology.math.geom.ImmutableVector3f; import org.terasology.math.geom.Quat4f; -import org.terasology.math.geom.Vector3f; -import org.terasology.math.geom.Vector3i; import org.terasology.physics.engine.CharacterCollider; import org.terasology.physics.engine.PhysicsEngine; import org.terasology.physics.engine.SweepCallback; @@ -107,8 +108,8 @@ public CharacterStateEvent step(CharacterStateEvent initial, CharacterMoveInputE // The CharacterMovementComponent also has a 'radius' which may be used here. // Question: Is this connected with _shapes_ or bounding boxes in some way? checkBlockEntry(entity, - new Vector3i(initial.getPosition(), RoundingMode.HALF_UP), - new Vector3i(result.getPosition(), RoundingMode.HALF_UP), + new Vector3i(JomlUtil.from(initial.getPosition()), org.joml.RoundingMode.HALF_UP), + new Vector3i(JomlUtil.from(result.getPosition()), org.joml.RoundingMode.HALF_UP), characterMovementComponent.height); } if (result.getMode() != MovementMode.GHOSTING && result.getMode() != MovementMode.NONE) { @@ -156,7 +157,7 @@ private void checkBlockEntry(EntityRef entity, Vector3i oldPosition, Vector3i ne for (int y = 0; y < characterHeightInBlocks; y++) { // send a block enter/leave event for this character - entity.send(new OnEnterBlockEvent(oldBlocks[y], newBlocks[y], new Vector3i(0, y, 0))); + entity.send(new OnEnterBlockEvent(oldBlocks[y], newBlocks[y], JomlUtil.from(new Vector3i(0, y, 0)))); } } } @@ -176,14 +177,14 @@ private void checkMode(final CharacterMovementComponent movementComp, final Char if (!state.getMode().respondToEnvironment) { return; } - Vector3f worldPos = state.getPosition(); + Vector3f worldPos = JomlUtil.from(state.getPosition()); Vector3f top = new Vector3f(worldPos); Vector3f bottom = new Vector3f(worldPos); top.y += 0.5f * movementComp.height; bottom.y -= 0.5f * movementComp.height; - final boolean topUnderwater = worldProvider.getBlock(top).isLiquid(); - final boolean bottomUnderwater = worldProvider.getBlock(bottom).isLiquid(); + final boolean topUnderwater = worldProvider.getBlock(JomlUtil.from(top)).isLiquid(); + final boolean bottomUnderwater = worldProvider.getBlock(JomlUtil.from(bottom)).isLiquid(); final boolean newSwimming = !topUnderwater && bottomUnderwater; final boolean newDiving = topUnderwater && bottomUnderwater; @@ -194,7 +195,7 @@ private void checkMode(final CharacterMovementComponent movementComp, final Char finalDir = findClimbable(movementComp, worldPos, newSwimming, newDiving); if (finalDir != null) { newClimbing = true; - state.setClimbDirection(finalDir); + state.setClimbDirection(JomlUtil.from(finalDir)); } } @@ -253,12 +254,12 @@ private Vector3i findClimbable(CharacterMovementComponent movementComp, Vector3f float distance = 100f; for (Vector3f side : sides) { - Block block = worldProvider.getBlock(side); + Block block = worldProvider.getBlock(JomlUtil.from(side)); if (block.isClimbable()) { //If any of our sides are near a climbable block, check if we are near to the side - Vector3i myPos = new Vector3i(worldPos, RoundingMode.HALF_UP); - Vector3i climbBlockPos = new Vector3i(side, RoundingMode.HALF_UP); - Vector3i dir = new Vector3i(block.getDirection().getVector3i()); + Vector3i myPos = new Vector3i(worldPos, org.joml.RoundingMode.HALF_UP); + Vector3i climbBlockPos = new Vector3i(side, org.joml.RoundingMode.HALF_UP); + Vector3i dir = new Vector3i(JomlUtil.from(block.getDirection().getVector3i())); float currentDistance = 10f; if (dir.x != 0 && Math.abs(worldPos.x - climbBlockPos.x + dir.x * .5f) < movementComp.radius + 0.1f) { @@ -305,7 +306,7 @@ private boolean checkStep(CharacterCollider collider, Vector3f position, Vector3 if (!stepped) { stepped = true; - boolean moveUpStep = callback.checkForStep(direction, stepHeight, slopeFactor, CHECK_FORWARD_DIST); + boolean moveUpStep = callback.checkForStep(JomlUtil.from(direction), stepHeight, slopeFactor, CHECK_FORWARD_DIST); if (moveUpStep) { steppedUpDist = moveUp(stepHeight, collider, position); @@ -323,12 +324,13 @@ private Vector3f extractResidualMovement(Vector3f hitNormal, Vector3f direction, float movementLength = direction.length(); if (movementLength > physics.getEpsilon()) { direction.normalize(); - Vector3f reflectDir = Vector3fUtil.reflect(direction, hitNormal, new Vector3f()); + Vector3f reflectDir = direction.reflect(hitNormal,new Vector3f()); reflectDir.normalize(); - Vector3f perpendicularDir = Vector3fUtil.getPerpendicularComponent(reflectDir, hitNormal, new Vector3f()); + + Vector3f perpendicularDir = hitNormal.mul(reflectDir.dot(hitNormal),new Vector3f()).mul(-1).add(reflectDir); if (normalMag != 0.0f) { Vector3f perpComponent = new Vector3f(perpendicularDir); - perpComponent.scale(normalMag * movementLength); + perpComponent.mul(normalMag * movementLength); direction.set(perpComponent); } } @@ -338,9 +340,9 @@ private Vector3f extractResidualMovement(Vector3f hitNormal, Vector3f direction, private void followToParent(final CharacterStateEvent state, EntityRef entity) { LocationComponent locationComponent = entity.getComponent(LocationComponent.class); if (!locationComponent.getParent().equals(EntityRef.NULL)) { - Vector3f velocity = new Vector3f(locationComponent.getWorldPosition()); - velocity.sub(state.getPosition()); - state.getVelocity().set(velocity); + Vector3f velocity = new Vector3f(JomlUtil.from(locationComponent.getWorldPosition())); + velocity.sub(JomlUtil.from(state.getPosition())); + state.getVelocity().set(JomlUtil.from(velocity)); state.getPosition().set(locationComponent.getWorldPosition()); } } @@ -388,14 +390,14 @@ private boolean moveDown(float dist, float slopeFactor, CharacterCollider collid boolean hit = false; int iteration = 0; while (remainingDist > physics.getEpsilon() && iteration++ < 10) { - SweepCallback callback = collider.sweep(position, targetPos, VERTICAL_PENETRATION, -1.0f); + SweepCallback callback = collider.sweep(JomlUtil.from(position), JomlUtil.from(targetPos), VERTICAL_PENETRATION, -1.0f); float actualDist = Math.max(0, (remainingDist + VERTICAL_PENETRATION_LEEWAY) * callback.getClosestHitFraction() - VERTICAL_PENETRATION_LEEWAY); Vector3f expectedMove = new Vector3f(targetPos); expectedMove.sub(position); if (expectedMove.lengthSquared() > physics.getEpsilon()) { expectedMove.normalize(); - expectedMove.scale(actualDist); + expectedMove.mul(actualDist); position.add(expectedMove); } remainingDist -= actualDist; @@ -403,14 +405,14 @@ private boolean moveDown(float dist, float slopeFactor, CharacterCollider collid break; } if (callback.hasHit()) { - float originalSlope = callback.getHitNormalWorld().dot(new Vector3f(0, 1, 0)); + float originalSlope = callback.getHitNormalWorld().dot(JomlUtil.from(new Vector3f(0, 1, 0))); if (originalSlope < slopeFactor) { float slope = callback.calculateAverageSlope(originalSlope, CHECK_FORWARD_DIST); if (slope < slopeFactor) { remainingDist -= actualDist; expectedMove.set(targetPos); expectedMove.sub(position); - extractResidualMovement(callback.getHitNormalWorld(), expectedMove); + extractResidualMovement(JomlUtil.from(callback.getHitNormalWorld()), expectedMove); float sqrDist = expectedMove.lengthSquared(); if (sqrDist > physics.getEpsilon()) { expectedMove.normalize(); @@ -427,7 +429,7 @@ private boolean moveDown(float dist, float slopeFactor, CharacterCollider collid break; } normalizedDir.set(expectedMove); - expectedMove.scale(-remainingDist / expectedMove.y + HORIZONTAL_PENETRATION_LEEWAY); + expectedMove.mul(-remainingDist / expectedMove.y + HORIZONTAL_PENETRATION_LEEWAY); targetPos.set(position); targetPos.add(expectedMove); } else { @@ -456,22 +458,24 @@ private boolean moveHorizontal(Vector3f horizMove, CharacterCollider collider, V return false; } boolean horizontalHit = false; - Vector3f normalizedDir = Vector3fUtil.safeNormalize(horizMove, new Vector3f()); + Vector3f normalizedDir = horizMove.normalize(); + if(!normalizedDir.isFinite()) + normalizedDir.set(0); if (collider == null) { // ignore collision - normalizedDir.scale(dist); + normalizedDir.mul(dist); position.add(normalizedDir); return false; } Vector3f targetPos = new Vector3f(normalizedDir); - targetPos.scale(dist + HORIZONTAL_PENETRATION_LEEWAY); + targetPos.mul(dist + HORIZONTAL_PENETRATION_LEEWAY); targetPos.add(position); int iteration = 0; Vector3f lastHitNormal = new Vector3f(0, 1, 0); while (remainingFraction >= 0.01f && iteration++ < 10) { - SweepCallback callback = collider.sweep(position, targetPos, HORIZONTAL_PENETRATION, slopeFactor); + SweepCallback callback = collider.sweep(JomlUtil.from(position), JomlUtil.from(targetPos), HORIZONTAL_PENETRATION, slopeFactor); /* Note: this isn't quite correct (after the first iteration the closestHitFraction is only for part of the moment) but probably close enough */ @@ -483,13 +487,13 @@ private boolean moveHorizontal(Vector3f horizMove, CharacterCollider collider, V if (callback.hasHit()) { if (actualDist > physics.getEpsilon()) { Vector3f actualMove = new Vector3f(normalizedDir); - actualMove.scale(actualDist); + actualMove.mul(actualDist); position.add(actualMove); } dist -= actualDist; Vector3f newDir = new Vector3f(normalizedDir); - newDir.scale(dist); - float slope = callback.getHitNormalWorld().dot(new Vector3f(0, 1, 0)); + newDir.mul(dist); + float slope = callback.getHitNormalWorld().dot(JomlUtil.from(new Vector3f(0, 1, 0))); // We step up if we're hitting a big slope, or if we're grazing // the ground, otherwise we move up a shallow slope. @@ -513,10 +517,10 @@ private boolean moveHorizontal(Vector3f horizMove, CharacterCollider collider, V } else { // Hitting a shallow slope, move up it Vector3f newHorizDir = new Vector3f(newDir.x, 0, newDir.z); - extractResidualMovement(callback.getHitNormalWorld(), newDir); + extractResidualMovement(JomlUtil.from(callback.getHitNormalWorld()), newDir); Vector3f modHorizDir = new Vector3f(newDir); modHorizDir.y = 0; - newDir.scale(newHorizDir.length() / modHorizDir.length()); + newDir.mul(newHorizDir.length() / modHorizDir.length()); } float sqrDist = newDir.lengthSquared(); if (sqrDist > physics.getEpsilon()) { @@ -530,10 +534,10 @@ private boolean moveHorizontal(Vector3f horizMove, CharacterCollider collider, V dist = (float) Math.sqrt(sqrDist); normalizedDir.set(newDir); targetPos.set(normalizedDir); - targetPos.scale(dist + HORIZONTAL_PENETRATION_LEEWAY); + targetPos.mul(dist + HORIZONTAL_PENETRATION_LEEWAY); targetPos.add(position); } else { - normalizedDir.scale(dist); + normalizedDir.mul(dist); position.add(normalizedDir); break; } @@ -544,7 +548,7 @@ private boolean moveHorizontal(Vector3f horizMove, CharacterCollider collider, V private float moveUp(float riseAmount, CharacterCollider collider, Vector3f position) { Vector3f to = new Vector3f(position.x, position.y + riseAmount + VERTICAL_PENETRATION_LEEWAY, position.z); if (collider != null) { - SweepCallback callback = collider.sweep(position, to, VERTICAL_PENETRATION_LEEWAY, -1f); + SweepCallback callback = collider.sweep(JomlUtil.from(position), JomlUtil.from(to), VERTICAL_PENETRATION_LEEWAY, -1f); if (callback.hasHit()) { float actualDist = Math.max(0, ((riseAmount + VERTICAL_PENETRATION_LEEWAY) * callback.getClosestHitFraction()) - VERTICAL_PENETRATION_LEEWAY); @@ -573,7 +577,7 @@ private void updateRotation(CharacterMovementComponent movementComp, CharacterSt CharacterMoveInputEvent input) { if (movementComp.faceMovementDirection && result.getVelocity().lengthSquared() > 0.01f) { float yaw = (float) Math.atan2(result.getVelocity().x, result.getVelocity().z); - result.getRotation().set(new Vector3f(0, 1, 0), yaw); + result.getRotation().set(JomlUtil.from(new Vector3f(0, 1, 0)), yaw); } else { result.getRotation().set(new Quat4f(TeraMath.DEG_TO_RAD * input.getYaw(), 0, 0)); } @@ -581,7 +585,7 @@ private void updateRotation(CharacterMovementComponent movementComp, CharacterSt private void walk(final CharacterMovementComponent movementComp, final CharacterStateEvent state, CharacterMoveInputEvent input, EntityRef entity) { - Vector3f desiredVelocity = new Vector3f(input.getMovementDirection()); + Vector3f desiredVelocity = new Vector3f(JomlUtil.from(input.getMovementDirection())); float lengthSquared = desiredVelocity.lengthSquared(); @@ -590,7 +594,7 @@ private void walk(final CharacterMovementComponent movementComp, final Character if (lengthSquared > 1) { desiredVelocity.normalize(); } - desiredVelocity.scale(movementComp.speedMultiplier); + desiredVelocity.mul(movementComp.speedMultiplier); float maxSpeed = getMaxSpeed(entity, movementComp); if (input.isRunning()) { @@ -603,10 +607,10 @@ private void walk(final CharacterMovementComponent movementComp, final Character desiredVelocity.y = 0; if (desiredVelocity.x != 0 || desiredVelocity.z != 0) { desiredVelocity.normalize(); - desiredVelocity.scale(speed); + desiredVelocity.mul(speed); } } - desiredVelocity.scale(maxSpeed); + desiredVelocity.mul(maxSpeed); if (movementComp.mode == MovementMode.CLIMBING) { climb(state, input, desiredVelocity); @@ -619,9 +623,9 @@ private void walk(final CharacterMovementComponent movementComp, final Character // Modify velocity towards desired, up to the maximum rate determined by friction Vector3f velocityDiff = new Vector3f(desiredVelocity); - velocityDiff.sub(state.getVelocity()); - velocityDiff.scale(Math.min(movementComp.mode.scaleInertia * input.getDelta(), 1.0f)); - Vector3f endVelocity = new Vector3f(state.getVelocity()); + velocityDiff.sub(JomlUtil.from(state.getVelocity())); + velocityDiff.mul(Math.min(movementComp.mode.scaleInertia * input.getDelta(), 1.0f)); + Vector3f endVelocity = new Vector3f(JomlUtil.from(state.getVelocity())); endVelocity.x += velocityDiff.x; endVelocity.z += velocityDiff.z; if (movementComp.mode.scaleGravity == 0) { @@ -633,16 +637,16 @@ private void walk(final CharacterMovementComponent movementComp, final Character endVelocity.y = Math.max(-TERMINAL_VELOCITY, state.getVelocity().y - (GRAVITY * movementComp.mode.scaleGravity) * input.getDelta()); } Vector3f moveDelta = new Vector3f(endVelocity); - moveDelta.scale(input.getDelta()); + moveDelta.mul(input.getDelta()); CharacterCollider collider = movementComp.mode.useCollision ? physics.getCharacterCollider(entity) : null; - MoveResult moveResult = move(state.getPosition(), moveDelta, + MoveResult moveResult = move(JomlUtil.from(state.getPosition()), moveDelta, (state.getMode() != MovementMode.CLIMBING && state.isGrounded() && movementComp.mode.canBeGrounded) ? movementComp.stepHeight : 0, movementComp.slopeFactor, collider); Vector3f distanceMoved = new Vector3f(moveResult.getFinalPosition()); - distanceMoved.sub(state.getPosition()); - state.getPosition().set(moveResult.getFinalPosition()); + distanceMoved.sub(JomlUtil.from(state.getPosition())); + state.getPosition().set(JomlUtil.from(moveResult.getFinalPosition())); if (input.isFirstRun() && distanceMoved.length() > 0) { - entity.send(new MovedEvent(new ImmutableVector3f(distanceMoved), new ImmutableVector3f(state.getPosition()))); + entity.send(new MovedEvent(new ImmutableVector3f(JomlUtil.from(distanceMoved)), new ImmutableVector3f(state.getPosition()))); } // Upon hitting solid ground, reset the number of jumps back to the maximum value. @@ -653,10 +657,10 @@ private void walk(final CharacterMovementComponent movementComp, final Character if (moveResult.isBottomHit()) { if (!state.isGrounded() && movementComp.mode.canBeGrounded) { if (input.isFirstRun()) { - Vector3f landVelocity = new Vector3f(state.getVelocity()); + Vector3f landVelocity = new Vector3f(JomlUtil.from(state.getVelocity())); landVelocity.y += (distanceMoved.y / moveDelta.y) * (endVelocity.y - state.getVelocity().y); logger.debug("Landed at " + landVelocity); - entity.send(new VerticalCollisionEvent(state.getPosition(), landVelocity)); + entity.send(new VerticalCollisionEvent(state.getPosition(), JomlUtil.from(landVelocity))); } state.setGrounded(true); movementComp.numberOfJumpsLeft = movementComp.numberOfJumpsMax; @@ -686,10 +690,10 @@ private void walk(final CharacterMovementComponent movementComp, final Character } else { if (moveResult.isTopHit() && endVelocity.y > 0) { if (input.isFirstRun()) { - Vector3f hitVelocity = new Vector3f(state.getVelocity()); + Vector3f hitVelocity = new Vector3f(JomlUtil.from(state.getVelocity())); hitVelocity.y += (distanceMoved.y / moveDelta.y) * (endVelocity.y - state.getVelocity().y); logger.debug("Hit at " + hitVelocity); - entity.send(new VerticalCollisionEvent(state.getPosition(), hitVelocity)); + entity.send(new VerticalCollisionEvent(state.getPosition(), JomlUtil.from(hitVelocity))); } endVelocity.y = -0.0f * endVelocity.y; } @@ -720,13 +724,13 @@ private void walk(final CharacterMovementComponent movementComp, final Character } } if (input.isFirstRun() && moveResult.isHorizontalHit()) { - Vector3f hitVelocity = new Vector3f(state.getVelocity()); + Vector3f hitVelocity = new Vector3f(JomlUtil.from(state.getVelocity())); hitVelocity.x += (distanceMoved.x / moveDelta.x) * (endVelocity.x - state.getVelocity().x); hitVelocity.z += (distanceMoved.z / moveDelta.z) * (endVelocity.z - state.getVelocity().z); logger.debug("Hit at " + hitVelocity); - entity.send(new HorizontalCollisionEvent(state.getPosition(), hitVelocity)); + entity.send(new HorizontalCollisionEvent(state.getPosition(), JomlUtil.from(hitVelocity))); } - state.getVelocity().set(endVelocity); + state.getVelocity().set(JomlUtil.from(endVelocity)); if (state.isGrounded() || movementComp.mode == MovementMode.SWIMMING || movementComp.mode == MovementMode.DIVING) { state.setFootstepDelta( state.getFootstepDelta() + distanceMoved.length() / movementComp.distanceBetweenFootsteps); @@ -759,12 +763,12 @@ private void climb(final CharacterStateEvent state, CharacterMoveInputEvent inpu } Vector3f tmp; - Vector3i climbDir3i = state.getClimbDirection(); - Vector3f climbDir3f = climbDir3i.toVector3f(); + Vector3i climbDir3i = JomlUtil.from(state.getClimbDirection()); + Vector3f climbDir3f = new Vector3f(climbDir3i); - Quat4f rotation = new Quat4f(TeraMath.DEG_TO_RAD * state.getYaw(), 0, 0); + Quaternionf rotation = new Quaternionf().rotationYXZ(TeraMath.DEG_TO_RAD * state.getYaw(), 0, 0); tmp = new Vector3f(0.0f, 0.0f, -1.0f); - rotation.rotate(tmp, tmp); + tmp.rotate(rotation); float angleToClimbDirection = tmp.angle(climbDir3f); boolean clearMovementToDirection = !state.isGrounded(); @@ -779,30 +783,28 @@ private void climb(final CharacterStateEvent state, CharacterMoveInputEvent inpu } else { float pitchAmount = state.isGrounded() ? 45f : 90f; float pitch = input.getPitch() > 30f ? pitchAmount : -pitchAmount; - rotation = new Quat4f(TeraMath.DEG_TO_RAD * state.getYaw(), TeraMath.DEG_TO_RAD * pitch, 0); - rotation.rotate(desiredVelocity, desiredVelocity); + rotation.rotationYXZ(TeraMath.DEG_TO_RAD * state.getYaw(), TeraMath.DEG_TO_RAD * pitch, 0); + desiredVelocity.rotate(rotation); } // looking sidewards from ladder } else if (angleToClimbDirection < Math.PI * 3.0 / 4.0) { float rollAmount = state.isGrounded() ? 45f : 90f; tmp = new Vector3f(); - rotation.rotate(climbDir3f, tmp); + climbDir3f.rotate(rotation,tmp); float leftOrRight = tmp.x; float plusOrMinus = (leftOrRight < 0f ? -1.0f : 1.0f) * (climbDir3i.x != 0 ? -1.0f : 1.0f); if (jumpOrCrouchActive) { - rotation = new Quat4f(TeraMath.DEG_TO_RAD * state.getYaw(), 0, 0); + rotation.rotationY(TeraMath.DEG_TO_RAD * state.getYaw()); } else { - rotation = new Quat4f(TeraMath.DEG_TO_RAD * input.getYaw(), 0f, - TeraMath.DEG_TO_RAD * rollAmount * plusOrMinus - ); + rotation.rotationYXZ(TeraMath.DEG_TO_RAD * input.getYaw(), 0f, + TeraMath.DEG_TO_RAD * rollAmount * plusOrMinus); } - rotation.rotate(desiredVelocity, desiredVelocity); - + desiredVelocity.rotate(rotation); // facing away from ladder } else { - rotation = new Quat4f(TeraMath.DEG_TO_RAD * state.getYaw(), 0, 0); - rotation.rotate(desiredVelocity, desiredVelocity); + rotation.rotationYXZ(TeraMath.DEG_TO_RAD * state.getYaw(), 0, 0); + desiredVelocity.rotate(rotation); clearMovementToDirection = false; }