Skip to content

Commit

Permalink
luau api
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Sep 8, 2023
1 parent 7630a05 commit d5c608b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
24 changes: 3 additions & 21 deletions data/scripts/flying_cam.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local lmath = require "scripts/math"
-- add to entity with a camera component
-- behaves similar to camera in scene view

Expand All @@ -8,22 +9,6 @@ local dyaw = 0
local dpitch = 0
local rmb_down = 0

function addVec3(a, b)
return {a[1] + b[1], a[2] + b[2], a[3] + b[3]}
end

function mulVec3(a, f)
return {a[1] * f, a[2] * f, a[3] * f}
end

function mulQuat(a, b)
return {
a[4] * b[1] + b[4] * a[1] + a[2] * b[3] - b[2] * a[3],
a[4] * b[2] + b[4] * a[2] + a[3] * b[1] - b[3] * a[1],
a[4] * b[3] + b[4] * a[3] + a[1] * b[2] - b[1] * a[2],
a[4] * b[4] - a[1] * b[1] - a[2] * b[2] - a[3] * b[3]
}
end

function update(dt)
yaw = yaw + dyaw * dt
Expand All @@ -35,11 +20,11 @@ function update(dt)
if pitch < -1 then pitch = -1 end

local dir = { math.sin(yaw), 0, math.cos(yaw) }
local pos = addVec3(this.position, mulVec3(dir, -forward * dt))
local pos = lmath.addVec3(this.position, lmath.mulVec3(dir, -forward * dt))
this.position = pos
local yaw_quat = { 0, math.sin(yaw * 0.5), 0, math.cos(yaw * 0.5) }
local pitch_quat = { math.sin(pitch * 0.5), 0, 0, math.cos(pitch * 0.5) }
this.rotation = mulQuat(yaw_quat, pitch_quat)
this.rotation = lmath.mulQuat(yaw_quat, pitch_quat)
end

function onInputEvent(event : InputEvent)
Expand Down Expand Up @@ -71,6 +56,3 @@ function onInputEvent(event : InputEvent)
end
end
end

function start()
end
12 changes: 10 additions & 2 deletions data/scripts/lumix.d.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
declare ImGui: {
Begin : (string) -> boolean,
End : () -> (),
Text : (string) -> ()
Text : (string) -> (),
Button : (string) -> boolean,
SameLine : () -> ()
}

declare class World
Expand Down Expand Up @@ -39,20 +41,26 @@ end

declare class Entity
world : World
name : string
parent : Entity?
animator : Animator
gui_rect : GUIRect
navmesh_agent : NavmeshAgent
physical_controller : PhysicalController
rotation : any
position : any
scale : any
hasComponent : (Entity, any) -> boolean
getComponent : (Entity, any) -> any
destroy : (Entity) -> ()
createComponent : (Entity, any) -> any
end


declare this:Entity

declare Editor: {
ENTITY_PROPERTY : number,
BOOLEAN_PROPERTY : number,
setPropertyType : (any, string, number) -> ()
}

Expand Down
13 changes: 11 additions & 2 deletions data/scripts/math.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
return {
mulquat = function(a, b)
mulQuat = function(a, b)
return {
a[4] * b[1] + b[4] * a[1] + a[2] * b[3] - b[2] * a[3],
a[4] * b[2] + b[4] * a[2] + a[3] * b[1] - b[3] * a[1],
Expand All @@ -26,5 +26,14 @@ end,

mulVec3Num = function(v, f)
return {v[1] * f, v[2] * f, v[3] * f}
end
end,

addVec3 = function(a, b)
return {a[1] + b[1], a[2] + b[2], a[3] + b[3]}
end,

mulVec3 = function(a, f)
return {a[1] * f, a[2] * f, a[3] * f}
end,

}
2 changes: 1 addition & 1 deletion data/scripts/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,5 @@ function update(td)
local yaw_rot = math.makeQuatFromYaw(yaw)
local pitch_rot = math.makeQuatFromPitch(pitch)
this.rotation = yaw_rot
camera_pivot.rotation = math.mulquat(yaw_rot, pitch_rot)
camera_pivot.rotation = math.mulQuat(yaw_rot, pitch_rot)
end

0 comments on commit d5c608b

Please sign in to comment.