Skip to content

Commit 0bd8764

Browse files
Add OOP class methods!
1 parent 86e2c5b commit 0bd8764

14 files changed

+683
-4
lines changed

classes/Matrix/Matrix.yaml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,106 @@ name: 'matrix'
22
description: |
33
Matrices are one of the most powerful features of MTA [OOP](/OOP). We did have a presence of Matrices before with [getElementMatrix](/getElementMatrix), but we were given an ugly disgusting table to play with. Now, with the new Matrix class, we can make and magically manipulate Matrices.
44
5+
methods:
6+
- name: create
7+
description: |
8+
Default constructor for the Matrix class. Returns a Matrix object.
9+
Can be instantiated in multiple ways.
10+
overloads:
11+
- signature: Matrix(Vector3 position[, Vector3 rotation])
12+
parameters:
13+
- name: position
14+
type: Vector3
15+
description: The position vector of the matrix
16+
- name: rotation
17+
type: Vector3
18+
optional: true
19+
description: The rotation vector of the matrix
20+
- signature: Matrix(Matrix matrixToClone)
21+
parameters:
22+
- name: matrixToClone
23+
type: Matrix
24+
description: A matrix you want to make a clone of
25+
- signature: Matrix()
26+
parameters: []
27+
description: Initialize a zero matrix
28+
29+
- name: transformPosition
30+
description: Transforms a given position vector using the Matrix.
31+
signature: Vector3 Matrix:transformPosition(Vector3 position)
32+
parameters:
33+
- name: position
34+
type: Vector3
35+
description: The position vector you want to transform
36+
examples:
37+
- description: Teleports a random player 5 meters in front of them
38+
code: |
39+
local player = getRandomPlayer()
40+
local desiredRelativePosition = Vector3(0, 5, 0)
41+
local matrix = player.matrix
42+
local newPosition = matrix:transformPosition(desiredRelativePosition)
43+
player.position = newPosition
44+
45+
- name: getPosition
46+
description: Returns the position vector of the matrix.
47+
signature: Vector3 Matrix:getPosition()
48+
parameters: []
49+
examples:
50+
- description: Prints the position of a random player.
51+
code: |
52+
local player = getRandomPlayer()
53+
local matrix = player.matrix
54+
local position = matrix:getPosition()
55+
outputChatBox("x: " .. position:getX() .. ", y: " .. position:getY() .. ", z:" .. position:getZ())
56+
57+
- name: getRotation
58+
description: Returns the rotation vector of the matrix.
59+
signature: Vector3 Matrix:getRotation()
60+
parameters: []
61+
examples:
62+
- description: Prints the rotation of a random player.
63+
code: |
64+
local player = getRandomPlayer()
65+
local matrix = player.matrix
66+
local rotation = matrix:getRotation()
67+
outputChatBox("rx: " .. rotation:getX() .. ", ry: " .. rotation:getY() .. ", rz:" .. rotation:getZ())
68+
69+
- name: getForward
70+
description: Returns the forward vector of the matrix.
71+
signature: Vector3 Matrix:getForward()
72+
parameters: []
73+
examples:
74+
- description: Prints the forward vector of a random player.
75+
code: |
76+
local player = getRandomPlayer()
77+
local matrix = player.matrix
78+
local vector = matrix:getForward()
79+
outputChatBox("X: " .. vector:getX() .. ", Y: " .. vector:getY() .. ", Z:" .. vector:getZ())
80+
81+
- name: getRight
82+
description: Returns the right vector of the matrix.
83+
signature: Vector3 Matrix:getRight()
84+
parameters: []
85+
examples:
86+
- description: Prints the right vector of a random player.
87+
code: |
88+
local player = getRandomPlayer()
89+
local matrix = player.matrix
90+
local vector = matrix:getRight()
91+
outputChatBox("X: " .. vector:getX() .. ", Y: " .. vector:getY() .. ", Z:" .. vector:getZ())
92+
93+
- name: getUp
94+
description: Returns the up vector of the matrix.
95+
signature: Vector3 Matrix:getUp()
96+
parameters: []
97+
examples:
98+
- description: Prints the up vector of a random player.
99+
code: |
100+
local player = getRandomPlayer()
101+
local matrix = player.matrix
102+
local vector = matrix:getUp()
103+
outputChatBox("X: " .. vector:getX() .. ", Y: " .. vector:getY() .. ", Z:" .. vector:getZ())
104+
5105
examples:
6106
- path: examples/matrix-1.lua
7107
description: >

classes/Vector/Vector2.yaml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,104 @@
11
name: 'vector2'
22
description: |
33
This is a 2D [Vector](/Vector) class.
4+
methods:
5+
- name: create
6+
description: |
7+
Default constructor for the Vector2 class. Returns a Vector2 object.
8+
overloads:
9+
- signature: Vector2(mixed vectorOrX[, float y])
10+
parameters:
11+
- name: vectorOrX
12+
type: float | table | vector2
13+
description: Vector2, table, or float indicating vector's coordinates
14+
- name: y
15+
type: float
16+
optional: true
17+
description: If vectorOrX is a float, this is the Y coordinate
418

19+
- name: normalize
20+
description: Normalizes the vector
21+
signature: bool Vector2.normalize(vector2 vector)
22+
parameters:
23+
- name: vector
24+
type: vector2
25+
description: Vector2 to normalize
26+
27+
- name: getX
28+
description: Gets the X coordinate of a vector
29+
signature: float Vector2.getX(vector2 vector)
30+
parameters:
31+
- name: vector
32+
type: vector2
33+
description: Vector2 to get X coordinate from
34+
35+
- name: getY
36+
description: Gets the Y coordinate of a vector
37+
signature: float Vector2.getY(vector2 vector)
38+
parameters:
39+
- name: vector
40+
type: vector2
41+
description: Vector2 to get Y coordinate from
42+
43+
- name: setX
44+
description: Sets the X coordinate of a vector
45+
signature: bool Vector2.setX(vector2 vector, float x)
46+
parameters:
47+
- name: vector
48+
type: vector2
49+
description: Vector2 to set X coordinate on
50+
- name: x
51+
type: float
52+
description: New X coordinate
53+
54+
- name: setY
55+
description: Sets the Y coordinate of a vector
56+
signature: bool Vector2.setY(vector2 vector, float y)
57+
parameters:
58+
- name: vector
59+
type: vector2
60+
description: Vector2 to set Y coordinate on
61+
- name: y
62+
type: float
63+
description: New Y coordinate
64+
65+
- name: getNormalized
66+
description: Gets a normalized version of the vector
67+
signature: vector2 Vector2.getNormalized(vector2 vector)
68+
parameters:
69+
- name: vector
70+
type: vector2
71+
description: Vector2 to get normalized version of
72+
73+
- name: getLength
74+
description: Gets the length of a vector
75+
signature: float Vector2.getLength(vector2 vector)
76+
parameters:
77+
- name: vector
78+
type: vector2
79+
description: Vector2 to get length from
80+
81+
- name: getSquaredLength
82+
description: Gets the squared length of a vector
83+
signature: float Vector2.getSquaredLength(vector2 vector)
84+
parameters:
85+
- name: vector
86+
type: vector2
87+
description: Vector2 to get squared length from
88+
89+
- name: dot
90+
description: Gets the dot product of two vectors
91+
signature: float Vector2.dot(vector2 vectorOne, vector2 vectorTwo)
92+
parameters:
93+
- name: vectorOne
94+
type: vector2
95+
description: First vector
96+
- name: vectorTwo
97+
type: vector2
98+
description: Second vector
99+
100+
examples:
101+
- path: examples/vector2-1.lua
102+
description: Checks if the player is using a low resolution
103+
- path: examples/vector2-2.lua
104+
description: Draws a red line from center to cursor, 200px long

0 commit comments

Comments
 (0)