Changed engine to need to require engine
This commit is contained in:
parent
7fff6d92c7
commit
8b44d35871
@ -1,5 +1,7 @@
|
||||
-- script.lua
|
||||
local Math = require("math") -- Require the enhanced math module
|
||||
local Math = require("./assets/scripts/math") -- Require the enhanced math module
|
||||
local Engine = require("./assets/scripts/engine")
|
||||
|
||||
|
||||
-- Variables to track elapsed time and rotation
|
||||
local elapsedTime = 0
|
||||
@ -15,7 +17,8 @@ local bobFrequency = 0.5 -- Frequency of the bobbing (oscillations per second)
|
||||
local gun = nil
|
||||
local transform = nil
|
||||
|
||||
local TAU = 6.283185307179586
|
||||
local TAU = Math.constants.TAU
|
||||
|
||||
|
||||
|
||||
-- Update function called every frame
|
||||
|
@ -1,72 +0,0 @@
|
||||
-- script.lua
|
||||
local itterator = 0
|
||||
local ticks = 0
|
||||
local new_rotation = 0
|
||||
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})
|
||||
|
||||
-- Log a message with a custom green color
|
||||
Engine.Log("This is a green message.", {0.0, 1.0, 0.0, 1.0})
|
||||
|
||||
-- Log a message with a custom blue color
|
||||
Engine.Log("This is a blue message.", {0.0, 0.0, 1.0, 1.0})
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
function OnUpdate(deltaTime)
|
||||
|
||||
-- Attempt to retrieve the GameObject with the tag "Player"
|
||||
local player = Engine.GetGameObjectByTag("Player")
|
||||
|
||||
if player ~= nil then
|
||||
-- Successfully retrieved the GameObject
|
||||
-- Call the GetName method on the GameObject
|
||||
local transform = player:GetComponent("Transform")
|
||||
|
||||
|
||||
-- Log the player's name with a white color
|
||||
-- local pos = transform:GetPosition()
|
||||
-- local x = string.format("%.2f", pos.x)
|
||||
-- local y = string.format("%.2f", pos.y)
|
||||
-- local z = string.format("%.2f", pos.z)
|
||||
|
||||
-- Engine.Log("Player Pos: (" .. x .. ", " .. y .. ", " .. z .. ")", {1, 1, 1, 1})
|
||||
|
||||
--local position = {x = 0.0, y = 2.0, z = -12.0} -- Define the new position
|
||||
--transform:SetPosition(position) -- Call the SetPosition method
|
||||
new_rotation = new_rotation + (deltaTime*speed)
|
||||
|
||||
if (new_rotation > 720) then
|
||||
new_rotation = 0
|
||||
end
|
||||
|
||||
local rotation = {x = -180, y = new_rotation, z = new_rotation} -- Define the new position
|
||||
|
||||
transform:SetRotation(rotation) -- Call the SetPosition method
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- (Optional) Perform additional operations on the player GameObject
|
||||
-- For example, you might want to move the player, change properties, etc.
|
||||
-- player:Move(newPosition)
|
||||
-- player:SetHealth(100)
|
||||
else
|
||||
-- Failed to retrieve the GameObject; it doesn't exist
|
||||
-- Log an error message with a red color
|
||||
Engine.Log("Error: Player GameObject not found!", {1, 0, 0, 1})
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
1
assets/scripts/engine.lua
Normal file
1
assets/scripts/engine.lua
Normal file
@ -0,0 +1 @@
|
||||
return _T_Engine_Table
|
@ -1,5 +1,7 @@
|
||||
-- script.lua
|
||||
local Math = require("math")
|
||||
|
||||
local Math = require("./assets/scripts/math")
|
||||
local Engine = require("./assets/scripts/engine")
|
||||
|
||||
local itterator = 0
|
||||
local ticks = 0
|
||||
|
132
examples/BounceingItem.lua
Normal file
132
examples/BounceingItem.lua
Normal file
@ -0,0 +1,132 @@
|
||||
--
|
||||
-- This lua makes a Game object bounce a nd spin like a minecraft item.
|
||||
local GameObjectName = "Gun" -- This is the tag of the game object you want it to modify
|
||||
--
|
||||
--
|
||||
--
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
local Math = require("./assets/scripts/math") -- Require the enhanced math module
|
||||
local Engine = require("./assets/scripts/engine")
|
||||
|
||||
|
||||
-- Variables to track elapsed time and rotation
|
||||
local elapsedTime = 0
|
||||
local rotationSpeed = 90 -- Degrees per second for spinning
|
||||
local new_rotation = 0
|
||||
|
||||
-- Variables for bobbing effect
|
||||
local initial_position = {x = 0, y = 0, z = 0} -- To store the gun's initial position
|
||||
local bobAmplitude = 0.1 -- Amplitude of the bobbing (units)
|
||||
local bobFrequency = 0.5 -- Frequency of the bobbing (oscillations per second)
|
||||
|
||||
-- Reference to the Gun GameObject and its Transform component
|
||||
local gun = nil
|
||||
local transform = nil
|
||||
|
||||
local TAU = Math.constants.TAU
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Update function called every frame
|
||||
function OnUpdate(deltaTime)
|
||||
-- Ensure that the Gun and its Transform component are valid
|
||||
-- this was made after OnInit was depricated
|
||||
if not gun then
|
||||
gun = Engine.GetGameObjectByTag(GameObjectName)
|
||||
if gun then
|
||||
transform = gun:GetComponent("Transform")
|
||||
if transform then
|
||||
local pos = transform:GetPosition()
|
||||
initial_position = {x = pos.x, y = pos.y, z = pos.z}
|
||||
Engine.Log("Gun found and initial position updated.", {1, 1, 1, 1})
|
||||
else
|
||||
Engine.Log("Transform component not found on Gun.", {1, 1, 0, 1})
|
||||
return
|
||||
end
|
||||
else
|
||||
Engine.Log("Gun GameObject still not found.", {1, 1, 0, 1})
|
||||
return
|
||||
end
|
||||
elseif not transform then
|
||||
transform = gun:GetComponent("Transform")
|
||||
if transform then
|
||||
local pos = transform:GetPosition()
|
||||
initial_position = {x = pos.x, y = pos.y, z = pos.z}
|
||||
Engine.Log("Transform component found and initial position updated.", {1, 1, 1, 1})
|
||||
else
|
||||
Engine.Log("Transform component still not found on Gun.", {1, 1, 0, 1})
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Increment elapsed time
|
||||
elapsedTime = elapsedTime + deltaTime
|
||||
|
||||
-- === Spinning the Gun ===
|
||||
-- Update the rotation angle based on rotationSpeed and deltaTime
|
||||
new_rotation = new_rotation + (deltaTime * rotationSpeed)
|
||||
|
||||
-- Keep the rotation angle within 0-360 degrees to prevent overflow
|
||||
if new_rotation >= 360 then
|
||||
new_rotation = new_rotation - 360
|
||||
end
|
||||
|
||||
-- Define the new rotation (spinning around the Y-axis)
|
||||
local rotation = {
|
||||
x = -180, -- Preserving existing rotation on X-axis
|
||||
y = new_rotation, -- Updated rotation on Y-axis for spinning
|
||||
z = 0 -- Preserving existing rotation on Z-axis
|
||||
}
|
||||
|
||||
-- Apply the new rotation to the Transform component
|
||||
transform:SetRotation(rotation)
|
||||
|
||||
-- === Bobbing the Gun Up and Down ===
|
||||
-- Calculate the bobbing offset using a sine wave
|
||||
local bobOffset = bobAmplitude * math.sin(TAU * bobFrequency * elapsedTime)
|
||||
|
||||
-- Define the new position by adding the bobbing offset to the initial Y position
|
||||
local new_position = {
|
||||
x = initial_position.x, -- No change on X-axis
|
||||
y = initial_position.y + bobOffset, -- Bouncing up and down on Y-axis
|
||||
z = initial_position.z -- No change on Z-axis
|
||||
}
|
||||
|
||||
-- Apply the new position to the Transform component
|
||||
transform:SetPosition(new_position)
|
||||
|
||||
-- === Optional: Log Current Rotation and Position ===
|
||||
-- Uncomment the following lines if you wish to log the gun's current rotation and position
|
||||
-- local current_rotation = transform:GetRotation()
|
||||
-- Engine.Log(string.format("Gun Rotation: (X: %.2f, Y: %.2f, Z: %.2f)", current_rotation.x, current_rotation.y, current_rotation.z), {1, 1, 1, 1})
|
||||
|
||||
-- local current_position = transform:GetPosition()
|
||||
-- Engine.Log(string.format("Gun Position: (X: %.2f, Y: %.2f, Z: %.2f)", current_position.x, current_position.y, current_position.z), {1, 1, 1, 1})
|
||||
end
|
10
imgui.ini
10
imgui.ini
@ -86,13 +86,13 @@ DockId=0x00000014,0
|
||||
|
||||
[Window][Logger##logger]
|
||||
Pos=275,689
|
||||
Size=655,480
|
||||
Size=797,480
|
||||
Collapsed=0
|
||||
DockId=0x0000001B,0
|
||||
|
||||
[Window][Lua Text Editor##LuaEditor]
|
||||
Pos=932,689
|
||||
Size=633,480
|
||||
Pos=1074,689
|
||||
Size=491,480
|
||||
Collapsed=0
|
||||
DockId=0x0000001C,0
|
||||
|
||||
@ -148,8 +148,8 @@ DockSpace ID=0x14621557 Window=0x3DA2F1DE Pos=8,27 Size=1904,1
|
||||
DockNode ID=0x0000000D Parent=0x00000003 SizeRef=1202,571 Split=Y Selected=0xDFF75B3F
|
||||
DockNode ID=0x00000017 Parent=0x0000000D SizeRef=1303,660 CentralNode=1 HiddenTabBar=1 Selected=0xDFF75B3F
|
||||
DockNode ID=0x00000018 Parent=0x0000000D SizeRef=1303,480 Split=X Selected=0x9B5D3198
|
||||
DockNode ID=0x0000001B Parent=0x00000018 SizeRef=655,680 HiddenTabBar=1 Selected=0x1C0788A1
|
||||
DockNode ID=0x0000001C Parent=0x00000018 SizeRef=633,680 Selected=0x9B5D3198
|
||||
DockNode ID=0x0000001B Parent=0x00000018 SizeRef=797,680 HiddenTabBar=1 Selected=0x1C0788A1
|
||||
DockNode ID=0x0000001C Parent=0x00000018 SizeRef=491,680 Selected=0x7D9E6BA2
|
||||
DockNode ID=0x0000000E Parent=0x00000003 SizeRef=1202,569 Selected=0xE98146C5
|
||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=1202,291 Selected=0x9DD4E196
|
||||
DockNode ID=0x00000002 Parent=0x00000008 SizeRef=334,1142 HiddenTabBar=1 Selected=0x36DC96AB
|
||||
|
BIN
lib/KERNEL32.dll
BIN
lib/KERNEL32.dll
Binary file not shown.
BIN
lib/OPENGL32.dll
BIN
lib/OPENGL32.dll
Binary file not shown.
BIN
lib/SHELL32.dll
BIN
lib/SHELL32.dll
Binary file not shown.
BIN
lib/USER32.dll
BIN
lib/USER32.dll
Binary file not shown.
BIN
lib/glew32.dll
BIN
lib/glew32.dll
Binary file not shown.
BIN
lib/glfw3.dll
BIN
lib/glfw3.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
lib/msvcrt.dll
BIN
lib/msvcrt.dll
Binary file not shown.
@ -2,115 +2,127 @@ Entities:
|
||||
- ID: 0
|
||||
Name: Player
|
||||
Components:
|
||||
Transform:
|
||||
Position: [0, 2.79999995, -12.6000004]
|
||||
Rotation: [121.932602, 121.932602, 121.932602]
|
||||
Scale: [1, 1, 1]
|
||||
Mesh:
|
||||
vao: 2
|
||||
indexCount: 15810
|
||||
textureID: 1
|
||||
MeshPath: assets/models/LowPolyFiatUNO.obj
|
||||
Transform:
|
||||
Position: [0, 2.79999995, -12.6000004]
|
||||
Rotation: [185.076614, 185.076614, 185.076614]
|
||||
Scale: [1, 1, 1]
|
||||
- ID: 2
|
||||
Name: Gun
|
||||
Components:
|
||||
Transform:
|
||||
Position: [-0.899999976, 0.776287973, -0.300000012]
|
||||
Rotation: [-180, 75.4972076, 0]
|
||||
Scale: [0.00499999989, 0.00499999989, 0.00499999989]
|
||||
ScriptComponent:
|
||||
ScriptPath: assets/scripts/BouncingItem.lua
|
||||
Mesh:
|
||||
vao: 5
|
||||
indexCount: 116445
|
||||
textureID: 6
|
||||
textureID: 5
|
||||
MeshPath: assets/models/Ak-47.obj
|
||||
ScriptComponent:
|
||||
ScriptPath: assets/scripts/BouncingItem.lua
|
||||
Transform:
|
||||
Position: [-2.5, 0.806414127, -0.300000012]
|
||||
Rotation: [-180, 261.233307, 0]
|
||||
Scale: [0.00499999989, 0.00499999989, 0.00499999989]
|
||||
- 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: 1
|
||||
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: 1
|
||||
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: 1
|
||||
indexCount: 36
|
||||
textureID: 7
|
||||
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: 1
|
||||
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: 1
|
||||
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: 1
|
||||
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: 1
|
||||
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
|
||||
Components:
|
||||
ScriptComponent:
|
||||
ScriptPath: assets/scripts/script.lua
|
||||
ScriptPath: assets/scripts/script.lua
|
||||
- ID: 10
|
||||
Name: Gun Podium
|
||||
Components:
|
||||
Transform:
|
||||
Position: [-2.5, 2, -0.300000012]
|
||||
Rotation: [0, 0, 0]
|
||||
Scale: [0.25, 1, 0.25]
|
||||
Mesh:
|
||||
vao: 1
|
||||
indexCount: 36
|
||||
textureID: 4
|
||||
MeshPath: assets/models/DefaultMesh.obj
|
@ -78,10 +78,10 @@ bool LuaManager::Initialize(const std::string &scriptPath)
|
||||
|
||||
// Create the Engine table
|
||||
lua_newtable(m_LuaState);
|
||||
lua_setglobal(m_LuaState, "Engine");
|
||||
lua_setglobal(m_LuaState, "_T_Engine_Table");
|
||||
|
||||
// Bind the Log function to the Engine table
|
||||
lua_getglobal(m_LuaState, "Engine");
|
||||
lua_getglobal(m_LuaState, "_T_Engine_Table");
|
||||
lua_pushcfunction(m_LuaState, Lua_Engine_Log);
|
||||
lua_setfield(m_LuaState, -2, "Log");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user