Skip to content

Instantly share code, notes, and snippets.

@wallabra
Last active September 30, 2017 18:44
Show Gist options
  • Select an option

  • Save wallabra/12a045e39c90253303d3a33af34ace6e to your computer and use it in GitHub Desktop.

Select an option

Save wallabra/12a045e39c90253303d3a33af34ace6e to your computer and use it in GitHub Desktop.
BSP node (incomplete) on UnrealScript.
//=============================================================================
// BSPNode.
//=============================================================================
class BSPNode expands Info;
struct TriPlane
{
var Vector points[3];
};
// BSP tree data
var BSPNode childNodes[2];
var BSPNode parentNode;
var BSPTree myTree;
var byte numChildren;
// Geometrical data
var Plane nodePlane;
var SubSector frontSub, backSub; // only if numChildren == 0
enum EPointPlane
{
PP_Front,
PP_Inside,
PP_Back
};
//===============================
// TriPlane normal
function Vector PlaneNormal(TriPlane plane, bool bBack)
{
local Vector U, V;
if ( bBack )
{
U = plane.points[1] - plane.points[0];
V = plane.points[2] - plane.points[1];
}
else
{
U = plane.points[2] - plane.points[1];
V = plane.points[1] - plane.points[0];
}
return U cross V;
}
// Center point of TriPlane's defining points
function Vector TriangleCenter(TriPlane plane)
{
local Vector res;
local int i;
for ( i = 0; i < 3; i++ )
res += plane.points[i];
return res / 3;
}
// Front or back of TriPlane
function EPointPlane InFrontOf(TriPlane plane, Vector other)
{
local float peq;
peq = planeNormal(plane, false) dot (other - triangleCenter(plane));
if ( peq > 0 )
return PP_Front;
else if ( peq == 0 )
return PP_Inside;
else
return PP_Back;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment