mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2024-12-18 16:10:58 +00:00
98 lines
3.9 KiB
C#
98 lines
3.9 KiB
C#
|
using CodeImp.DoomBuilder.Rendering;
|
|||
|
using SlimDX;
|
|||
|
|
|||
|
namespace CodeImp.DoomBuilder.GZBuilder.Data
|
|||
|
{
|
|||
|
public struct BoundingBoxSizes
|
|||
|
{
|
|||
|
public short MinX;
|
|||
|
public short MaxX;
|
|||
|
public short MinY;
|
|||
|
public short MaxY;
|
|||
|
public short MinZ;
|
|||
|
public short MaxZ;
|
|||
|
|
|||
|
//we need some reference here
|
|||
|
public BoundingBoxSizes(WorldVertex v) {
|
|||
|
MinX = MaxX = (short)v.x;
|
|||
|
MinY = MaxY = (short)v.y;
|
|||
|
MinZ = MaxZ = (short)v.z;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public class BoundingBoxTools
|
|||
|
{
|
|||
|
//this creates array of vectors resembling bounding box
|
|||
|
public static Vector3[] CalculateBoundingBox(BoundingBoxSizes bbs) {
|
|||
|
//center
|
|||
|
Vector3 v0 = new Vector3(bbs.MinX + (bbs.MaxX - bbs.MinX) / 2, bbs.MinY + (bbs.MaxY - bbs.MinY) / 2, bbs.MinZ + (bbs.MaxZ - bbs.MinZ) / 2);
|
|||
|
|
|||
|
//corners
|
|||
|
Vector3 v1 = new Vector3(bbs.MinX, bbs.MinY, bbs.MinZ);
|
|||
|
Vector3 v2 = new Vector3(bbs.MaxX, bbs.MinY, bbs.MinZ);
|
|||
|
Vector3 v3 = new Vector3(bbs.MinX, bbs.MaxY, bbs.MinZ);
|
|||
|
Vector3 v4 = new Vector3(bbs.MaxX, bbs.MaxY, bbs.MinZ);
|
|||
|
Vector3 v5 = new Vector3(bbs.MinX, bbs.MinY, bbs.MaxZ);
|
|||
|
Vector3 v6 = new Vector3(bbs.MaxX, bbs.MinY, bbs.MaxZ);
|
|||
|
Vector3 v7 = new Vector3(bbs.MinX, bbs.MaxY, bbs.MaxZ);
|
|||
|
Vector3 v8 = new Vector3(bbs.MaxX, bbs.MaxY, bbs.MaxZ);
|
|||
|
|
|||
|
return new Vector3[] { v0, v1, v2, v3, v4, v5, v6, v7, v8 };
|
|||
|
}
|
|||
|
|
|||
|
public static Vector3[] CalculateBoundingPlane(BoundingBoxSizes bbs) {
|
|||
|
//mxd. looks like I need only these 2 points, so...
|
|||
|
//center
|
|||
|
Vector3 v0 = new Vector3(bbs.MinX + (bbs.MaxX - bbs.MinX) / 2, bbs.MinY + (bbs.MaxY - bbs.MinY) / 2, bbs.MinZ + (bbs.MaxZ - bbs.MinZ) / 2);
|
|||
|
Vector3 v1 = new Vector3(bbs.MinX, bbs.MinY, bbs.MinZ);
|
|||
|
return new Vector3[] { v0, v1 };
|
|||
|
}
|
|||
|
|
|||
|
/*public static Vector3[] CalculateBoundingPlane(BoundingBoxSizes bbs) {
|
|||
|
if(bbs.MinX != bbs.MaxX && bbs.MinY != bbs.MaxY && bbs.MinZ != bbs.MaxZ)
|
|||
|
return CalculateBoundingBox(bbs);
|
|||
|
|
|||
|
//center
|
|||
|
Vector3 v0 = new Vector3(bbs.MinX + (bbs.MaxX - bbs.MinX) / 2, bbs.MinY + (bbs.MaxY - bbs.MinY) / 2, bbs.MinZ + (bbs.MaxZ - bbs.MinZ) / 2);
|
|||
|
Vector3 v1, v2, v3, v4;
|
|||
|
|
|||
|
//corners
|
|||
|
if (bbs.MinX == bbs.MaxX) {
|
|||
|
v1 = new Vector3(bbs.MinX, bbs.MinY, bbs.MinZ);
|
|||
|
v2 = new Vector3(bbs.MinX, bbs.MaxY, bbs.MinZ);
|
|||
|
v3 = new Vector3(bbs.MinX, bbs.MinY, bbs.MaxZ);
|
|||
|
v4 = new Vector3(bbs.MinX, bbs.MaxY, bbs.MaxZ);
|
|||
|
} else if (bbs.MinY == bbs.MaxY) {
|
|||
|
v1 = new Vector3(bbs.MinX, bbs.MinY, bbs.MinZ);
|
|||
|
v2 = new Vector3(bbs.MaxX, bbs.MinY, bbs.MinZ);
|
|||
|
v3 = new Vector3(bbs.MinX, bbs.MinY, bbs.MaxZ);
|
|||
|
v4 = new Vector3(bbs.MaxX, bbs.MinY, bbs.MaxZ);
|
|||
|
} else {
|
|||
|
v1 = new Vector3(bbs.MinX, bbs.MinY, bbs.MinZ);
|
|||
|
v2 = new Vector3(bbs.MaxX, bbs.MinY, bbs.MinZ);
|
|||
|
v3 = new Vector3(bbs.MinX, bbs.MaxY, bbs.MinZ);
|
|||
|
v4 = new Vector3(bbs.MaxX, bbs.MaxY, bbs.MinZ);
|
|||
|
}
|
|||
|
|
|||
|
return new Vector3[] { v0, v1, v2, v3, v4 };
|
|||
|
}*/
|
|||
|
|
|||
|
public static void UpdateBoundingBoxSizes(ref BoundingBoxSizes bbs, WorldVertex v) {
|
|||
|
if (v.x < bbs.MinX)
|
|||
|
bbs.MinX = (short)v.x;
|
|||
|
else if (v.x > bbs.MaxX)
|
|||
|
bbs.MaxX = (short)v.x;
|
|||
|
|
|||
|
if (v.z < bbs.MinZ)
|
|||
|
bbs.MinZ = (short)v.z;
|
|||
|
else if (v.z > bbs.MaxZ)
|
|||
|
bbs.MaxZ = (short)v.z;
|
|||
|
|
|||
|
if (v.y < bbs.MinY)
|
|||
|
bbs.MinY = (short)v.y;
|
|||
|
else if (v.y > bbs.MaxY)
|
|||
|
bbs.MaxY = (short)v.y;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|