Skip to content

Commit

Permalink
Add matrices, Hash is now an alias for number
Browse files Browse the repository at this point in the history
  • Loading branch information
Xseba360 committed Oct 17, 2022
1 parent 4a3f8c8 commit 33487b8
Show file tree
Hide file tree
Showing 2 changed files with 167 additions and 91 deletions.
61 changes: 54 additions & 7 deletions docs/data-types.def.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
---This is temporary until Luanalysis decides to support Lua5.4's undef.
---See here for more info: http://lua-users.org/lists/lua-l/2018-03/msg00155.html
---@type nil
undef = nil

--- @class Cam
local Cam = {}

Expand Down Expand Up @@ -30,8 +25,7 @@ local FireId = {}
--- @class Blip
local Blip = {}

--- @class Hash
local Hash = {}
--- @alias Hash number

--- @class ScrHandle
local ScrHandle = {}
Expand Down Expand Up @@ -75,6 +69,59 @@ local Vector4
--- @field public w number
local Quat

--- @shape Matrix2x2
--- @field public [1] Vector2
--- @field public [2] Vector2
local Matrix2x2

--- @shape Matrix3x2
--- @field public [1] Vector2
--- @field public [2] Vector2
--- @field public [3] Vector2
local Matrix3x2

--- @shape Matrix4x2
--- @field public [1] Vector2
--- @field public [2] Vector2
--- @field public [3] Vector2
--- @field public [4] Vector2
local Matrix4x2

--- @shape Matrix2x3
--- @field public [1] Vector3
--- @field public [2] Vector3
local Matrix2x3

--- @shape Matrix3x3
--- @field public [1] Vector3
--- @field public [2] Vector3
--- @field public [3] Vector3
local Matrix3x3

--- @shape Matrix4x3
--- @field public [1] Vector3
--- @field public [2] Vector3
--- @field public [3] Vector3
--- @field public [4] Vector3
local Matrix4x3

--- @shape Matrix2x4
--- @field public [1] Vector4
--- @field public [2] Vector4
local Matrix2x4

--- @shape Matrix3x4
--- @field public [1] Vector4
--- @field public [2] Vector4
--- @field public [3] Vector4
local Matrix3x4

--- @shape Matrix4x4
--- @field public [1] Vector4
--- @field public [2] Vector4
--- @field public [3] Vector4
--- @field public [4] Vector4
local Matrix4x4

--- @shape EventHandlerData
--- @field key number
Expand Down
197 changes: 113 additions & 84 deletions docs/vectors.def.lua
Original file line number Diff line number Diff line change
Expand Up @@ -187,90 +187,6 @@ end
function vector3(x, y, z)
end

--- Creates a new vector4 value.
--- In FiveM's Lua runtime, vectors are real data types, just like numbers, booleans and strings are. This means that type(vector4(1, 2, 3, 4)) will return vector4. More about this in the Lua runtime manual.
--- @usage ## Basic vector with zero length:
--- ```lua
--- vector4(0, 0, 0, 0)
--- ```
---
--- ## Vectors are a real data type:
--- ```lua
--- local v = vector4(1, 2, 3, 4)
--- print(type(v)) -- prints `vector4`
--- ```
--- ## Vectors support equality operators:
--- ```lua
--- local v1 = vector4(1, 2, 3, 4)
--- local v2 = vector4(1, 2, 3, 4)
--- local v3 = vector4(5, 6, 7, 8)
--- print(v1 == v2) -- prints `true`
--- print(v1 == v3) -- prints `false`
--- print(v1 ~= v3) -- prints `true`
--- ```
--- ## Arithmetic operations between vectors are supported:
--- ```lua
--- local v = vector4(1, 2, 3, 4)
--- print(v + 2) -- prints `vector4(3, 4, 5, 6)`
--- print(v - 2) -- prints `vector4(-1, 0, 1, 2)`
--- print(v * 2) -- prints `vector4(1, 4, 6, 8)`
--- print(v / 2) -- prints `vector4(0.5, 1, 1.5, 2)`
--- ```
--- ## Or even with another vector:
--- ```lua
--- local v1 = vector4(1, 2, 3, 4)
--- local v2 = vector4(5, 6, 7, 8)
--- print(v1 + v2) -- prints `vector4(6, 8, 9, 12)`
--- print(v1 - v2) -- prints `vector4(-4, -4, -4)`
--- print(v1 * v2) -- prints `vector4(5, 12, 21, 32)`
--- print(v1 / v2) -- prints `vector4(0.2, 0.33, 0.43, 0.5)`
--- ```
--- ## Vectors can be inverted:
--- ```lua
--- local v = vector4(1, 2, 3, 4)
--- print(-v) -- prints `vector4(-1, -2, -3, -4)`
--- ```
--- ## The length of the vector can be retrieved (pythagoras):
--- ```
--- local v = vector4(1, 2, 3, 4)
--- print(#v) -- prints `5.477`
--- ```
--- ## Vectors can be normalized:
--- ```lua
--- local v = vector3(1, 2, 3, 4)
--- print(norm(v)) -- prints `vector3(0.18, 0.37, 0.55, 0.73)`
--- ```
--- ## Unpacking works:
--- ```lua
--- local v = vector4(1, 2, 3, 4)
--- local x, y, z, w = table.unpack(v)
--- ```
--- ## To get the individual values from a vector:
--- ```lua
--- local v = vector4(1, 2, 3, 4)
--- print(v.x) -- prints `1`
--- print(v.y) -- prints `2`
--- print(v.z) -- prints `3`
--- print(v.w) -- prints `4`
--- ```
--- ## Vectors support arbitrary swizzling:
--- ```lua
--- local v = vector4(1, 2, 3, 4)
--- print(v.yx) -- prints `vector2(2, 1)`
--- print(v.wz) -- prints `vector2(3, 1)`
--- print(v.xyx) -- prints `vector3(1, 2, 1)`
--- print(v.ywz) -- prints `vector3(1, 2, 1)`
--- print(v.yxyx) -- prints `vector4(2, 1, 2, 1)`
--- print(v.zxwy) -- prints `vector4(3, 1, 1, 2)`
--- ```
--- @param x number
--- @param y number
--- @param z number
--- @param w number
--- @return Vector4
function vec(x, y, z, w)
end

--- Creates a new vector4 value.
--- In FiveM's Lua runtime, vectors are real data types, just like numbers, booleans and strings are. This means that type(vector4(1, 2, 3, 4)) will return vector4. More about this in the Lua runtime manual.
--- @usage ## Basic vector with zero length:
Expand Down Expand Up @@ -376,3 +292,116 @@ end
--- @overload fun(vec1: Vector3, vec2: Vector3):Quat
function quat(w, x, y, z)
end


--- Creates a new matrix depending on the count of arguments.
---
--- [More info about matrices here](https://github.com/citizenfx/lua/tree/luaglm-dev/cfx#matrices)
--- @param vec1 Vector4
--- @param vec2 Vector4
--- @param vec3 Vector4
--- @param vec4 Vector4
--- @return Matrix4x4
---
--- @overload fun(vec1: Vector2,vec2: Vector2): Matrix2x2
--- @overload fun(vec1: Vector2,vec2: Vector2,vec3: Vector2): Matrix3x2
--- @overload fun(vec1: Vector2,vec2: Vector2,vec3: Vector2,vec4: Vector2): Matrix4x2
---
--- @overload fun(vec1: Vector3, vec2: Vector3) : Matrix2x3
--- @overload fun(vec1: Vector3, vec2: Vector3, vec3: Vector3) : Matrix3x3
--- @overload fun(vec1: Vector3, vec2: Vector3, vec3: Vector3, vec4: Vector3) : Matrix4x3
---
--- @overload fun(vec1: Vector4, vec2: Vector4): Matrix2x4
--- @overload fun(vec1: Vector4, vec2: Vector4, vec3: Vector4): Matrix3x4
function mat(vec1,vec2,vec3,vec4)
end

--- Create a new 2x2 matrix
---
--- [More info about matrices here](https://github.com/citizenfx/lua/tree/luaglm-dev/cfx#matrices)
--- @param vec1 Vector2
--- @param vec2 Vector2
--- @return Matrix2x2
function mat2x2(vec1,vec2)
end

--- Create a new 3x2 matrix
---
--- [More info about matrices here](https://github.com/citizenfx/lua/tree/luaglm-dev/cfx#matrices)
--- @param vec1 Vector2
--- @param vec2 Vector2
--- @param vec3 Vector2
--- @return Matrix3x2
function mat3x2(vec1,vec2,vec3)
end

--- Create a new 4x2 matrix
---
--- [More info about matrices here](https://github.com/citizenfx/lua/tree/luaglm-dev/cfx#matrices)
--- @param vec1 Vector2
--- @param vec2 Vector2
--- @param vec3 Vector2
--- @param vec4 Vector2
--- @return Matrix4x2
function mat4x2(vec1,vec2,vec3,vec4)
end

--- Create a new 2x3 matrix
---
--- [More info about matrices here](https://github.com/citizenfx/lua/tree/luaglm-dev/cfx#matrices)
--- @param vec1 Vector3
--- @param vec2 Vector3
--- @return Matrix2x3
function mat2x3(vec1, vec2)
end

--- Create a new 3x3 matrix
---
--- [More info about matrices here](https://github.com/citizenfx/lua/tree/luaglm-dev/cfx#matrices)
--- @param vec1 Vector3
--- @param vec2 Vector3
--- @param vec3 Vector3
--- @return Matrix3x3
function mat3x3(vec1, vec2, vec3)
end

--- Create a new 4x3 matrix
---
--- [More info about matrices here](https://github.com/citizenfx/lua/tree/luaglm-dev/cfx#matrices)
--- @param vec1 Vector3
--- @param vec2 Vector3
--- @param vec3 Vector3
--- @param vec4 Vector3
--- @return Matrix4x3
function mat4x3(vec1, vec2, vec3, vec4)
end

--- Create a new 2x4 matrix
---
--- [More info about matrices here](https://github.com/citizenfx/lua/tree/luaglm-dev/cfx#matrices)
--- @param vec1 Vector4
--- @param vec2 Vector4
--- @return Matrix2x4
function mat2x4(vec1, vec2)
end

--- Create a new 3x4 matrix
---
--- [More info about matrices here](https://github.com/citizenfx/lua/tree/luaglm-dev/cfx#matrices)
--- @param vec1 Vector4
--- @param vec2 Vector4
--- @param vec3 Vector4
--- @return Matrix4x4
function mat3x4(vec1, vec2, vec3)
end

--- Create a new 4x4 matrix
---
--- [More info about matrices here](https://github.com/citizenfx/lua/tree/luaglm-dev/cfx#matrices)
--- @param vec1 Vector4
--- @param vec2 Vector4
--- @param vec3 Vector4
--- @param vec4 Vector4
--- @return Matrix4x4
function mat4x4(vec1, vec2, vec3, vec4)
end

0 comments on commit 33487b8

Please sign in to comment.