diff options
Diffstat (limited to 'Resources/DefaultContent/Libraries')
11 files changed, 132 insertions, 59 deletions
diff --git a/Resources/DefaultContent/Libraries/GameLab/Engine/GL/init.lua b/Resources/DefaultContent/Libraries/GameLab/Engine/GL/init.lua index 87d47d3..f69d1f6 100644 --- a/Resources/DefaultContent/Libraries/GameLab/Engine/GL/init.lua +++ b/Resources/DefaultContent/Libraries/GameLab/Engine/GL/init.lua @@ -1,6 +1,20 @@ local GL = GameLab.Engine.GL or {} GameLab.Engine.GL = GL +local Matrix44 = GameLab.find("GameLab.Engine.Math.Matrix44") +GL.LoadPixelMatrix = function(l, r, b, t) + local ortho = Matrix44.New() + ortho:SetOrtho(l, r, b, t, 0.1, 10) + GL.MatrixMode(GL.EMatrixMode.Projection) + GL.LoadIdentity() + GL.LoadMatrix(ortho) + GL.MatrixMode(GL.EMatrixMode.ModelView) + GL.LoadIdentity() +end + +GL.LoadPixelMatrixTL = function (l, r, b, t) + +end return GL
\ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/GameLab/Engine/Math/Matrix33.lua b/Resources/DefaultContent/Libraries/GameLab/Engine/Math/Matrix33.lua new file mode 100644 index 0000000..8cb7e72 --- /dev/null +++ b/Resources/DefaultContent/Libraries/GameLab/Engine/Math/Matrix33.lua @@ -0,0 +1,7 @@ +local Matrix33 = GameLab.Class("GameLab.Engine.Math.Matrix33") + +Matrix33.Ctor = function(self) + +end + +return Matrix33
\ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/GameLab/Engine/Math/Matrix3x3.lua b/Resources/DefaultContent/Libraries/GameLab/Engine/Math/Matrix3x3.lua deleted file mode 100644 index b0aad47..0000000 --- a/Resources/DefaultContent/Libraries/GameLab/Engine/Math/Matrix3x3.lua +++ /dev/null @@ -1,7 +0,0 @@ -local Matrix3x3 = GameLab.Class("GameLab.Engine.Math.Matrix3x3") - -Matrix3x3.Ctor = function(self) - -end - -return Matrix3x3
\ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/GameLab/Engine/Math/Matrix44.lua b/Resources/DefaultContent/Libraries/GameLab/Engine/Math/Matrix44.lua new file mode 100644 index 0000000..2347207 --- /dev/null +++ b/Resources/DefaultContent/Libraries/GameLab/Engine/Math/Matrix44.lua @@ -0,0 +1,73 @@ +local Matrix44 = GameLab.Class("GameLab.Engine.Math.Matrix44") + +Matrix44.Ctor = function(self) + for r = 0, 3 do + for c = 0, 3 do + self["m"..r..c] = 0 + end + end +end + +Matrix44.Clear = function(self) + for r = 0, 3 do + for c = 0, 3 do + self["m"..r..c] = 0 + end + end +end + +Matrix44.SetRow = function(self, row, value) + +end + +Matrix44.SetColum = function(self, colum, value) + +end + +Matrix44.Set = function(self, row, colum ,value) + +end + +Matrix44.GetColum = function(self, colum) + +end + +Matrix44.GetRow = function(self, row) + +end + +-- note: n>0, f>0 +Matrix44.SetOrtho = function(self, l, r, b, t, n, f) + self:Clear() + self.m00 = 2 / (r - l) + self.m03 = (r + l) / (l - r) + self.m11 = 2 / (t - b) + self.m13 = (t + b) / (b - t) + self.m22 = 2 / (n - f) + self.m23 = (f + n) / (n - f) + self.m33 = 1 +end + +-- note: n>0, f>0 +Matrix44.SetFrustum = function(self, l, r, b, t, n, f) + self:Clear() + self.m00 = 2 * n / (r - l) + self.m02 = (r + l) / (r - l) + self.m11 = 2 * n / (t - b) + self.m12 = (t + b) / (t - b) + self.m22 = (f + n) / (n - f) + self.m23 = 2 * f * n / (n - f) + self.m32 = -1 +end + +-- note: n>0, f>0 +Matrix44.SetPerspective = function(self, fov, aspect, near, far) + self:Clear() + self.m00 = 1 / (aspect * math.tan(fov/2)) + self.m11 = 1 / math.tan(fov/2) + self.m22 = (far + near) / (near - far) + self.m23 = 2 * far * near / (near - far) + self.m32 = -1 +end + +return Matrix44
\ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/GameLab/Engine/Math/Matrix4x4.lua b/Resources/DefaultContent/Libraries/GameLab/Engine/Math/Matrix4x4.lua deleted file mode 100644 index 8e4d70a..0000000 --- a/Resources/DefaultContent/Libraries/GameLab/Engine/Math/Matrix4x4.lua +++ /dev/null @@ -1,31 +0,0 @@ -local Matrix4x4 = GameLab.Class("GameLab.Engine.Math.Matrix4x4") - -Matrix4x4.Ctor = function(self) - for r = 0, 3 do - for c = 0, 3 do - self["m"..r..c] = 0 - end - end -end - -Matrix4x4.SetRow = function(self, row, value) - -end - -Matrix4x4.SetColum = function(self, colum, value) - -end - -Matrix4x4.Set = function(self, row, colum ,value) - -end - -Matrix4x4.GetColum = function(self, colum) - -end - -Matrix4x4.GetRow = function(self, row) - -end - -return Matrix4x4
\ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/GameLab/Engine/Math/init.lua b/Resources/DefaultContent/Libraries/GameLab/Engine/Math/init.lua index bebc9ee..eb75db7 100644 --- a/Resources/DefaultContent/Libraries/GameLab/Engine/Math/init.lua +++ b/Resources/DefaultContent/Libraries/GameLab/Engine/Math/init.lua @@ -1,15 +1,15 @@ local m = GameLab.Engine.Math or {}
GameLab.Engine.Math = m
-local require = GameLab.require(...)
+local import = GameLab.import(...)
-require("Math")
-m.Vector2 = require("Vector2")
-m.Vector3 = require("Vector3")
-m.Vector4 = require("Vector4")
-m.Matrix4x4 = require("Matrix4x4")
-m.Matrix3x3 = require("Matrix3x3")
-m.Quaternion = require("Quaternion")
+import("Math")
+m.Vector2 = import("Vector2")
+m.Vector3 = import("Vector3")
+m.Vector4 = import("Vector4")
+m.Matrix44 = import("Matrix44")
+m.Matrix33 = import("Matrix33")
+m.Quaternion = import("Quaternion")
GameLab.Debug.Log("GameLab.Engine.Math loaded")
diff --git a/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/Color.lua b/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/Color.lua index fb3e773..bf908a4 100644 --- a/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/Color.lua +++ b/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/Color.lua @@ -1,7 +1,4 @@ local Color = GameLab.Class("GameLab.Engine.Rendering.Color") -GameLab.Engine.Rendering.Color = Color -- 避免require循环 - -local Color32 = GameLab.Engine.Rendering.Color32 or require("GameLab.Engine.Rendering.Color32") Color.Ctor = function(self, r, g, b, a) self.r = r @@ -11,6 +8,7 @@ Color.Ctor = function(self, r, g, b, a) end Color.ToColor32 = function(self) + local Color32 = GameLab.find("GameLab.Engine.Rendering.Color32") local c32 = Color32.New() c32.r = self.r * 255 c32.g = self.g * 255 diff --git a/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/Color32.lua b/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/Color32.lua index c17187a..d108dfb 100644 --- a/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/Color32.lua +++ b/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/Color32.lua @@ -1,7 +1,4 @@ local Color32 = GameLab.Class("GameLab.Engine.Rendering.Color32") -GameLab.Engine.Rendering.Color32 = Color32 -- 避免require循环 - -local Color = GameLab.Engine.Rendering.Color or require("GameLab.Engine.Rendering.Color") Color32.Ctor = function(self, r, g, b, a) self.r = r @@ -11,6 +8,7 @@ Color32.Ctor = function(self, r, g, b, a) end Color32.ToColor = function(self) + local Color = GameLab.find("GameLab.Engine.Rendering.Color") local c = Color.New() c.r = self.r / 255 c.g = self.g / 255 diff --git a/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/init.lua b/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/init.lua index 933adc1..d9b4e3e 100644 --- a/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/init.lua +++ b/Resources/DefaultContent/Libraries/GameLab/Engine/Rendering/init.lua @@ -1,10 +1,10 @@ local m = GameLab.Engine.Rendering or {} GameLab.Engine.Rendering = m -local require = GameLab.require(...) +local import = GameLab.import(...) -m.Color = require("Color") -m.Color32 = require("Color32") +m.Color = import("Color") +m.Color32 = import("Color32") m.LoadTexture = function(path) diff --git a/Resources/DefaultContent/Libraries/GameLab/Engine/init.lua b/Resources/DefaultContent/Libraries/GameLab/Engine/init.lua index 3987de1..f6f46a4 100644 --- a/Resources/DefaultContent/Libraries/GameLab/Engine/init.lua +++ b/Resources/DefaultContent/Libraries/GameLab/Engine/init.lua @@ -1,5 +1,5 @@ GameLab.Engine = GameLab.Engine or {} -local require = GameLab.require(...) +local import = GameLab.import(...) return GameLab.Engine
\ No newline at end of file diff --git a/Resources/DefaultContent/Libraries/GameLab/init.lua b/Resources/DefaultContent/Libraries/GameLab/init.lua index 92fef6c..51e1901 100644 --- a/Resources/DefaultContent/Libraries/GameLab/init.lua +++ b/Resources/DefaultContent/Libraries/GameLab/init.lua @@ -2,14 +2,35 @@ GameLab = GameLab or {} -- methods
-- 用于模块的init.lua中加载模块内的脚本
-GameLab.require = function(packageName)
- local _require = function(path)
+GameLab.import = function(packageName)
+ local _import = function(path)
local name = packageName .. "." .. path
local m = require(name)
--package.loaded[name] = m
return m
end
- return _require
+ return _import
+end
+
+-- 用于相对路径包含
+-- GameLab.require = function(className)
+-- local packageName = (type(className) == "string") and string.match(className, "^(.+)%.%w+$") or ""
+-- local _require = function(path)
+-- local name = packageName .. "." .. path
+-- local m = require(name)
+-- return m
+-- end
+-- return _require
+-- end
+
+GameLab.find = function(fullName)
+ if _G[fullName] ~= nil then
+ return _G[fullName]
+ end
+ if package.loaded[fullName] ~= nil then
+ return package.loaded[fullName]
+ end
+ return require(fullName)
end
-- classes
|