diff options
Diffstat (limited to 'examples/resources/lib')
| -rw-r--r-- | examples/resources/lib/bounding_box.lua | 72 | ||||
| -rw-r--r-- | examples/resources/lib/color.lua | 12 | ||||
| -rw-r--r-- | examples/resources/lib/raygui.lua | 2 | ||||
| -rw-r--r-- | examples/resources/lib/vector2.lua | 10 | ||||
| -rw-r--r-- | examples/resources/lib/vector3.lua | 12 |
5 files changed, 81 insertions, 27 deletions
diff --git a/examples/resources/lib/bounding_box.lua b/examples/resources/lib/bounding_box.lua index 3cf6787..ad3b45a 100644 --- a/examples/resources/lib/bounding_box.lua +++ b/examples/resources/lib/bounding_box.lua @@ -3,7 +3,7 @@ if table.unpack == nil then table.unpack = unpack end -local Vector3 = require( "vector3" ) +local Vector3 = Vector3 or require( "vector3" ) local BoundingBox = {} local metatable = { @@ -125,41 +125,35 @@ end function BoundingBox:getPoints() return { self.min:clone(), -- Down back left. - Vector3:new( self.max.x, self.min.y, self.min.z ), -- Down back right. - Vector3:new( self.min.x, self.min.y, self.max.z ), -- Down front left. - Vector3:new( self.max.x, self.min.y, self.max.z ), -- Down front right. - Vector3:new( self.min.x, self.max.y, self.min.z ), -- Up back left. - Vector3:new( self.max.x, self.max.y, self.min.z ), -- Up back right. - Vector3:new( self.min.x, self.max.y, self.max.z ), -- Up front left. + Vector3:new( self.max.x, self.min.y, self.min.z ), -- Down back right. + Vector3:new( self.min.x, self.min.y, self.max.z ), -- Down front left. + Vector3:new( self.max.x, self.min.y, self.max.z ), -- Down front right. + Vector3:new( self.min.x, self.max.y, self.min.z ), -- Up back left. + Vector3:new( self.max.x, self.max.y, self.min.z ), -- Up back right. + Vector3:new( self.min.x, self.max.y, self.max.z ), -- Up front left. self.max:clone(), -- Up front right. } end --- Assumes max is used as size. function BoundingBox:checkCollisionBox( b ) - return RL.CheckCollisionBoxes( self:maxToPos(), b:maxToPos() ) + return RL.CheckCollisionBoxes( self, b ) end --- Assumes max is used as size. function BoundingBox:checkCollisionSphere( center, radius ) - return RL.CheckCollisionBoxSphere( self:maxToPos(), center, radius ) + return RL.CheckCollisionBoxSphere( self, 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 + and point.x <= self.max.x + and point.y <= self.max.y + and point.z <= self.max.z end --- Assumes max is used as size. function BoundingBox:getRayCollision( ray ) - return RL.GetRayCollisionBox( ray, self:maxToPos() ) + return RL.GetRayCollisionBox( ray, self ) end -- Max to position from size. @@ -172,6 +166,36 @@ function BoundingBox:maxToSize() return BoundingBox:newV( self.min, self.max - self.min ) end +-- MAS stands for max as size. These functions handles max as size instead of position. + +function BoundingBox:checkCollisionBoxMASBox( b ) + return RL.CheckCollisionBoxes( self:tempMaxToPos(), b ) +end + +function BoundingBox:checkCollisionBoxMAS( b ) + return RL.CheckCollisionBoxes( self:tempMaxToPos(), b:tempMaxToPos() ) +end + +function BoundingBox:checkCollisionSphereMAS( center, radius ) + return RL.CheckCollisionBoxSphere( self:tempMaxToPos(), center, radius ) +end + +function BoundingBox:checkCollisionPointMAS( 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 + +function BoundingBox:getRayCollisionMAS( ray ) + return RL.GetRayCollisionBox( ray, self:tempMaxToPos() ) + -- return RL.GetRayCollisionBox( ray, self:maxToPos() ) +end + -- Temp pre generated objects to avoid "slow" table generation. local TEMP_COUNT = 100 @@ -230,6 +254,16 @@ function BoundingBox:tempB( b ) return object end +-- Max to position from size. +function BoundingBox:tempMaxToPos() + return BoundingBox:tempV( self.min, Vector3:tempT( RL.Vector3Add( self.min, self.max ) ) ) +end + +-- Max to size from position. +function BoundingBox:tempMaxToSize() + return BoundingBox:tempV( self.min, Vector3:tempT( RL.Vector3Subtract( self.max, self.min ) ) ) +end + function BoundingBox:getTempId() return curTemp end diff --git a/examples/resources/lib/color.lua b/examples/resources/lib/color.lua index 8ca3920..e16837b 100644 --- a/examples/resources/lib/color.lua +++ b/examples/resources/lib/color.lua @@ -3,8 +3,6 @@ if table.unpack == nil then table.unpack = unpack end -local Vector3 = require( "vector3" ) - local Color = {} local metatable = { __index = Color, @@ -92,7 +90,7 @@ function Color:setC( c ) end function Color:serialize() - return "Color:new("..self.r..","..self.g..","..self.b..","..self.a..")" + return "Color:new("..RL.Round( self.r )..","..RL.Round( self.g )..","..RL.Round( self.b )..","..RL.Round( self.a )..")" end function Color:arr() @@ -156,12 +154,12 @@ function Color:alphaBlend( dst, src, tint ) end function Color:lerp( color, amount ) - return Color:new( + return Color:temp( RL.Lerp( self.r, color.r, amount ), RL.Lerp( self.g, color.g, amount ), RL.Lerp( self.b, color.b, amount ), RL.Lerp( self.a, color.a, amount ) - ) + ):round() end function Color:round() @@ -173,6 +171,10 @@ function Color:round() ) end +function Color:invert() + return Color:new( 255 - self.r, 255 - self.g, 255 - self.b, self.a ) +end + -- Temp pre generated objects to avoid "slow" table generation. local TEMP_COUNT = 100 diff --git a/examples/resources/lib/raygui.lua b/examples/resources/lib/raygui.lua index 3caba0d..984b1ee 100644 --- a/examples/resources/lib/raygui.lua +++ b/examples/resources/lib/raygui.lua @@ -1729,7 +1729,7 @@ function Raygui:update() for i = #self.controls, 1, -1 do local control = self.controls[i] - if control.visible and control.update ~= nil and self:inView( control ) then + if control.visible and not control.noUpdate and control.update ~= nil and self:inView( control ) then if control:update() then self.focused = i diff --git a/examples/resources/lib/vector2.lua b/examples/resources/lib/vector2.lua index 8739ced..6da1977 100644 --- a/examples/resources/lib/vector2.lua +++ b/examples/resources/lib/vector2.lua @@ -36,6 +36,12 @@ local metatable = { __eq = function( v1, v2 ) return RL.Vector2Equals( v1, v2 ) end, + __lt = function( v1, v2 ) + return v1.x < v2.x and v1.y < v2.y + end, + __le = function( v1, v2 ) + return v1.x <= v2.x and v1.y <= v2.y + end, __concat = function( a, b ) return tostring( a )..tostring( b ) end, @@ -205,6 +211,10 @@ function Vector2:equals( v2 ) return RL.Vector2Equals( self, v2 ) end +function Vector2:sign() + return Vector2:new( RL.Sign( self.x ), RL.Sign( self.y ) ) +end + function Vector2:addEq( v2 ) self.x = self.x + v2.x self.y = self.y + v2.y diff --git a/examples/resources/lib/vector3.lua b/examples/resources/lib/vector3.lua index bfecb07..7b339f6 100644 --- a/examples/resources/lib/vector3.lua +++ b/examples/resources/lib/vector3.lua @@ -3,8 +3,6 @@ if table.unpack == nil then table.unpack = unpack end -local Vector2 = Vector2 or require( "vector2" ) - local Vector3 = {} local metatable = { __index = Vector3, @@ -38,6 +36,12 @@ local metatable = { __eq = function( v1, v2 ) return RL.Vector3Equals( v1, v2 ) end, + __lt = function( v1, v2 ) + return v1.x < v2.x and v1.y < v2.y and v1.z < v2.z + end, + __le = function( v1, v2 ) + return v1.x <= v2.x and v1.y <= v2.y and v1.z <= v2.z + end, __concat = function( a, b ) return tostring( a )..tostring( b ) end, @@ -232,6 +236,10 @@ function Vector3:equals( v2 ) return RL.Vector3Equals( self, v2 ) end +function Vector3:sign() + return Vector3:new( RL.Sign( self.x ), RL.Sign( self.y ), RL.Sign( self.z ) ) +end + function Vector3:addEq( v2 ) self.x = self.x + v2.x self.y = self.y + v2.y |
