Improved gravity slightly.

This commit is contained in:
Andrew Lalis 2022-07-29 00:24:43 +02:00
parent 492b9f66aa
commit 4f172ccb98
3 changed files with 25 additions and 6 deletions

View File

@ -52,6 +52,14 @@ public class Camera {
velocity.set(p.getVelocity());
}
public void setToPlayerScopeView(Player p) {
Vector3f pos = new Vector3f();
Matrix4f tx = p.getHeldItemTransform();
tx.transformPosition(pos);
position.set(pos);
velocity.set(p.getVelocity());
}
public void setOrientationToPlayer(Player p) {
orientation.set(p.getOrientation());
}

View File

@ -137,7 +137,7 @@ public class GameRenderer {
throw new RuntimeException(e);
}
log.debug("Initialized model renderer.");
updatePerspective();
updatePerspective(config.fov);
}
public float getAspectRatio() {
@ -147,8 +147,8 @@ public class GameRenderer {
/**
* Updates the rendering perspective used to render the game.
*/
private void updatePerspective() {
float fovRad = (float) Math.toRadians(config.fov);
public void updatePerspective(float fov) {
float fovRad = (float) Math.toRadians(fov);
if (fovRad >= Math.PI) {
fovRad = (float) (Math.PI - 0.01f);
} else if (fovRad <= 0) {

View File

@ -1,10 +1,9 @@
package nl.andrewl.aos_core.model;
import nl.andrewl.aos_core.Directions;
import nl.andrewl.aos_core.MathUtils;
import org.joml.*;
import org.joml.Math;
import org.joml.Vector2f;
import org.joml.Vector3f;
import org.joml.Vector3i;
import java.util.ArrayList;
import java.util.List;
@ -168,6 +167,18 @@ public class Player {
return crouching ? HEIGHT_CROUCH : HEIGHT;
}
/**
* Gets a transformation that transforms a position to the position of the
* player's held gun.
* @return The gun transform.
*/
public Matrix4f getHeldItemTransform() {
return new Matrix4f()
.translate(position)
.rotate(orientation.x + (float) Math.PI, Directions.UPf)
.translate(-0.35f, getEyeHeight() - 0.4f, 0.35f);
}
public List<Vector3i> getBlockSpaceOccupied() {
float playerBodyMinZ = position.z - RADIUS;
float playerBodyMaxZ = position.z + RADIUS;