Garry's Mod Wiki

Matrix

  VMatrix Matrix( table data = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}} )

Description

Returns a VMatrix object, a 4x4 matrix.

Arguments

1 table data = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}}
Initial data to initialize the matrix with. Leave empty to initialize an identity matrix. See examples for usage.

Can be a VMatrix to copy its data.

Returns

1 VMatrix
New matrix.

Example

Initializes a matrix, translates it by Vector( 4, 5, 6 ) and then scales it by Vector( 1, 2, 3 ).

local M = Matrix() M:Translate( Vector( 4, 5, 6 ) ) M:Scale( Vector( 1, 2, 3 ) ) -- This matrix is equivalent: local M2 = Matrix( { { 1, 0, 0, 4 }, { 0, 2, 0, 5 }, { 0, 0, 3, 6 }, { 0, 0, 0, 1 } } )