summaryrefslogtreecommitdiff
path: root/examples/resources/lib
diff options
context:
space:
mode:
authorjussi2024-07-19 22:57:31 +0300
committerjussi2024-07-19 22:57:31 +0300
commit03e9226b5f6c3fe4d113759b3a023ee92d7b2d4f (patch)
tree44c801b37e675aa63a0b13c7548be33e765e5842 /examples/resources/lib
parentc7b7975482bb33e7fb352c5759920748b6d3769b (diff)
downloadreilua-enhanced-03e9226b5f6c3fe4d113759b3a023ee92d7b2d4f.tar.gz
reilua-enhanced-03e9226b5f6c3fe4d113759b3a023ee92d7b2d4f.tar.bz2
reilua-enhanced-03e9226b5f6c3fe4d113759b3a023ee92d7b2d4f.zip
GetRayBoxCells.
Diffstat (limited to 'examples/resources/lib')
-rw-r--r--examples/resources/lib/bounding_box.lua (renamed from examples/resources/lib/boundingBox.lua)107
1 files changed, 104 insertions, 3 deletions
diff --git a/examples/resources/lib/boundingBox.lua b/examples/resources/lib/bounding_box.lua
index cc29fab..3cf6787 100644
--- a/examples/resources/lib/boundingBox.lua
+++ b/examples/resources/lib/bounding_box.lua
@@ -3,7 +3,7 @@ if table.unpack == nil then
table.unpack = unpack
end
-local Vector3 = Vector3 or require( "vector3" )
+local Vector3 = require( "vector3" )
local BoundingBox = {}
local metatable = {
@@ -12,6 +12,30 @@ local metatable = {
return "{{"..tostring( b.min.x )..", "..tostring( b.min.y )..", "..tostring( b.min.z ).."}, {"
..tostring( b.max.x )..", "..tostring( b.max.y )..", "..tostring( b.max.z ).."}}"
end,
+ -- __add = function( v1, v2 )
+ -- return Vector2:new( v1.x + v2.x, v1.y + v2.y )
+ -- end,
+ -- __sub = function( v1, v2 )
+ -- return Vector2:new( v1.x - v2.x, v1.y - v2.y )
+ -- end,
+ -- __mul = function( v1, v2 )
+ -- return Vector2:new( v1.x * v2.x, v1.y * v2.y )
+ -- end,
+ -- __div = function( v1, v2 )
+ -- return Vector2:new( v1.x / v2.x, v1.y / v2.y )
+ -- end,
+ -- __mod = function( v, value )
+ -- return Vector2:new( math.fmod( v.x, value ), math.fmod( v.y, value ) )
+ -- end,
+ -- __pow = function( v, value )
+ -- return Vector2:new( v.x ^ value, v.y ^ value )
+ -- end,
+ -- __unm = function( v )
+ -- return Vector2:new( -v.x, -v.y )
+ -- end,
+ __eq = function( b1, b2 )
+ return b1.min == b2.min and b1.max == b2.max
+ end,
}
--- Expects format { ... }, { ... }
@@ -111,26 +135,103 @@ function BoundingBox:getPoints()
}
end
+-- Assumes max is used as size.
function BoundingBox:checkCollisionBox( b )
return RL.CheckCollisionBoxes( self:maxToPos(), b:maxToPos() )
end
+-- Assumes max is used as size.
function BoundingBox:checkCollisionSphere( center, radius )
return RL.CheckCollisionBoxSphere( self:maxToPos(), center, radius )
end
+-- Assumes max is used as size.
+function BoundingBox:checkCollisionPoint( point )
+ local max = self.min + self.max
+
+ return self.min.x <= point.x
+ and self.min.y <= point.y
+ and self.min.z <= point.z
+ and point.x <= max.x
+ and point.y <= max.y
+ and point.z <= max.z
+end
+
+-- Assumes max is used as size.
function BoundingBox:getRayCollision( ray )
return RL.GetRayCollisionBox( ray, self:maxToPos() )
end
-- Max to position from size.
function BoundingBox:maxToPos()
- return BoundingBox:new( self.min, self.min + self.max )
+ return BoundingBox:newV( self.min, self.min + self.max )
end
-- Max to size from position.
function BoundingBox:maxToSize()
- return BoundingBox:new( self.min, self.max - self.min )
+ return BoundingBox:newV( self.min, self.max - self.min )
+end
+
+-- Temp pre generated objects to avoid "slow" table generation.
+
+local TEMP_COUNT = 100
+local tempPool = {}
+local curTemp = 1
+
+for _ = 1, TEMP_COUNT do
+ table.insert( tempPool, BoundingBox:new( { 0, 0, 0 }, { 0, 0, 0 } ) )
+end
+
+--- Expects format { ... }, { ... }
+function BoundingBox:temp( min, max )
+ local object = tempPool[ curTemp ]
+
+ curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
+
+ object.min = Vector3:tempT( min )
+ object.max = Vector3:tempT( max )
+
+ return object
+end
+
+--- Expects format { { ... }, { ... } }
+function BoundingBox:tempT( t )
+ local object = tempPool[ curTemp ]
+
+ curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
+
+ object.min = Vector3:tempT( t[1] )
+ object.max = Vector3:tempT( t[2] )
+
+ return object
+end
+
+--- Expects format { Vector3, Vector3 }
+function BoundingBox:tempV( min, max )
+ local object = tempPool[ curTemp ]
+
+ curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
+
+ object.min = Vector3:tempV( min )
+ object.max = Vector3:tempV( max )
+
+ return object
+end
+
+--- Expects format BoundingBox
+function BoundingBox:tempB( b )
+ local object = tempPool[ curTemp ]
+
+ curTemp = curTemp < TEMP_COUNT and curTemp + 1 or 1
+
+ object.min = Vector3:tempV( b.min )
+ object.max = Vector3:tempV( b.max )
+
+ return object
+end
+
+function BoundingBox:getTempId()
+ return curTemp
end
return BoundingBox