Skip to content

Commit 467f3d3

Browse files
committed
Updated Mat4 docs
1 parent 430a4e9 commit 467f3d3

9 files changed

Lines changed: 933 additions & 13 deletions

File tree

docs/API/Math/Mat4.md

Lines changed: 361 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,364 @@ returns
8484

8585
---
8686
87+
### `multiplyQuat`
88+
89+
Mat4 * Quat
90+
91+
```php
92+
static function multiplyQuat(\GL\Math\Mat4 $left, \GL\Math\Quat $right) : \GL\Math\Mat4
93+
```
94+
95+
Multiplies the left matrix by the right quaternion
96+
97+
Note: **This method only exists because there is a bug with the order of operation in PHP.**
98+
99+
---
100+
101+
### `copy`
102+
103+
Copys the current matrix
104+
105+
```php
106+
function copy() : \GL\Math\Mat4
107+
```
108+
109+
Returns a new instance of the current matrix with the same values. This means that any modifications made to the returned matrix will not affect the current matrix.
110+
111+
```php
112+
$copy = $matrix->copy();
113+
```
114+
115+
returns
116+
117+
: `\Mat4` The copy of the current matrix.
118+
119+
---
120+
121+
### `row`
122+
123+
Returns the row at the given index.
124+
125+
```php
126+
function row(int $index) : \GL\Math\Vec4
127+
```
128+
129+
Example usage:
130+
131+
```php
132+
$matrix = new Mat4([
133+
[1.0, 2.0, 3.0, 4.0],
134+
[5.0, 6.0, 7.0, 8.0],
135+
[9.0, 10.0, 11.0, 12.0],
136+
[13.0, 14.0, 15.0, 16.0]
137+
]);
138+
139+
// Get the first row
140+
$row = $matrix->row(0);
141+
// Expected result: Vec4(1.0, 2.0, 3.0, 4.0)
142+
```
143+
144+
arguments
145+
146+
: 1. `int` `$index` The index of the row to return.
147+
148+
returns
149+
150+
: `\Vec4` The row at the given index.
151+
152+
---
153+
154+
### `setRow`
155+
156+
Sets the row at the given index to the given row
157+
158+
```php
159+
function setRow(int $index, \GL\Math\Vec4 $row) : void
160+
```
161+
162+
Example usage:
163+
```php
164+
$matrix = new Mat4();
165+
$row = new Vec4(1, 2, 3, 4);
166+
$matrix->setRow(0, $row);
167+
```
168+
169+
arguments
170+
171+
: 1. `int` `$index` The index of the row to set.
172+
2. `\Vec4` `$row` The row to set.
173+
174+
returns
175+
176+
: `void`
177+
178+
---
179+
180+
### `col`
181+
182+
Returns the column at the given index.
183+
184+
```php
185+
function col(int $index) : \GL\Math\Vec4
186+
```
187+
188+
This method retrieves a column from the matrix at the specified index and returns it as a Vec4 object.
189+
190+
Example:
191+
```php
192+
$matrix = new Mat4([
193+
[1.0, 2.0, 3.0, 4.0],
194+
[5.0, 6.0, 7.0, 8.0],
195+
[9.0, 10.0, 11.0, 12.0],
196+
[13.0, 14.0, 15.0, 16.0]
197+
]);
198+
199+
$col = $matrix->col(0);
200+
201+
// Returns Vec4(1.0, 5.0, 9.0, 13.0)
202+
```
203+
204+
arguments
205+
206+
: 1. `int` `$index` The index of the column to return.
207+
208+
returns
209+
210+
: `\Vec4` The column at the given index.
211+
212+
---
213+
214+
### `setCol`
215+
216+
Sets the column at the given index to the given column
217+
218+
```php
219+
function setCol(int $index, \GL\Math\Vec4 $col) : void
220+
```
221+
222+
```php
223+
// Create a new matrix and set the second column
224+
$matrix = new Mat4();
225+
$col = new Vec4(1, 2, 3, 4);
226+
$matrix->setCol(1, $col);
227+
```
228+
229+
arguments
230+
231+
: 1. `int` `$index` The index of the column to set.
232+
2. `\Vec4` `$col` The column to set.
233+
234+
returns
235+
236+
: `void`
237+
238+
---
239+
240+
### `lookAt`
241+
242+
Sets the matrix to a lookAt matrix
243+
244+
```php
245+
function lookAt(\GL\Math\Vec3 $eye, \GL\Math\Vec3 $center, \GL\Math\Vec3 $up) : void
246+
```
247+
248+
The `lookAt()` method sets the matrix to a lookAt matrix based on the camera's position and orientation.
249+
It takes three parameters: `$eye`, `$center`, and `$up`, which are all instances of the `Vec3` class.
250+
251+
The `$eye` parameter indicates the position of the camera, while `$center` indicates the point
252+
in space to look at. The `$up` parameter specifies the up vector, which determines the orientation of the camera.
253+
254+
Example usage:
255+
256+
```php
257+
// Create a new matrix
258+
$matrix = new Mat4();
259+
260+
// Set the matrix to a lookAt matrix
261+
$matrix->lookAt(
262+
new Vec3(0, 0, 5), // eye
263+
new Vec3(0, 0, 0), // center
264+
new Vec3(0, 1, 0) // up
265+
);
266+
```
267+
268+
This will create a new matrix and set it to a lookAt matrix with the camera positioned at `(0, 0, 5)`,
269+
looking at the origin `(0, 0, 0)`, with the up vector pointing in the positive y direction.
270+
271+
arguments
272+
273+
: 1. `\Vec3` `$eye` The position of the camera.
274+
2. `\Vec3` `$center` The position to look at.
275+
3. `\Vec3` `$up` The up vector.
276+
277+
returns
278+
279+
: `void`
280+
281+
---
282+
283+
### `perspective`
284+
285+
Sets the matrix to a perspective matrix
286+
287+
```php
288+
function perspective(float $fov, float $aspect, float $near, float $far) : void
289+
```
290+
291+
```php
292+
$matrix->perspective($fov, $aspect, $near, $far);
293+
```
294+
295+
arguments
296+
297+
: 1. `float` `$fov` The field of view.
298+
2. `float` `$aspect` The aspect ratio.
299+
3. `float` `$near` The near plane.
300+
4. `float` `$far` The far plane.
301+
302+
returns
303+
304+
: `void`
305+
306+
---
307+
308+
### `ortho`
309+
310+
Sets the matrix to an orthographic matrix
311+
312+
```php
313+
function ortho(float $left, float $right, float $bottom, float $top, float $near, float $far) : void
314+
```
315+
316+
```php
317+
$matrix->ortho($left, $right, $bottom, $top, $near, $far);
318+
```
319+
320+
arguments
321+
322+
: 1. `float` `$left` The left plane.
323+
2. `float` `$right` The right plane.
324+
3. `float` `$bottom` The bottom plane.
325+
4. `float` `$top` The top plane.
326+
5. `float` `$near` The near plane.
327+
6. `float` `$far` The far plane.
328+
329+
returns
330+
331+
: `void`
332+
333+
---
334+
335+
### `transpose`
336+
337+
Tranposes the matrix
338+
339+
```php
340+
function transpose() : void
341+
```
342+
343+
```php
344+
$matrix->transpose();
345+
```
346+
347+
returns
348+
349+
: `void`
350+
351+
---
352+
353+
### `inverse`
354+
355+
Inverts the current matrix
356+
357+
```php
358+
function inverse() : void
359+
```
360+
361+
```php
362+
$matrix->inverse();
363+
```
364+
365+
returns
366+
367+
: `void`
368+
369+
---
370+
371+
### `scale`
372+
373+
Scale the matrix by the given vector
374+
375+
```php
376+
function scale(\GL\Math\Vec3 $scale) : void
377+
```
378+
379+
```php
380+
$matrix->scale(new Vec3(2, 2, 2));
381+
```
382+
383+
---
384+
385+
### `translate`
386+
387+
Translates the matrix by the given vector
388+
389+
```php
390+
function translate(\GL\Math\Vec3 $vector) : void
391+
```
392+
393+
```php
394+
$matrix->translate(new Vec3(1, 1, 1));
395+
```
396+
397+
arguments
398+
399+
: 1. `\Vec3` `$vector` The vector to translate by.
400+
401+
returns
402+
403+
: `void`
404+
405+
---
406+
407+
### `rotate`
408+
409+
Rotates the matrix by the given angle around the given axis
410+
411+
```php
412+
function rotate(float $angle, \GL\Math\Vec3 $axis) : void
413+
```
414+
415+
```php
416+
$matrix->rotate(GLM::radians(90), new Vec3(0, 1, 0));
417+
```
418+
419+
arguments
420+
421+
: 1. `float` `$angle` The angle to rotate by.
422+
2. `\Vec3` `$axis` The axis to rotate around.
423+
424+
returns
425+
426+
: `void`
427+
428+
---
429+
430+
### `determinant`
431+
432+
Retruns the determinant of the matrix
433+
434+
```php
435+
function determinant() : float
436+
```
437+
438+
```php
439+
$det = $matrix->determinant();
440+
```
441+
442+
returns
443+
444+
: `float` The determinant of the matrix.
445+
446+
---
447+

0 commit comments

Comments
 (0)