Last active
September 30, 2017 18:44
-
-
Save wallabra/12a045e39c90253303d3a33af34ace6e to your computer and use it in GitHub Desktop.
BSP node (incomplete) on UnrealScript.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //============================================================================= | |
| // 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