From 5e0c284f3a8debdd9ebb080f80e36dceb7bc4ce2 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 1 Dec 2010 15:20:12 +0200 Subject: some work-in-progress water stuff --- src/voxel.h | 119 +++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 86 insertions(+), 33 deletions(-) (limited to 'src/voxel.h') diff --git a/src/voxel.h b/src/voxel.h index 2bc591d2a..3a4dacd49 100644 --- a/src/voxel.h +++ b/src/voxel.h @@ -25,7 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include /* - TODO: A fast voxel manipulator class + A fast voxel manipulator class Not thread-safe. */ @@ -71,16 +71,24 @@ public: if(p.Y > MaxEdge.Y) MaxEdge.Y = p.Y; if(p.Z > MaxEdge.Z) MaxEdge.Z = p.Z; } - v3s16 getExtent() + v3s16 getExtent() const { return MaxEdge - MinEdge + v3s16(1,1,1); } - s32 getVolume() + s32 getVolume() const { v3s16 e = getExtent(); return (s32)e.X * (s32)e.Y * (s32)e.Z; } - bool isInside(v3s16 p) + bool contains(VoxelArea &a) const + { + return( + a.MinEdge.X >= MinEdge.X && a.MaxEdge.X <= MaxEdge.X && + a.MinEdge.Y >= MinEdge.Y && a.MaxEdge.Y <= MaxEdge.Y && + a.MinEdge.Z >= MinEdge.Z && a.MaxEdge.Z <= MaxEdge.Z + ); + } + bool contains(v3s16 p) const { return( p.X >= MinEdge.X && p.X <= MaxEdge.X && @@ -88,7 +96,7 @@ public: p.Z >= MinEdge.Z && p.Z <= MaxEdge.Z ); } - bool operator==(const VoxelArea &other) + bool operator==(const VoxelArea &other) const { return (MinEdge == other.MinEdge && MaxEdge == other.MaxEdge); @@ -97,7 +105,7 @@ public: /* Translates position from virtual coordinates to array index */ - s32 index(s16 x, s16 y, s16 z) + s32 index(s16 x, s16 y, s16 z) const { v3s16 em = getExtent(); v3s16 off = MinEdge; @@ -105,12 +113,12 @@ public: //dstream<<" i("<