Added Lua Math Library

This commit is contained in:
OusmBlueNinja 2024-12-28 12:07:06 -06:00
parent f9404ef680
commit 2c432f7229
5 changed files with 129 additions and 56 deletions

57
assets/scripts/math.lua Normal file
View File

@ -0,0 +1,57 @@
-- math.lua
-- Math constants
local MathConstants = {
PI = 3.14159,
E = 2.71828,
TAU = 6.28318 -- 2 * PI
}
-- Basic math functions
local MathFunctions = {}
function MathFunctions.square(x)
return x * x
end
function MathFunctions.cube(x)
return x * x * x
end
function MathFunctions.max(a, b)
return (a > b) and a or b
end
function MathFunctions.min(a, b)
return (a < b) and a or b
end
function MathFunctions.clamp(value, minValue, maxValue)
if value < minValue then
return minValue
elseif value > maxValue then
return maxValue
else
return value
end
end
-- Trigonometric functions
local TrigFunctions = {}
function TrigFunctions.deg_to_rad(degrees)
return degrees * (MathConstants.PI / 180)
end
function TrigFunctions.rad_to_deg(radians)
return radians * (180 / MathConstants.PI)
end
-- Export the math module
local Math = {
constants = MathConstants,
functions = MathFunctions,
trig = TrigFunctions
}
return Math

View File

@ -1,4 +1,6 @@
-- script.lua
local Math = require("math")
local itterator = 0
local ticks = 0
local new_rotation = 0
@ -6,6 +8,8 @@ local speed = 50
function OnInit()
-- Log a message with a custom red color
Engine.Log("This is a red message.", {1.0, 0.0, 0.0, 1.0})
@ -49,7 +53,7 @@ function OnUpdate(deltaTime)
new_rotation = 0
end
local rotation = {x = -180, y = new_rotation, z = new_rotation} -- Define the new position
local rotation = {x = -180.0, y = new_rotation, z = 0.0} -- Define the new position
transform:SetRotation(rotation) -- Call the SetPosition method

View File

@ -18,7 +18,7 @@ DockId=0x00000002,0
Pos=374,27
Size=1212,770
Collapsed=0
DockId=0x00000003,0
DockId=0x0000000D,0
[Window][Performance]
Pos=8,774
@ -46,28 +46,36 @@ DockId=0x0000000B,0
[Window][Editor]
Pos=374,27
Size=1202,621
Size=1202,812
Collapsed=0
DockId=0x00000003,0
DockId=0x0000000D,0
[Window][Lua Text Editor]
Pos=374,650
Size=1202,519
Pos=374,841
Size=1202,328
Collapsed=0
DockId=0x00000004,0
[Docking][Data]
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,27 Size=1904,1142 Split=X Selected=0xF7365A5A
DockNode ID=0x00000009 Parent=0x14621557 SizeRef=364,1142 Split=Y Selected=0x3DC5AC3F
DockNode ID=0x00000005 Parent=0x00000009 SizeRef=364,745 Split=Y Selected=0x3DC5AC3F
DockNode ID=0x0000000B Parent=0x00000005 SizeRef=364,423 HiddenTabBar=1 Selected=0x3DC5AC3F
DockNode ID=0x0000000C Parent=0x00000005 SizeRef=364,320 HiddenTabBar=1 Selected=0x9DD4E196
DockNode ID=0x00000006 Parent=0x00000009 SizeRef=364,395 HiddenTabBar=1 Selected=0x726D8899
DockNode ID=0x0000000A Parent=0x14621557 SizeRef=1538,1142 Split=X
DockNode ID=0x00000007 Parent=0x0000000A SizeRef=357,1142 Selected=0x7737E8B2
DockNode ID=0x00000008 Parent=0x0000000A SizeRef=1545,1142 Split=X
DockNode ID=0x00000001 Parent=0x00000008 SizeRef=1202,1142 Split=Y Selected=0xF7365A5A
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1578,621 CentralNode=1 Selected=0xDF0EC458
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=1578,519 HiddenTabBar=1 Selected=0xAE3C694A
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=334,1142 HiddenTabBar=1 Selected=0x36DC96AB
[Window][Lua Editor Window]
Pos=374,600
Size=1202,569
Collapsed=0
DockId=0x0000000E,0
[Docking][Data]
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,27 Size=1904,1142 Split=X Selected=0xF7365A5A
DockNode ID=0x00000009 Parent=0x14621557 SizeRef=364,1142 Split=Y Selected=0x3DC5AC3F
DockNode ID=0x00000005 Parent=0x00000009 SizeRef=364,745 Split=Y Selected=0x3DC5AC3F
DockNode ID=0x0000000B Parent=0x00000005 SizeRef=364,423 HiddenTabBar=1 Selected=0x3DC5AC3F
DockNode ID=0x0000000C Parent=0x00000005 SizeRef=364,320 HiddenTabBar=1 Selected=0x9DD4E196
DockNode ID=0x00000006 Parent=0x00000009 SizeRef=364,395 HiddenTabBar=1 Selected=0x726D8899
DockNode ID=0x0000000A Parent=0x14621557 SizeRef=1538,1142 Split=X
DockNode ID=0x00000007 Parent=0x0000000A SizeRef=357,1142 Selected=0x7737E8B2
DockNode ID=0x00000008 Parent=0x0000000A SizeRef=1545,1142 Split=X
DockNode ID=0x00000001 Parent=0x00000008 SizeRef=1202,1142 Split=Y Selected=0xDF0EC458
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1202,812 Split=Y Selected=0xDF0EC458
DockNode ID=0x0000000D Parent=0x00000003 SizeRef=1202,571 CentralNode=1 Selected=0xDF0EC458
DockNode ID=0x0000000E Parent=0x00000003 SizeRef=1202,569 Selected=0xE98146C5
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=1202,328 Selected=0xAE3C694A
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=334,1142 HiddenTabBar=1 Selected=0x36DC96AB

View File

@ -2,111 +2,111 @@ Entities:
- ID: 0
Name: Player
Components:
Transform:
Position: [0, 2.79999995, -12.6000004]
Rotation: [-180, 146.58255, 0]
Scale: [1, 1, 1]
Mesh:
vao: 2
indexCount: 15810
textureID: 1
MeshPath: assets/models/LowPolyFiatUNO.obj
Transform:
Position: [0, 2.79999995, -12.6000004]
Rotation: [149.699997, -137.899994, -39.2999992]
Scale: [1, 1, 1]
- ID: 2
Name: Null Texture Box
Components:
Transform:
Position: [7.80000019, -8.10000038, -20.6000004]
Rotation: [-86.3000031, 0, -66]
Scale: [1, 1, 1]
Mesh:
vao: 5
indexCount: 36
textureID: 3
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [7.80000019, -8.10000038, -20.6000004]
Rotation: [-86.3000031, 0, -66]
Scale: [1, 1, 1]
- ID: 3
Name: Grass Box Top
Components:
Transform:
Position: [-1.20000005, -3.4000001, -17.7000008]
Rotation: [-23.5, 15.8999996, -59.9000015]
Scale: [1, 1, 1]
Mesh:
vao: 5
indexCount: 36
textureID: 4
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [-1.20000005, -3.4000001, -17.7000008]
Rotation: [-23.5, 15.8999996, -59.9000015]
Scale: [1, 1, 1]
- ID: 4
Name: Bark Box
Components:
Transform:
Position: [8.10000038, 0.800000012, -12]
Rotation: [-17.2999992, -16.1000004, -19.2999992]
Scale: [1, 1, 1]
Mesh:
vao: 5
indexCount: 36
textureID: 5
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [8.10000038, 0.800000012, -12]
Rotation: [-17.2999992, -16.1000004, -19.2999992]
Scale: [1, 1, 1]
- ID: 5
Name: Skybox
Components:
Transform:
Position: [0, 0, 43.2000008]
Rotation: [0, 0, 0]
Scale: [100, 100, 100]
Mesh:
vao: 5
indexCount: 36
textureID: 6
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [0, 0, 43.2000008]
Rotation: [0, 0, 0]
Scale: [100, 100, 100]
- ID: 6
Name: Null Texture Box
Components:
Transform:
Position: [-6.5, -6, -18]
Rotation: [15.8000002, -18.2000008, -11.1000004]
Scale: [1, 1, 1]
Mesh:
vao: 5
indexCount: 36
textureID: 3
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [-6.5, -6, -18]
Rotation: [15.8000002, -18.2000008, -11.1000004]
Scale: [1, 1, 1]
- ID: 7
Name: Grass Box Bottom
Components:
Transform:
Position: [6.5999999, 1.79999995, -23.8999996]
Rotation: [-16.1000004, -15.8999996, -35]
Scale: [1, 1, 1]
Mesh:
vao: 5
indexCount: 36
textureID: 4
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [6.5999999, 1.79999995, -23.8999996]
Rotation: [-16.1000004, -15.8999996, -35]
Scale: [1, 1, 1]
- ID: 8
Name: Wood Box
Components:
Transform:
Position: [-7.80000019, 0.200000003, -29.7999992]
Rotation: [22.2999992, -32.7999992, 0]
Scale: [1, 1, 1]
Mesh:
vao: 5
indexCount: 36
textureID: 1
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [-7.80000019, 0.200000003, -29.7999992]
Rotation: [22.2999992, -32.7999992, 0]
Scale: [1, 1, 1]
- ID: 9
Name: Bricks
Components:
Transform:
Position: [5.5, -2.9000001, -19.5]
Rotation: [-41.4000015, -22.6000004, -52.2999992]
Scale: [1, 1, 1]
Mesh:
vao: 5
indexCount: 36
textureID: 2
MeshPath: assets/models/DefaultMesh.obj
Transform:
Position: [5.5, -2.9000001, -19.5]
Rotation: [-41.4000015, -22.6000004, -52.2999992]
Scale: [1, 1, 1]
- ID: 10
Name: Script Handler
Components:

View File

@ -49,6 +49,10 @@ int g_GPU_Triangles_drawn_to_screen = 0;
GameObject *g_SelectedObject; // Pointer to the currently selected object
bool MyEngine::Init(int width, int height, const std::string &title)
{
DEBUG_PRINT("[START] Engine Init");