Files
VoxelEngine/Rendering/Camera.cs
MDietermann e034d10339 feat(world-gen): larger biomes, smooth height blending, capped mountains; centralize tunables in Configuration
Terrain feel: biome regions ~10x larger (Voronoi cell size 96->960); terrain height now eases across biome borders via a Voronoi distance blend (smooth, and ~25x cheaper than the old 169-sample box blur); mountains capped to ~2/3 world height and gentled (ridged amplitude/frequency lowered), snow line lowered to match.

Centralization: ~27 world-gen/render tuning constants (biome amplitudes & frequencies, climate-noise frequencies/octaves, biome-selection thresholds, blend width, cell size, filler depth, snow line, camera near plane, spawn offset, overlay scale) hoisted from scattered literals into a region-organized, fully-commented Configuration. Configuration is threaded into NoiseSource, the biomes, BiomeRegistry, BiomeMap (+Classify), TerrainSampler, WorldGenerator (+BlockAt filler depth), and Camera via Player. Defaults equal the prior values, so generation is unchanged; worldgen tests updated for the new constructor signatures.
2026-06-03 16:27:06 +02:00

57 lines
2.0 KiB
C#

using OpenTK.Mathematics;
namespace VoxelEngine.Rendering;
public sealed class Camera
{
private static readonly Vector3 WorldUp = Vector3.UnitY;
public Vector3 Position { get; private set; }
public float Yaw { get; private set; } = -90f; // degrees; -90 looks down -Z
public float Pitch { get; private set; } // degrees
public float Fov { get; set; } = 60f; // degrees
public float NearPlane { get; set; } = 0.1f; // world units
public float FarPlane { get; set; } = 100f; // world units
public float AspectRatio { get; set; }
public Vector3 Front { get; private set; } = -Vector3.UnitZ;
public Vector3 Right { get; private set; } = Vector3.UnitX;
public Vector3 Up { get; private set; } = Vector3.UnitY;
public Camera(Vector3 position, float aspectRatio)
{
this.Position = position;
this.AspectRatio = aspectRatio;
this.UpdateVectors();
}
public void Move(Vector3 delta) => this.Position += delta;
public void AddRotation(float yawDelta, float pitchDelta)
{
this.Yaw += yawDelta;
this.Pitch = MathHelper.Clamp(this.Pitch + pitchDelta, -89f, 89f);
this.UpdateVectors();
}
public Matrix4 GetViewMatrix() => Matrix4.LookAt(this.Position, this.Position + this.Front, this.Up);
public Matrix4 GetProjectionMatrix() =>
Matrix4.CreatePerspectiveFieldOfView(
MathHelper.DegreesToRadians(this.Fov), this.AspectRatio, this.NearPlane, this.FarPlane);
private void UpdateVectors()
{
float yaw = MathHelper.DegreesToRadians(this.Yaw);
float pitch = MathHelper.DegreesToRadians(this.Pitch);
this.Front = Vector3.Normalize(new Vector3(
MathF.Cos(yaw) * MathF.Cos(pitch),
MathF.Sin(pitch),
MathF.Sin(yaw) * MathF.Cos(pitch)));
this.Right = Vector3.Normalize(Vector3.Cross(this.Front, WorldUp));
this.Up = Vector3.Normalize(Vector3.Cross(this.Right, this.Front));
}
}