GetRayBoxCells fix.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
Reference in New Issue
Block a user