Added Lua Math Library
This commit is contained in:
parent
f9404ef680
commit
2c432f7229
57
assets/scripts/math.lua
Normal file
57
assets/scripts/math.lua
Normal 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
|
@ -1,4 +1,6 @@
|
|||||||
-- script.lua
|
-- script.lua
|
||||||
|
local Math = require("math")
|
||||||
|
|
||||||
local itterator = 0
|
local itterator = 0
|
||||||
local ticks = 0
|
local ticks = 0
|
||||||
local new_rotation = 0
|
local new_rotation = 0
|
||||||
@ -6,6 +8,8 @@ local speed = 50
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function OnInit()
|
function OnInit()
|
||||||
-- Log a message with a custom red color
|
-- Log a message with a custom red color
|
||||||
Engine.Log("This is a red message.", {1.0, 0.0, 0.0, 1.0})
|
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
|
new_rotation = 0
|
||||||
end
|
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
|
transform:SetRotation(rotation) -- Call the SetPosition method
|
||||||
|
|
||||||
|
24
imgui.ini
24
imgui.ini
@ -18,7 +18,7 @@ DockId=0x00000002,0
|
|||||||
Pos=374,27
|
Pos=374,27
|
||||||
Size=1212,770
|
Size=1212,770
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000003,0
|
DockId=0x0000000D,0
|
||||||
|
|
||||||
[Window][Performance]
|
[Window][Performance]
|
||||||
Pos=8,774
|
Pos=8,774
|
||||||
@ -46,16 +46,22 @@ DockId=0x0000000B,0
|
|||||||
|
|
||||||
[Window][Editor]
|
[Window][Editor]
|
||||||
Pos=374,27
|
Pos=374,27
|
||||||
Size=1202,621
|
Size=1202,812
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000003,0
|
DockId=0x0000000D,0
|
||||||
|
|
||||||
[Window][Lua Text Editor]
|
[Window][Lua Text Editor]
|
||||||
Pos=374,650
|
Pos=374,841
|
||||||
Size=1202,519
|
Size=1202,328
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000004,0
|
DockId=0x00000004,0
|
||||||
|
|
||||||
|
[Window][Lua Editor Window]
|
||||||
|
Pos=374,600
|
||||||
|
Size=1202,569
|
||||||
|
Collapsed=0
|
||||||
|
DockId=0x0000000E,0
|
||||||
|
|
||||||
[Docking][Data]
|
[Docking][Data]
|
||||||
DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,27 Size=1904,1142 Split=X Selected=0xF7365A5A
|
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=0x00000009 Parent=0x14621557 SizeRef=364,1142 Split=Y Selected=0x3DC5AC3F
|
||||||
@ -66,8 +72,10 @@ DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,27 Size=1904,1142 Split=
|
|||||||
DockNode ID=0x0000000A Parent=0x14621557 SizeRef=1538,1142 Split=X
|
DockNode ID=0x0000000A Parent=0x14621557 SizeRef=1538,1142 Split=X
|
||||||
DockNode ID=0x00000007 Parent=0x0000000A SizeRef=357,1142 Selected=0x7737E8B2
|
DockNode ID=0x00000007 Parent=0x0000000A SizeRef=357,1142 Selected=0x7737E8B2
|
||||||
DockNode ID=0x00000008 Parent=0x0000000A SizeRef=1545,1142 Split=X
|
DockNode ID=0x00000008 Parent=0x0000000A SizeRef=1545,1142 Split=X
|
||||||
DockNode ID=0x00000001 Parent=0x00000008 SizeRef=1202,1142 Split=Y Selected=0xF7365A5A
|
DockNode ID=0x00000001 Parent=0x00000008 SizeRef=1202,1142 Split=Y Selected=0xDF0EC458
|
||||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1578,621 CentralNode=1 Selected=0xDF0EC458
|
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=1202,812 Split=Y Selected=0xDF0EC458
|
||||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=1578,519 HiddenTabBar=1 Selected=0xAE3C694A
|
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
|
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=334,1142 HiddenTabBar=1 Selected=0x36DC96AB
|
||||||
|
|
||||||
|
@ -2,111 +2,111 @@ Entities:
|
|||||||
- ID: 0
|
- ID: 0
|
||||||
Name: Player
|
Name: Player
|
||||||
Components:
|
Components:
|
||||||
|
Transform:
|
||||||
|
Position: [0, 2.79999995, -12.6000004]
|
||||||
|
Rotation: [-180, 146.58255, 0]
|
||||||
|
Scale: [1, 1, 1]
|
||||||
Mesh:
|
Mesh:
|
||||||
vao: 2
|
vao: 2
|
||||||
indexCount: 15810
|
indexCount: 15810
|
||||||
textureID: 1
|
textureID: 1
|
||||||
MeshPath: assets/models/LowPolyFiatUNO.obj
|
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
|
- ID: 2
|
||||||
Name: Null Texture Box
|
Name: Null Texture Box
|
||||||
Components:
|
Components:
|
||||||
|
Transform:
|
||||||
|
Position: [7.80000019, -8.10000038, -20.6000004]
|
||||||
|
Rotation: [-86.3000031, 0, -66]
|
||||||
|
Scale: [1, 1, 1]
|
||||||
Mesh:
|
Mesh:
|
||||||
vao: 5
|
vao: 5
|
||||||
indexCount: 36
|
indexCount: 36
|
||||||
textureID: 3
|
textureID: 3
|
||||||
MeshPath: assets/models/DefaultMesh.obj
|
MeshPath: assets/models/DefaultMesh.obj
|
||||||
Transform:
|
|
||||||
Position: [7.80000019, -8.10000038, -20.6000004]
|
|
||||||
Rotation: [-86.3000031, 0, -66]
|
|
||||||
Scale: [1, 1, 1]
|
|
||||||
- ID: 3
|
- ID: 3
|
||||||
Name: Grass Box Top
|
Name: Grass Box Top
|
||||||
Components:
|
Components:
|
||||||
|
Transform:
|
||||||
|
Position: [-1.20000005, -3.4000001, -17.7000008]
|
||||||
|
Rotation: [-23.5, 15.8999996, -59.9000015]
|
||||||
|
Scale: [1, 1, 1]
|
||||||
Mesh:
|
Mesh:
|
||||||
vao: 5
|
vao: 5
|
||||||
indexCount: 36
|
indexCount: 36
|
||||||
textureID: 4
|
textureID: 4
|
||||||
MeshPath: assets/models/DefaultMesh.obj
|
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
|
- ID: 4
|
||||||
Name: Bark Box
|
Name: Bark Box
|
||||||
Components:
|
Components:
|
||||||
|
Transform:
|
||||||
|
Position: [8.10000038, 0.800000012, -12]
|
||||||
|
Rotation: [-17.2999992, -16.1000004, -19.2999992]
|
||||||
|
Scale: [1, 1, 1]
|
||||||
Mesh:
|
Mesh:
|
||||||
vao: 5
|
vao: 5
|
||||||
indexCount: 36
|
indexCount: 36
|
||||||
textureID: 5
|
textureID: 5
|
||||||
MeshPath: assets/models/DefaultMesh.obj
|
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
|
- ID: 5
|
||||||
Name: Skybox
|
Name: Skybox
|
||||||
Components:
|
Components:
|
||||||
Transform:
|
|
||||||
Position: [0, 0, 43.2000008]
|
|
||||||
Rotation: [0, 0, 0]
|
|
||||||
Scale: [100, 100, 100]
|
|
||||||
Mesh:
|
Mesh:
|
||||||
vao: 5
|
vao: 5
|
||||||
indexCount: 36
|
indexCount: 36
|
||||||
textureID: 6
|
textureID: 6
|
||||||
MeshPath: assets/models/DefaultMesh.obj
|
MeshPath: assets/models/DefaultMesh.obj
|
||||||
|
Transform:
|
||||||
|
Position: [0, 0, 43.2000008]
|
||||||
|
Rotation: [0, 0, 0]
|
||||||
|
Scale: [100, 100, 100]
|
||||||
- ID: 6
|
- ID: 6
|
||||||
Name: Null Texture Box
|
Name: Null Texture Box
|
||||||
Components:
|
Components:
|
||||||
|
Transform:
|
||||||
|
Position: [-6.5, -6, -18]
|
||||||
|
Rotation: [15.8000002, -18.2000008, -11.1000004]
|
||||||
|
Scale: [1, 1, 1]
|
||||||
Mesh:
|
Mesh:
|
||||||
vao: 5
|
vao: 5
|
||||||
indexCount: 36
|
indexCount: 36
|
||||||
textureID: 3
|
textureID: 3
|
||||||
MeshPath: assets/models/DefaultMesh.obj
|
MeshPath: assets/models/DefaultMesh.obj
|
||||||
Transform:
|
|
||||||
Position: [-6.5, -6, -18]
|
|
||||||
Rotation: [15.8000002, -18.2000008, -11.1000004]
|
|
||||||
Scale: [1, 1, 1]
|
|
||||||
- ID: 7
|
- ID: 7
|
||||||
Name: Grass Box Bottom
|
Name: Grass Box Bottom
|
||||||
Components:
|
Components:
|
||||||
|
Transform:
|
||||||
|
Position: [6.5999999, 1.79999995, -23.8999996]
|
||||||
|
Rotation: [-16.1000004, -15.8999996, -35]
|
||||||
|
Scale: [1, 1, 1]
|
||||||
Mesh:
|
Mesh:
|
||||||
vao: 5
|
vao: 5
|
||||||
indexCount: 36
|
indexCount: 36
|
||||||
textureID: 4
|
textureID: 4
|
||||||
MeshPath: assets/models/DefaultMesh.obj
|
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
|
- ID: 8
|
||||||
Name: Wood Box
|
Name: Wood Box
|
||||||
Components:
|
Components:
|
||||||
|
Transform:
|
||||||
|
Position: [-7.80000019, 0.200000003, -29.7999992]
|
||||||
|
Rotation: [22.2999992, -32.7999992, 0]
|
||||||
|
Scale: [1, 1, 1]
|
||||||
Mesh:
|
Mesh:
|
||||||
vao: 5
|
vao: 5
|
||||||
indexCount: 36
|
indexCount: 36
|
||||||
textureID: 1
|
textureID: 1
|
||||||
MeshPath: assets/models/DefaultMesh.obj
|
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
|
- ID: 9
|
||||||
Name: Bricks
|
Name: Bricks
|
||||||
Components:
|
Components:
|
||||||
|
Transform:
|
||||||
|
Position: [5.5, -2.9000001, -19.5]
|
||||||
|
Rotation: [-41.4000015, -22.6000004, -52.2999992]
|
||||||
|
Scale: [1, 1, 1]
|
||||||
Mesh:
|
Mesh:
|
||||||
vao: 5
|
vao: 5
|
||||||
indexCount: 36
|
indexCount: 36
|
||||||
textureID: 2
|
textureID: 2
|
||||||
MeshPath: assets/models/DefaultMesh.obj
|
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
|
- ID: 10
|
||||||
Name: Script Handler
|
Name: Script Handler
|
||||||
Components:
|
Components:
|
||||||
|
@ -49,6 +49,10 @@ int g_GPU_Triangles_drawn_to_screen = 0;
|
|||||||
|
|
||||||
GameObject *g_SelectedObject; // Pointer to the currently selected object
|
GameObject *g_SelectedObject; // Pointer to the currently selected object
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool MyEngine::Init(int width, int height, const std::string &title)
|
bool MyEngine::Init(int width, int height, const std::string &title)
|
||||||
{
|
{
|
||||||
DEBUG_PRINT("[START] Engine Init");
|
DEBUG_PRINT("[START] Engine Init");
|
||||||
|
Loading…
Reference in New Issue
Block a user