mat4¶
Quelle: base/tealdef/scripts/mat4.d.tl
Hinweise
Typen der reinen Lua-Bibliothek für 4x4-Matrizen /scripts/mat4.tl (Mat4Serialized). Eine Matrix ist
eine flache Tabelle aus 16 Zahlen in spaltenweiser Reihenfolge (die Elemente 13, 14 und 15 enthalten die
Verschiebung). Das Spiel legt Transformationen von Modellen und Konstruktionen (transf) genauso ab.
Das Basisspiel lädt sie meist mit local mat4 = ug_require "/scripts/mat4.tl" as Mat4Serialized.
Beispiel
Mat4Serialized¶
record global base/tealdef/scripts/mat4.d.tl:3
global record Mat4Serialized
Laden: local transf = require "::/scripts/mat4.tl" as Mat4Serialized
Hinweise
Die 4x4-Matrixbibliothek, die ug_require "/scripts/mat4.tl" zurückgibt, und der Namensraum ihres Typs
Mat4. Matrizen sind flache Tabellen aus 16 Zahlen in spaltenweiser Reihenfolge. Die Verschiebung steht
in den Elementen 13–15.
Funktionen
new(col1 : Vec4Serialized.Vec4, col2 : Vec4Serialized.Vec4, col3 : Vec4Serialized.Vec4, col4 : Vec4Serialized.Vec4) : Mat4 base/tealdef/scripts/mat4.d.tl:10
Aufruf: transf.new(…)
Hinweise
Erzeugt eine Matrix aus vier Spaltenvektoren und hängt die Operatoren +, - und * an.
| Parameter | Typ | Beschreibung |
|---|---|---|
col1 |
Vec4Serialized.Vec4 |
Erste Spalte (Elemente 1–4). |
col2 |
Vec4Serialized.Vec4 |
Zweite Spalte (Elemente 5–8). |
col3 |
Vec4Serialized.Vec4 |
Dritte Spalte (Elemente 9–12). |
col4 |
Vec4Serialized.Vec4 |
Vierte Spalte (Elemente 13–16). Bei affinen Transformationen sind x, y und z die Verschiebung. |
Rückgabe Mat4: Die Matrix als flache Tabelle mit 16 Elementen.
identity() : Mat4 base/tealdef/scripts/mat4.d.tl:11
Aufruf: transf.identity(…)
Hinweise
Gibt die 4x4-Einheitsmatrix zurück.
Rückgabe Mat4
Im Basisspiel verwendet: 29-mal in 12 Dateien
base/content/depots/rail/rail/rail_depot.script.lua:359
base/content/industries/industryutil.lua:104
base/content/landmarks/landmark_util_serialized.tl:41
base/content/stations/air/air/airfield/airfield_modules.script.lua:219
base/content/stations/air/air/airport/airport_modules.script.lua:337
base/content/stations/air/air/helipad/helipad.script.lua:152
… und 6 weitere Dateien.
add(m1 : Mat4, m2 : Mat4) : Mat4 base/tealdef/scripts/mat4.d.tl:13
Aufruf: transf.add(…)
Hinweise
Gibt die elementweise Summe m1 + m2 zurück.
Rückgabe Mat4
sub(m1 : Mat4, m2 : Mat4) : Mat4 base/tealdef/scripts/mat4.d.tl:14
Aufruf: transf.sub(…)
Hinweise
Gibt die elementweise Differenz m1 - m2 zurück.
Rückgabe Mat4
mul(m1 : Mat4, m2 : Mat4) : Mat4 base/tealdef/scripts/mat4.d.tl:15
Aufruf: transf.mul(…)
Hinweise
Gibt das Matrixprodukt m1 * m2 zurück, also die Transformation, die erst m2 und dann m1 anwendet.
Rückgabe Mat4
Details
Um ein Teil relativ zu einer übergeordneten Transformation zu platzieren, schreibst du
mat4.mul(parentTransf, localTransf).
Beispiel
Im Basisspiel verwendet: 60-mal in 20 Dateien
base/content/buildings/townbuildingutil.lua:154
model.transf = transf.mul(transf.transl({ x = 0, y = 0, z = math.lerp(p1[3], p2[3], (alignmentPos[1] - p1[1]) / dx) }), model.transf)
base/content/industries/fieldutil.lua:282
base/content/industries/fishing_grounds/fishing_grounds/modules.script.lua:28
base/content/industries/oil_well/oil_well/modules.script.lua:20
base/content/infrastructure/traffic_light/traffic_light/trafficlightutil.lua:77
base/content/infrastructure/tunnel/tunnel/tunnel.script.lua:143
… und 14 weitere Dateien.
gemv(m : Mat4, v : Vec4Serialized.Vec4) : Vec4Serialized.Vec4 base/tealdef/scripts/mat4.d.tl:21
Aufruf: transf.gemv(…)
General matrix-vector multiplication.
| Parameter | Typ | Beschreibung |
|---|---|---|
m |
Mat4 |
matrix |
v |
Vec4Serialized.Vec4 |
vector |
Rückgabe Vec4Serialized.Vec4: resulting vector
Im Basisspiel verwendet: 30-mal in 4 Dateien
base/content/scripts/scripts/construction/modulesutil.lua:358
base/content/stations/air/air/airport/airport_modules.script.lua:16
base/content/stations/street/street/modular_street_station/modules.script.lua:105
base/content/stations/water/water/modules.script.lua:844
flipY(m : Mat4) : Mat4 base/tealdef/scripts/mat4.d.tl:26
Aufruf: transf.flipY(…)
Multiply the y coordinate of each column with -1.
| Parameter | Typ | Beschreibung |
|---|---|---|
m |
Mat4 |
matrix |
Rückgabe Mat4: matrix with Y flipped
transl(t : Vec3Serialized.Vec3) : Mat4 base/tealdef/scripts/mat4.d.tl:30
Aufruf: transf.transl(…)
Create translation matrix from a translation vector.
| Parameter | Typ | Beschreibung |
|---|---|---|
t |
Vec3Serialized.Vec3 |
translation vector |
Rückgabe Mat4: translation matrix
Im Basisspiel verwendet: 222-mal in 35 Dateien
base/content/buildings/townbuildingutil.lua:154
model.transf = transf.mul(transf.transl({ x = 0, y = 0, z = math.lerp(p1[3], p2[3], (alignmentPos[1] - p1[1]) / dx) }), model.transf)
base/content/depots/rail/rail/rail_maint_station.script.lua:174
base/content/depots/road/road/road_depot/road_depot.script.lua:216
base/content/depots/road/road/road_maint_station.script.lua:259
base/content/depots/road/road/tram_depot/tram_depot.script.lua:247
base/content/depots/water/water/water_depot.script.lua:407
… und 29 weitere Dateien.
scale(t : Vec3Serialized.Vec3) : Mat4 base/tealdef/scripts/mat4.d.tl:34
Aufruf: transf.scale(…)
Create scale matrix.
| Parameter | Typ | Beschreibung |
|---|---|---|
t |
Vec3Serialized.Vec3 |
scale vector |
Rückgabe Mat4: scale matrix
Im Basisspiel verwendet: 48-mal in 11 Dateien
base/content/base/base/metadataanimationutil.lua:79
base/content/gui/gui/construction/construction.css.lua:415
base/content/gui/gui/main/builtin.css.lua:38
base/content/gui/gui/main/hud_icon_master.css.lua:19
base/content/gui/gui/main/tile_list_react_util.css.lua:118
base/content/gui/gui/menu/main_menu.css.lua:245
… und 5 weitere Dateien.
rotZ(rotZ : number) : Mat4 base/tealdef/scripts/mat4.d.tl:38
Aufruf: transf.rotZ(…)
Create rotation matrix for the rotation around Z axis.
| Parameter | Typ | Beschreibung |
|---|---|---|
rotZ |
number |
rotation angle in radians |
Rückgabe Mat4: rotation matrix
Im Basisspiel verwendet: 18-mal in 11 Dateien
base/content/base/base/metadataanimationutil.lua:304
base/content/gui/gui/main/tile_list_react_util.css.lua:22
base/content/gui/gui/menu/main_menu.css.lua:72
base/content/industries/fishing_grounds/fishing_grounds/modules.script.lua:28
base/content/industries/oil_well/oil_well/modules.script.lua:20
base/content/infrastructure/tunnel/tunnel/tunnel.script.lua:158
… und 5 weitere Dateien.
rotY(rotY : number) : Mat4 base/tealdef/scripts/mat4.d.tl:42
Aufruf: transf.rotY(…)
Create rotation matrix for the rotation around Y axis.
| Parameter | Typ | Beschreibung |
|---|---|---|
rotY |
number |
rotation angle in radians |
Rückgabe Mat4: rotation matrix
rotX(rotX : number) : Mat4 base/tealdef/scripts/mat4.d.tl:46
Aufruf: transf.rotX(…)
Create rotation matrix around X axis.
| Parameter | Typ | Beschreibung |
|---|---|---|
rotX |
number |
rotation angle in radians |
Rückgabe Mat4: rotation matrix
rotZTransl(rotZ : number, transl : Vec3Serialized.Vec3) : Mat4 base/tealdef/scripts/mat4.d.tl:52
Aufruf: transf.rotZTransl(…)
Create matrix who has rotation around Z and translation
| Parameter | Typ | Beschreibung |
|---|---|---|
rotZ |
number |
rotation angle |
transl |
Vec3Serialized.Vec3 |
translation vector |
Rückgabe Mat4: combined matrix
Im Basisspiel verwendet: 315-mal in 29 Dateien
base/content/depots/rail/rail/rail_depot.script.lua:360
base/content/depots/water/water/water_depot.script.lua:419
base/content/depots/water/water/water_maint_station.script.lua:311
base/content/infrastructure/traffic_light/traffic_light/trafficlightutil.lua:188
base/content/landmarks/hq/hq/headquarter.script.tl:427
base/content/landmarks/landmark_util_serialized.tl:413
… und 23 weitere Dateien.
rotZYXTransl(rot : Vec3Serialized.Vec3, transl : Vec3Serialized.Vec3) : Mat4 base/tealdef/scripts/mat4.d.tl:57
Aufruf: transf.rotZYXTransl(…)
Create matrix for ZYX rotations and translation.
| Parameter | Typ | Beschreibung |
|---|---|---|
rot |
Vec3Serialized.Vec3 |
rotation vector (x is rotZ, y is rotY, z is rotX) and performed in this order |
transl |
Vec3Serialized.Vec3 |
translation vector |
Rückgabe Mat4: combined matrix
Im Basisspiel verwendet: 34-mal in 8 Dateien
base/content/landmarks/hq/hq/headquarter.script.tl:337
base/content/scripts/scripts/construction/modulesutil.lua:188
base/content/stations/air/air/airfield.script.lua:261
base/content/stations/air/air/airport.script.lua:172
transf = transf.rotZYXTransl(vec3.degToRad(0, 0, 0), vec3.new(airportLimitEnd - 5, runway1YCoord, 0 )),
base/content/stations/air/air/heliport/heliport.script.lua:414
base/content/stations/rail/rail/modular_station/modular_station.script.lua:534
… und 2 weitere Dateien.
rotZYTransl(rot : Vec3Serialized.Vec3, transl : Vec3Serialized.Vec3) : Mat4 base/tealdef/scripts/mat4.d.tl:62
Aufruf: transf.rotZYTransl(…)
Create a matrix for ZY rotations and translation.
| Parameter | Typ | Beschreibung |
|---|---|---|
rot |
Vec3Serialized.Vec3 |
rotation vector (x is rotZ, y is rotY, z is unused) and performed in this order |
transl |
Vec3Serialized.Vec3 |
translation vector |
Rückgabe Mat4: combined matrix
rotYCntTransl(rotY : number, cnt : Vec3Serialized.Vec3, transl : Vec3Serialized.Vec3) : Mat4 base/tealdef/scripts/mat4.d.tl:68
Aufruf: transf.rotYCntTransl(…)
Create matrix for rotation around Y with a center specified and a translation.
| Parameter | Typ | Beschreibung |
|---|---|---|
rotY |
number |
rotation angle |
cnt |
Vec3Serialized.Vec3 |
center point |
transl |
Vec3Serialized.Vec3 |
translation vector |
Rückgabe Mat4: combined matrix
rotZY(rot : Vec3Serialized.Vec3) : Mat4 base/tealdef/scripts/mat4.d.tl:73
Aufruf: transf.rotZY(…)
Create a matrix for ZY rotations.
| Parameter | Typ | Beschreibung |
|---|---|---|
rot |
Vec3Serialized.Vec3 |
rotation vector (x is rotZ, y is rotY, z is unused) and performed in this order |
Rückgabe Mat4: rotation matrix
scaleRotZTransl(scale : number, rotZ : number, transl : Vec3Serialized.Vec3) : Mat4 base/tealdef/scripts/mat4.d.tl:80
Aufruf: transf.scaleRotZTransl(…)
Create matrix for (homogenous) scaling, rotation around Z, and translation.
| Parameter | Typ | Beschreibung |
|---|---|---|
scale |
number |
scale factor |
rotZ |
number |
rotation angle |
transl |
Vec3Serialized.Vec3 |
translation vector |
Rückgabe Mat4: combined matrix
Im Basisspiel verwendet: 93-mal in 20 Dateien
base/content/game_mechanics/game_mechanics/celebrations/gui/celebration.css.lua:16
base/content/game_mechanics/game_mechanics/company/company.css.lua:36
base/content/game_mechanics/game_mechanics/finance/finances.css.lua:41
base/content/game_mechanics/game_mechanics/notifications/gui/notifications.css.lua:52
base/content/gui/gui/construction/construction.css.lua:35
base/content/gui/gui/context_helper/context_helper.css.lua:19
… und 14 weitere Dateien.
scaleXYZRotZTransl(scale : Vec3Serialized.Vec3, rotZ : number, transl : Vec3Serialized.Vec3) : Mat4 base/tealdef/scripts/mat4.d.tl:86
Aufruf: transf.scaleXYZRotZTransl(…)
Create matrix for (inhomogenous) scaling, rotation around Z, and translation.
| Parameter | Typ | Beschreibung |
|---|---|---|
scale |
Vec3Serialized.Vec3 |
scale vector |
rotZ |
number |
rotation angle |
transl |
Vec3Serialized.Vec3 |
translation vector |
Rückgabe Mat4: combined matrix
Im Basisspiel verwendet: 5-mal in 3 Dateien
base/content/infrastructure/bridge/bridge/bridgeutil.lua:223
base/content/infrastructure/bridge/bridge/bridgeutil2.lua:234
base/content/scripts/scripts/construction/constructionutil.lua:487
scaleRotZYXTransl(scale : Vec3Serialized.Vec3, rot : Vec3Serialized.Vec3, transl : Vec3Serialized.Vec3) : Mat4 base/tealdef/scripts/mat4.d.tl:92
Aufruf: transf.scaleRotZYXTransl(…)
Create matrix for (inhomogenous) scaling, ZYX rotations and translation.
| Parameter | Typ | Beschreibung |
|---|---|---|
scale |
Vec3Serialized.Vec3 |
scale vector |
rot |
Vec3Serialized.Vec3 |
rotation vector (x is rotZ, y is rotY, z is rotX) and performed in this order |
transl |
Vec3Serialized.Vec3 |
translation vector |
Rückgabe Mat4: combined matrix
getTransl(m : Mat4) : Vec3Serialized.Vec3 base/tealdef/scripts/mat4.d.tl:97
Aufruf: transf.getTransl(…)
Extract translation vector from matrix.
| Parameter | Typ | Beschreibung |
|---|---|---|
m |
Mat4 |
matrix |
Rückgabe Vec3Serialized.Vec3: translation vector
print(v : Mat4) : string base/tealdef/scripts/mat4.d.tl:102
Aufruf: transf.print(…)
Convert matrix to a string representation.
| Parameter | Typ | Beschreibung |
|---|---|---|
v |
Mat4 |
matrix |
Rückgabe string: string representation
Mat4Serialized.Mat4¶
record base/tealdef/scripts/mat4.d.tl:4
record Mat4 is {number}
16 entries, column major
Im Basisspiel verwendet: 48-mal in 5 Dateien
base/content/landmarks/hq/hq/headquarter.script.tl:344
result.addAlignmentColliderAndGroundTexture = function(cellSize : {Vec2Serialized.Vec2}, fenceCellSize : {Vec2Serialized.Vec2}, transf2 : Mat4Serialized.Mat4)
base/content/landmarks/hq/hq/headquarter_addon.script.tl:7
function data.updateFn(captureParams : table, result : HeadquarterUtilSerialized.HeadquarterConstructionResult, _transform : Mat4Serialized.Mat4, tag : string,
base/content/scripts/scripts/construction/construction.script.tl:85
local function addModel(name : string, mtransf : Mat4Serialized.Mat4, tag2 : string, models : {ConstructionUtilSerialized.TransformedModel}) : integer
base/content/scripts/scripts/mat4.tl:6
mat4_util.new = function(col1 : Vec4Serialized.Vec4, col2 : Vec4Serialized.Vec4, col3 : Vec4Serialized.Vec4, col4 : Vec4Serialized.Vec4) : Mat4Serialized.Mat4
base/content/stations/air/air/heliport/modules.script.tl:7
Funktionen
metamethod __add(m1 : Mat4, m2 : Mat4) : Mat4 base/tealdef/scripts/mat4.d.tl:5
Hinweise
Elementweise Summe m1 + m2.
Rückgabe Mat4