Skip to content

Commit

Permalink
Fix some FOV-related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
GlennFolker committed Dec 14, 2024
1 parent 3a88d08 commit eaadd56
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/confictura/graphics/RenderContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import static mindustry.Vars.*;

public class RenderContext{
public Camera3D camera = new Camera3D(){{
fov = 60f;
public float fovX = 60f;
public Camera3D cam = new Camera3D(){{
near = 1f;

up.set(0f, 0f, -1f);
Expand All @@ -21,12 +21,13 @@ public class RenderContext{

public RenderContext(){
Events.run(Trigger.draw, () -> {
int sw = graphics.getWidth(), sh = graphics.getHeight();
cam.resize(camera.width, camera.height);

camera.resize(sw, sh);
camera.position.set(Core.camera.position.x, Core.camera.height / 2f / Mathf.tan(camera.fov / 2f * Mathf.degRad, 1f, 1f), -Core.camera.position.y);
camera.far = Math.max(150f, camera.position.y * 1.5f);
camera.update();
double y = cam.width / 2d / Math.tan(fovX / 2d * Mathf.doubleDegRad);
cam.position.set(camera.position.x, (float)y, -camera.position.y);
cam.fov = (float)(2d * Math.atan2(cam.height, 2d * y) * Mathf.doubleRadDeg);
cam.far = Math.max(150f, cam.position.y * 1.5f);
cam.update();
});

Events.on(WorldLoadEvent.class, e -> {
Expand Down
3 changes: 1 addition & 2 deletions src/confictura/graphics/g3d/ModelPropDrawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public class ModelPropDrawer implements Disposable{
private static final Vec3 pos = new Vec3(), scl = new Vec3(), vec = new Vec3();
private static final Quat quat = new Quat();
private static final Mat3D nor = new Mat3D();
private static final Color col = new Color();

protected ObjectMap<Mesh, PropData> data = new ObjectMap<>();
protected FrameBuffer buffer = new FrameBuffer(2, 2, true);
Expand Down Expand Up @@ -145,7 +144,7 @@ protected void flush(){
if(indexOffset == 0) return;

shader.bind();
shader.camera = renderContext.camera;
shader.camera = renderContext.cam;
shader.lightDir.set(-1.2f, -0.8f, 0.9f).nor();
shader.reflectColor.set(!state.rules.lighting ? Color.white : state.rules.ambientLight);
shader.apply();
Expand Down

0 comments on commit eaadd56

Please sign in to comment.