-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use collision data to assist Sendificator tracing
- Loading branch information
1 parent
1a650dd
commit edd3fa6
Showing
4 changed files
with
137 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
95 changes: 95 additions & 0 deletions
95
packages/valve/clean_style/resources/scripts/vscripts/BEE2/collisions.nut
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Provides an interface to allow querying BEE's collision data. | ||
|
||
::BEECollide <- { | ||
// Must match Python constants! | ||
NOTHING = 0, | ||
SOLID = 1, | ||
DECORATION = 2, | ||
GRATING = 4, | ||
GLASS = 8, | ||
BRIDGE = 16, | ||
FIZZLER = 32, | ||
TEMPORARY = 64, | ||
ANTLINES = 128, | ||
OOB = 256, | ||
} | ||
|
||
class Plane { | ||
norm = null; | ||
dist = 0.0; | ||
constructor(x, y, z, distance) { | ||
norm = Vector(x, y, z); | ||
dist = distance; | ||
} | ||
} | ||
|
||
class Volume { | ||
mins = null; | ||
maxes = null; | ||
planes = null; // List of planes | ||
constructor(min_x, min_y, min_z, max_x, max_y, max_z, plane_list) { | ||
mins = Vector(min_x, min_y, min_z); | ||
maxes = Vector(max_x, max_y, max_z); | ||
planes = plane_list; | ||
} | ||
|
||
function point_inside(point, tol) { | ||
if (point.x < mins.x - tol || point.x > maxes.x + tol) { | ||
return false; | ||
} | ||
if (point.y < mins.y - tol || point.y > maxes.y + tol) { | ||
return false; | ||
} | ||
if (point.z < mins.z - tol || point.z > maxes.z + tol) { | ||
return false; | ||
} | ||
if (planes == null) { | ||
return true; | ||
} | ||
foreach(plane in planes) { | ||
if (plane.norm.Dot(point) < plane.dist + tol) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
class Entry { | ||
mask = 0; | ||
volumes = null; | ||
constructor(m, v) { | ||
mask = m; | ||
volumes = v; | ||
} | ||
} | ||
|
||
function point_collide(point, mask, tolerance) { | ||
foreach(entry in VOLUMES) { | ||
if ((entry.mask & mask) == 0) { | ||
continue; | ||
} | ||
foreach(volume in entry.volumes) { | ||
local center = (volume.mins + volume.maxes) * 0.5; | ||
if (volume.point_inside(point, tolerance)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
|
||
::BEE_PointCollide <- point_collide.bindenv(this); | ||
|
||
function Display() { | ||
printl("Dump collisions:") | ||
foreach(entry in VOLUMES) { | ||
printl("- " + entry.mask + " = ["); | ||
foreach(volume in entry.volumes) { | ||
local center = (volume.mins + volume.maxes) * 0.5; | ||
DebugDrawBox(center, volume.mins - center, volume.maxes - center, 255, 128, 64, 255, 1); | ||
printl(" center=" + center + ", " + (volume.mins - center) + " <-> " + (volume.maxes - center)); | ||
} | ||
} | ||
} |