Windows Lua build instructions.
This commit is contained in:
29
README.md
29
README.md
@@ -106,7 +106,7 @@ If you now see extremely low res snake racing off the window then you are succes
|
|||||||
|
|
||||||
* Download "w64devkit" from https://github.com/skeeto/w64devkit and "CMake" from https://cmake.org/download/. Install CMake with path environment variables set.
|
* Download "w64devkit" from https://github.com/skeeto/w64devkit and "CMake" from https://cmake.org/download/. Install CMake with path environment variables set.
|
||||||
* Download Raylib source.
|
* Download Raylib source.
|
||||||
* Run "w64devkit.exe" and navigate( ls == dir ) to "raylib-master/src" folder and run...
|
* Run "w64devkit.exe" and navigate( ls == dir ) to "raylib/src" folder and run...
|
||||||
|
|
||||||
```
|
```
|
||||||
mingw32-make
|
mingw32-make
|
||||||
@@ -114,9 +114,26 @@ mingw32-make
|
|||||||
|
|
||||||
* You should now have "libraylib.a" file in that folder.
|
* You should now have "libraylib.a" file in that folder.
|
||||||
* Copy that to "ReiLua/lib" folder.
|
* Copy that to "ReiLua/lib" folder.
|
||||||
* I haven't got Lua to compile on Windows so we will download it's binarys from http://luabinaries.sourceforge.net/download.html. Take the one with "Windows x64 DLL and Includes (MingW-w64 6 Built)".
|
* Download Lua source from https://github.com/lua/lua
|
||||||
* Copy "liblua54.a" to "ReiLua/lib" folder.
|
* Make following changes to Lua's makefile so we can build on Windows.
|
||||||
* Change it's name to "liblua.a" or change the part in "CMakeLists.txt" where it links to "/lib/liblua.a" to "/lib/liblua54.a".
|
|
||||||
|
```
|
||||||
|
MYCFLAGS= $(LOCAL) -std=c99 -DLUA_USE_LINUX -DLUA_USE_READLINE
|
||||||
|
# to
|
||||||
|
MYCFLAGS= $(LOCAL) -std=c99
|
||||||
|
|
||||||
|
# And comment out or remove line.
|
||||||
|
MYLIBS= -ldl -lreadline
|
||||||
|
```
|
||||||
|
|
||||||
|
* Navigate "w64devkit" to Lua folder and build using.
|
||||||
|
|
||||||
|
```
|
||||||
|
mingw32-make
|
||||||
|
```
|
||||||
|
|
||||||
|
* There should now be "liblua.a" file in Lua folder.
|
||||||
|
* Copy that also to "ReiLua/lib" folder.
|
||||||
* Navigate to "ReiLua/build" folder on "w64devkit" and run...
|
* Navigate to "ReiLua/build" folder on "w64devkit" and run...
|
||||||
|
|
||||||
```
|
```
|
||||||
@@ -124,11 +141,10 @@ cmake -G "MinGW Makefiles" ..
|
|||||||
|
|
||||||
# Cmake uses NMake Makefiles by default so we will set the Generator to MinGW with -G
|
# Cmake uses NMake Makefiles by default so we will set the Generator to MinGW with -G
|
||||||
|
|
||||||
mingw32-make.exe
|
mingw32-make
|
||||||
```
|
```
|
||||||
|
|
||||||
* You should now have "ReiLua.exe".
|
* You should now have "ReiLua.exe".
|
||||||
* From Lua folder, copy "lua54.dll" to same folder with "ReiLua.exe". Don't change the name of it!
|
|
||||||
|
|
||||||
Run example.
|
Run example.
|
||||||
|
|
||||||
@@ -149,6 +165,7 @@ Compile ReiLua with.
|
|||||||
```
|
```
|
||||||
cmake .. -DDRM=ON
|
cmake .. -DDRM=ON
|
||||||
```
|
```
|
||||||
|
Note that DRM should be launched from CLI and not in X.
|
||||||
|
|
||||||
### Web
|
### Web
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ end
|
|||||||
local function tileCollision( entity )
|
local function tileCollision( entity )
|
||||||
local vPos = entity.pos + entity.vel -- Future pos with current vel.
|
local vPos = entity.pos + entity.vel -- Future pos with current vel.
|
||||||
local vRect = util.tableClone( entity.colRect )
|
local vRect = util.tableClone( entity.colRect )
|
||||||
local tinySlit = 0.001 -- Tiny slit between collisionRect and tile to prevent getting stuck on all seams.
|
local tinyGap = 0.001 -- Tiny slit between collisionRect and tile to prevent getting stuck on all seams.
|
||||||
|
|
||||||
-- Move test rect to predicted position.
|
-- Move test rect to predicted position.
|
||||||
vRect[1] = vPos.x - vRect[3] / 2
|
vRect[1] = vPos.x - vRect[3] / 2
|
||||||
@@ -121,14 +121,14 @@ local function tileCollision( entity )
|
|||||||
if isTileWall( Vec2:new( tileRect[3], y ) ) then
|
if isTileWall( Vec2:new( tileRect[3], y ) ) then
|
||||||
-- Use new_x to push out of tile.
|
-- Use new_x to push out of tile.
|
||||||
local new_x = tileRect[3] * TILE_SIZE - ( entity.colRect[1] + entity.colRect[3] )
|
local new_x = tileRect[3] * TILE_SIZE - ( entity.colRect[1] + entity.colRect[3] )
|
||||||
entity.vel.x = new_x - tinySlit
|
entity.vel.x = new_x - tinyGap
|
||||||
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
elseif entity.vel.x < 0 then
|
elseif entity.vel.x < 0 then
|
||||||
if isTileWall( Vec2:new( tileRect[1], y ) ) then
|
if isTileWall( Vec2:new( tileRect[1], y ) ) then
|
||||||
local new_x = ( tileRect[1] * TILE_SIZE + TILE_SIZE ) - entity.colRect[1]
|
local new_x = ( tileRect[1] * TILE_SIZE + TILE_SIZE ) - entity.colRect[1]
|
||||||
entity.vel.x = new_x + tinySlit, 0
|
entity.vel.x = new_x + tinyGap, 0
|
||||||
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
@@ -151,7 +151,7 @@ local function tileCollision( entity )
|
|||||||
if isTileWall( Vec2:new( x, tileRect[4] ) ) then
|
if isTileWall( Vec2:new( x, tileRect[4] ) ) then
|
||||||
local new_y = tileRect[4] * TILE_SIZE - ( entity.colRect[2] + entity.colRect[4] )
|
local new_y = tileRect[4] * TILE_SIZE - ( entity.colRect[2] + entity.colRect[4] )
|
||||||
-- math.max prevents bounce when hitting right on the corner.
|
-- math.max prevents bounce when hitting right on the corner.
|
||||||
entity.vel.y = math.max( new_y - tinySlit, 0 )
|
entity.vel.y = math.max( new_y - tinyGap, 0 )
|
||||||
player.onFloor = true
|
player.onFloor = true
|
||||||
|
|
||||||
break
|
break
|
||||||
@@ -159,7 +159,7 @@ local function tileCollision( entity )
|
|||||||
elseif entity.vel.y < 0 then
|
elseif entity.vel.y < 0 then
|
||||||
if isTileWall( Vec2:new( x, tileRect[2] ) ) then
|
if isTileWall( Vec2:new( x, tileRect[2] ) ) then
|
||||||
local new_y = ( tileRect[2] * TILE_SIZE + TILE_SIZE ) - entity.colRect[2]
|
local new_y = ( tileRect[2] * TILE_SIZE + TILE_SIZE ) - entity.colRect[2]
|
||||||
entity.vel.y = new_y + tinySlit
|
entity.vel.y = new_y + tinyGap
|
||||||
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|||||||
122
examples/point_triangle_collision/main.lua
Normal file
122
examples/point_triangle_collision/main.lua
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
package.path = package.path..";"..RL_GetBasePath().."../resources/lib/?.lua"
|
||||||
|
|
||||||
|
util = require "utillib"
|
||||||
|
Vec2 = require "vector2"
|
||||||
|
Vec3 = require "vector3"
|
||||||
|
|
||||||
|
local MOVE_SPEED = 0.5
|
||||||
|
|
||||||
|
local monitor = 0
|
||||||
|
local camera = -1
|
||||||
|
local texture = -1
|
||||||
|
local tri = {
|
||||||
|
a = Vec3:new( 0, 0, 0 ),
|
||||||
|
-- a = Vec3:new( 0, 1, 0 ),
|
||||||
|
b = Vec3:new( 0, 0, 2 ),
|
||||||
|
c = Vec3:new( 1, 0, 0 ),
|
||||||
|
normal = Vec3:new( 0, 0, 0 ),
|
||||||
|
}
|
||||||
|
local point = {
|
||||||
|
pos = Vec3:new( 0.2, 0.3, 0.2 ),
|
||||||
|
radius = 0.05,
|
||||||
|
lineLen = 0.5,
|
||||||
|
color = RED,
|
||||||
|
}
|
||||||
|
|
||||||
|
local debugText = ""
|
||||||
|
|
||||||
|
local function calcNormal( tri )
|
||||||
|
tri.normal = Vec3:new( RL_Vector3Normalize( RL_Vector3CrossProduct( tri.b - tri.a, tri.c - tri.a ) ) )
|
||||||
|
end
|
||||||
|
|
||||||
|
function init()
|
||||||
|
local mPos = RL_GetMonitorPosition( monitor )
|
||||||
|
local mSize = RL_GetMonitorSize( monitor )
|
||||||
|
local winSize = { 1920, 1080 }
|
||||||
|
|
||||||
|
RL_SetWindowState( FLAG_WINDOW_RESIZABLE )
|
||||||
|
RL_SetWindowPosition( { mPos[1] + mSize[1] / 2 - winSize[1] / 2, mPos[2] + mSize[2] / 2 - winSize[2] / 2 } )
|
||||||
|
RL_SetWindowSize( winSize )
|
||||||
|
camera = RL_CreateCamera3D()
|
||||||
|
RL_SetCamera3DPosition( camera, { 0, 1, 2 } )
|
||||||
|
RL_SetCamera3DTarget( camera, { 0, 0, 0 } )
|
||||||
|
RL_SetCamera3DUp( camera, { 0, 2, 0 } )
|
||||||
|
RL_SetCamera3DMode( camera, CAMERA_FREE )
|
||||||
|
|
||||||
|
calcNormal( tri )
|
||||||
|
end
|
||||||
|
|
||||||
|
local function checkCollisionPointTriangle( p, a, b, c, n )
|
||||||
|
local result = Vec3:new( 0, 0, 0 )
|
||||||
|
|
||||||
|
local v0 = Vec3:new( b.x - a.x, b.y - a.y, b.z - a.z ) -- Vector3Subtract( b, a )
|
||||||
|
local v1 = Vec3:new( c.x - a.x, c.y - a.y, c.z - a.z ) -- Vector3Subtract( c, a )
|
||||||
|
local v2 = Vec3:new( p.x - a.x, p.y - a.y, p.z - a.z ) -- Vector3Subtract( p, a )
|
||||||
|
local d00 = v0.x * v0.x + v0.y * v0.y + v0.z * v0.z -- Vector3DotProduct( v0, v0 )
|
||||||
|
local d01 = v0.x * v1.x + v0.y * v1.y + v0.z * v1.z -- Vector3DotProduct( v0, v1 )
|
||||||
|
local d11 = v1.x * v1.x + v1.y * v1.y + v1.z * v1.z -- Vector3DotProduct( v1, v1 )
|
||||||
|
local d20 = v2.x * v0.x + v2.y * v0.y + v2.z * v0.z -- Vector3DotProduct( v2, v0 )
|
||||||
|
local d21 = v2.x * v1.x + v2.y * v1.y + v2.z * v1.z -- Vector3DotProduct( v2, v1 )
|
||||||
|
|
||||||
|
local denom = d00 * d11 - d01 * d01
|
||||||
|
local distance = v2.x * n.x + v2.y * n.y + v2.z * n.z -- Vector3DotProduct( v2, n )
|
||||||
|
|
||||||
|
debugText = debugText.."distance "..distance.."\n"
|
||||||
|
debugText = debugText.."v0 "..v0.x..", "..v0.y..", "..v0.z.."\n"
|
||||||
|
debugText = debugText.."v1 "..v1.x..", "..v1.y..", "..v1.z.."\n"
|
||||||
|
debugText = debugText.."v2 "..v2.x..", "..v2.y..", "..v2.z.."\n"
|
||||||
|
|
||||||
|
result.y = ( d11 * d20 - d01 * d21) / denom
|
||||||
|
result.z = ( d00 * d21 - d01 * d20) / denom
|
||||||
|
result.x = 1.0 - ( result.z + result.y )
|
||||||
|
|
||||||
|
debugText = debugText.."result "..result.x..", "..result.y..", "..result.z.."\n"
|
||||||
|
|
||||||
|
return 0.0 < result.x and 0.0 < result.y and 0.0 < result.z and distance < 0.0, distance
|
||||||
|
end
|
||||||
|
|
||||||
|
function process( delta )
|
||||||
|
debugText = ""
|
||||||
|
|
||||||
|
if RL_IsKeyDown( string.byte( "D" ) ) then
|
||||||
|
point.pos.x = point.pos.x + MOVE_SPEED * delta
|
||||||
|
elseif RL_IsKeyDown( string.byte( "A" ) ) then
|
||||||
|
point.pos.x = point.pos.x - MOVE_SPEED * delta
|
||||||
|
end
|
||||||
|
if RL_IsKeyDown( string.byte( "S" ) ) then
|
||||||
|
point.pos.z = point.pos.z + MOVE_SPEED * delta
|
||||||
|
elseif RL_IsKeyDown( string.byte( "W" ) ) then
|
||||||
|
point.pos.z = point.pos.z - MOVE_SPEED * delta
|
||||||
|
end
|
||||||
|
if RL_IsKeyDown( string.byte( "R" ) ) then
|
||||||
|
point.pos.y = point.pos.y + MOVE_SPEED * delta
|
||||||
|
elseif RL_IsKeyDown( string.byte( "F" ) ) then
|
||||||
|
point.pos.y = point.pos.y - MOVE_SPEED * delta
|
||||||
|
end
|
||||||
|
|
||||||
|
if checkCollisionPointTriangle( point.pos, tri.a, tri.b, tri.c, tri.normal ) then
|
||||||
|
point.color = RED
|
||||||
|
else
|
||||||
|
point.color = GREEN
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function draw()
|
||||||
|
RL_ClearBackground( { 100, 150, 100 } )
|
||||||
|
RL_UpdateCamera3D( camera )
|
||||||
|
|
||||||
|
RL_BeginMode3D( camera )
|
||||||
|
RL_DrawGrid( 8, 1 )
|
||||||
|
RL_DrawTriangle3D( tri.a, tri.b, tri.c, { 200, 100, 100 } )
|
||||||
|
|
||||||
|
RL_DrawLine3D( { point.pos.x - point.lineLen, point.pos.y, point.pos.z },
|
||||||
|
{ point.pos.x + point.lineLen, point.pos.y, point.pos.z }, BLUE )
|
||||||
|
RL_DrawLine3D( { point.pos.x, point.pos.y - point.lineLen, point.pos.z },
|
||||||
|
{ point.pos.x, point.pos.y + point.lineLen, point.pos.z }, BLUE )
|
||||||
|
RL_DrawLine3D( { point.pos.x, point.pos.y, point.pos.z - point.lineLen },
|
||||||
|
{ point.pos.x, point.pos.y, point.pos.z + point.lineLen }, BLUE )
|
||||||
|
RL_DrawSphereWires( point.pos, point.radius, 3, 8, point.color )
|
||||||
|
RL_EndMode3D()
|
||||||
|
|
||||||
|
RL_DrawText( 0, debugText, { 10, 10 }, 30, 4, WHITE )
|
||||||
|
end
|
||||||
@@ -34,6 +34,7 @@ local function reset()
|
|||||||
-- Set ball to center.
|
-- Set ball to center.
|
||||||
ball.pos = { winSize[1] / 2, winSize[2] / 2 }
|
ball.pos = { winSize[1] / 2, winSize[2] / 2 }
|
||||||
-- Short for if math random result 1, set BALL_SPEED otherwise set -BALL_SPEED.
|
-- Short for if math random result 1, set BALL_SPEED otherwise set -BALL_SPEED.
|
||||||
|
-- Could be replaced by normal if statement for easier readability.
|
||||||
ball.vel[1] = math.random( 0, 1 ) == 1 and BALL_SPEED or -BALL_SPEED
|
ball.vel[1] = math.random( 0, 1 ) == 1 and BALL_SPEED or -BALL_SPEED
|
||||||
-- Start slow.
|
-- Start slow.
|
||||||
ball.vel[2] = 0
|
ball.vel[2] = 0
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ local function reset()
|
|||||||
-- Set ball to center.
|
-- Set ball to center.
|
||||||
ball.pos:set( winSize.x / 2, winSize.y / 2 )
|
ball.pos:set( winSize.x / 2, winSize.y / 2 )
|
||||||
-- Short for if math random result 1, set BALL_SPEED otherwise set -BALL_SPEED.
|
-- Short for if math random result 1, set BALL_SPEED otherwise set -BALL_SPEED.
|
||||||
|
-- Could be replaced by normal if statement for easier readability.
|
||||||
ball.vel.x = math.random( 0, 1 ) == 1 and BALL_SPEED or -BALL_SPEED
|
ball.vel.x = math.random( 0, 1 ) == 1 and BALL_SPEED or -BALL_SPEED
|
||||||
-- Start slow.
|
-- Start slow.
|
||||||
ball.vel.y = 0
|
ball.vel.y = 0
|
||||||
@@ -123,7 +124,7 @@ function draw()
|
|||||||
-- Draw ball. Ball position will be the center in drawCircle.
|
-- Draw ball. Ball position will be the center in drawCircle.
|
||||||
RL_DrawCircle( ball.pos, ball.radius, WHITE )
|
RL_DrawCircle( ball.pos, ball.radius, WHITE )
|
||||||
|
|
||||||
-- Draw scire
|
-- Draw score.
|
||||||
RL_DrawText( 0, playerLeft.score, { 50, 10 }, 40, 2, WHITE )
|
RL_DrawText( 0, playerLeft.score, { 50, 10 }, 40, 2, WHITE )
|
||||||
local rightTextSize = Vec2:new( RL_MeasureText( 0, playerRight.score, 40, 2 ) )
|
local rightTextSize = Vec2:new( RL_MeasureText( 0, playerRight.score, 40, 2 ) )
|
||||||
RL_DrawText( 0, playerRight.score, { winSize.x - 50 - rightTextSize.x, 10 }, 40, 2, WHITE )
|
RL_DrawText( 0, playerRight.score, { winSize.x - 50 - rightTextSize.x, 10 }, 40, 2, WHITE )
|
||||||
|
|||||||
Reference in New Issue
Block a user