Major collision refactor to correct AABB system
This commit is contained in:
35
World.cs
35
World.cs
@@ -1,6 +1,4 @@
|
||||
using OpenTK.Mathematics;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
|
||||
namespace Voxel
|
||||
{
|
||||
@@ -62,22 +60,17 @@ namespace Voxel
|
||||
int centerX = (int)Math.Floor(playerPosition.X / Chunk.Size);
|
||||
int centerZ = (int)Math.Floor(playerPosition.Z / Chunk.Size);
|
||||
|
||||
// Quick check - skip if still in same chunk
|
||||
if ((centerX == _lastCenter.x && centerZ == _lastCenter.z) && chunkLoadingInitialized)
|
||||
return;
|
||||
|
||||
_lastCenter = (centerX, centerZ);
|
||||
|
||||
// Calculate bounds
|
||||
int minX = centerX - _loadDistance;
|
||||
int maxX = centerX + _loadDistance;
|
||||
int minZ = centerZ - _loadDistance;
|
||||
int maxZ = centerZ + _loadDistance;
|
||||
|
||||
// Unload chunks outside range
|
||||
UnloadDistantChunks(minX, maxX, minZ, maxZ);
|
||||
|
||||
// Load chunks inside range
|
||||
LoadChunksInRange(minX, maxX, minZ, maxZ);
|
||||
|
||||
chunkLoadingInitialized = true;
|
||||
@@ -347,9 +340,35 @@ namespace Voxel
|
||||
return (false, Blocks.Air, 0, 0, 0, Vector3i.Zero);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
public List<AABB> GetColliders(AABB body)
|
||||
{
|
||||
List<AABB> collisions = new List<AABB>();
|
||||
|
||||
int minX = (int)Math.Floor(body.Min.X);
|
||||
int maxX = (int)Math.Ceiling(body.Max.X) - 1;
|
||||
int minY = (int)Math.Floor(body.Min.Y);
|
||||
int maxY = (int)Math.Ceiling(body.Max.Y) - 1;
|
||||
int minZ = (int)Math.Floor(body.Min.Z);
|
||||
int maxZ = (int)Math.Ceiling(body.Max.Z) - 1;
|
||||
|
||||
for (int x = minX; x <= maxX; x++)
|
||||
{
|
||||
for (int y = minY; y <= maxY; y++)
|
||||
{
|
||||
for (int z = minZ; z <= maxZ; z++)
|
||||
{
|
||||
if (GetBlock(x, y, z) != Blocks.Air)
|
||||
{
|
||||
collisions.Add(new AABB(
|
||||
new Vector3(x, y, z),
|
||||
new Vector3(x + 1, y + 1, z + 1)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return collisions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user