summaryrefslogtreecommitdiff
path: root/examples/resources
diff options
context:
space:
mode:
authorjussi2024-08-05 23:35:57 +0300
committerjussi2024-08-05 23:35:57 +0300
commitb011b2ca4e161fea2a742cb9b1673cd84cf0eba5 (patch)
treee8a46e45013cc0c2ad27a9f045349ae790cd0a07 /examples/resources
parentc6eb85b3674c36cfc426486d866a78dfc5452ae0 (diff)
downloadreilua-enhanced-b011b2ca4e161fea2a742cb9b1673cd84cf0eba5.tar.gz
reilua-enhanced-b011b2ca4e161fea2a742cb9b1673cd84cf0eba5.tar.bz2
reilua-enhanced-b011b2ca4e161fea2a742cb9b1673cd84cf0eba5.zip
GetRayBoxCells fix.
Diffstat (limited to 'examples/resources')
-rw-r--r--examples/resources/lib/bounding_box.lua72
-rw-r--r--examples/resources/lib/color.lua12
-rw-r--r--examples/resources/lib/raygui.lua2
-rw-r--r--examples/resources/lib/vector2.lua10
-rw-r--r--examples/resources/lib/vector3.lua12
-rw-r--r--examples/resources/shaders/glsl330/base.fs7
-rw-r--r--examples/resources/shaders/glsl330/base.vs5
7 files changed, 86 insertions, 34 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
diff --git a/examples/resources/shaders/glsl330/base.fs b/examples/resources/shaders/glsl330/base.fs
index 6b50062..57d9725 100644
--- a/examples/resources/shaders/glsl330/base.fs
+++ b/examples/resources/shaders/glsl330/base.fs
@@ -13,13 +13,12 @@ out vec4 finalColor;
// NOTE: Add here your custom variables
-void main()
-{
+void main() {
// Texel color fetching from texture sampler
- vec4 texelColor = texture(texture0, fragTexCoord);
+ vec4 texelColor = texture( texture0, fragTexCoord );
// NOTE: Implement here your fragment shader code
- finalColor = texelColor*colDiffuse;
+ finalColor = texelColor * colDiffuse;
}
diff --git a/examples/resources/shaders/glsl330/base.vs b/examples/resources/shaders/glsl330/base.vs
index 8cc2abb..04f50db 100644
--- a/examples/resources/shaders/glsl330/base.vs
+++ b/examples/resources/shaders/glsl330/base.vs
@@ -15,12 +15,11 @@ out vec4 fragColor;
// NOTE: Add here your custom variables
-void main()
-{
+void main() {
// Send vertex attributes to fragment shader
fragTexCoord = vertexTexCoord;
fragColor = vertexColor;
// Calculate final vertex position
- gl_Position = mvp*vec4(vertexPosition, 1.0);
+ gl_Position = mvp * vec4( vertexPosition, 1.0 );
} \ No newline at end of file