Zum Inhalt

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

-- from base/content/landmarks/hq/hq/headquarter.script.tl
coll.transf = mat4.mul(transf2, mat4.transl(vec3.new(0, 0, 14)))
-- from base/content/landmarks/hq/hq/headquarter_addon.script.tl
transf2 = mat4.mul(transf2, mat4.rotZ((params.modules[slotId].variant or 0) * math.pi / 2))

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

Beispiel

-- from base/content/landmarks/landmark_util_serialized.tl
lane.transf = mat4.identity()
Im Basisspiel verwendet: 29-mal in 12 Dateien

base/content/depots/rail/rail/rail_depot.script.lua:359

local transform = transf.identity
base/content/industries/industryutil.lua:104
lane.transf = transf.identity()
base/content/landmarks/landmark_util_serialized.tl:41
lane.transf = mat4.identity()
base/content/stations/air/air/airfield/airfield_modules.script.lua:219
local transform = transf.identity()
base/content/stations/air/air/airport/airport_modules.script.lua:337
local transform = transf.identity()
base/content/stations/air/air/helipad/helipad.script.lua:152
lane.transf = transf.identity()
… 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

-- from base/content/landmarks/hq/hq/headquarter.script.tl
coll.transf = mat4.mul(transf2, mat4.transl(vec3.new(0, 0, 14)))
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
transf = transf.mul(fieldTransf, transf.scaleRotZTransl(
base/content/industries/fishing_grounds/fishing_grounds/modules.script.lua:28
transform = transf.mul(transform, transf.rotZ( math.rad(randomRotation[rnd])))
base/content/industries/oil_well/oil_well/modules.script.lua:20
transform = transf.mul(transform, transf.rotZ( math.rad(90)))
base/content/infrastructure/traffic_light/traffic_light/trafficlightutil.lua:77
local posRight = transf.mul(args.position, transf.transl(vec3.new(0, -wRight, 0)))
base/content/infrastructure/tunnel/tunnel/tunnel.script.lua:143
result.transf = transf.mul(transl, result.transf)
… 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

modulesutil.mul = transf.gemv
base/content/stations/air/air/airport/airport_modules.script.lua:16
local center = transf.gemv(transform, vec4.new(20.0, 0.0, -1.0, 1.0))
base/content/stations/street/street/modular_street_station/modules.script.lua:105
local tng = vec4.toArray(transf.gemv(transform, vec4.new(0.0, -20.0, 0.0, 0.0)))
base/content/stations/water/water/modules.script.lua:844
local entryGlob = transf.gemv(transform, entry)

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
transf = transf.transl(vec3.new(0, -7, 0)),
base/content/depots/road/road/road_depot/road_depot.script.lua:216
transf = transf.transl(vec3.new(0, -30.0, 0)),
base/content/depots/road/road/road_maint_station.script.lua:259
transf = transf.transl(vec3.new(0, -depth-4, 0)),
base/content/depots/road/road/tram_depot/tram_depot.script.lua:247
transf = transf.transl(vec3.new(-1.64813, -35.4153, 0)),
base/content/depots/water/water/water_depot.script.lua:407
transf = transf.transl(vec3.new(0, -30, 0)),
… 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

return { times = { 0 }, transfs = { transf.scale(vec3.new(1,1,1)) }, interpolation = "NEAREST" }
base/content/gui/gui/construction/construction.css.lua:415
transform = transf.scale(vec3.new(1.0, 1.0, 1.0)),
base/content/gui/gui/main/builtin.css.lua:38
transform = transf.scale(vec3.new(1,1,1)),
base/content/gui/gui/main/hud_icon_master.css.lua:19
transform = transf.scale(vec3.new(0.1, 0.1, 0.1)),
base/content/gui/gui/main/tile_list_react_util.css.lua:118
transform = transf.scale(vec3.new(1.0, 1.0, 1.0)),
base/content/gui/gui/menu/main_menu.css.lua:245
transform = transf.scale(vec3.new(1.0, 1.0, 1.0)),
… 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

local animation = generateRotateAnimation(maxAngle, transf.rotZ)
base/content/gui/gui/main/tile_list_react_util.css.lua:22
transform = transf.rotZ(i * angle),
base/content/gui/gui/menu/main_menu.css.lua:72
transform = transf.rotZ(i * angle),
base/content/industries/fishing_grounds/fishing_grounds/modules.script.lua:28
transform = transf.mul(transform, transf.rotZ( math.rad(randomRotation[rnd])))
base/content/industries/oil_well/oil_well/modules.script.lua:20
transform = transf.mul(transform, transf.rotZ( math.rad(90)))
base/content/infrastructure/tunnel/tunnel/tunnel.script.lua:158
local rot = transf.rotZ(math.pi)
… 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

Im Basisspiel verwendet: 2-mal in 2 Dateien

base/content/base/base/metadataanimationutil.lua:296

local animation = generateRotateAnimation(maxAngle, transf.rotY)
base/content/scripts/scripts/construction/constructionutil.lua:19
transf.rotY(params.constructOpt78 and params.constructOpt78 or 0)

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

Im Basisspiel verwendet: 7-mal in 2 Dateien

base/content/base/base/metadataanimationutil.lua:323

local animation = generateRotateAnimation(maxAngle, transf.rotX)
base/content/scripts/scripts/construction/constructionutil.lua:18
transf.rotX(params.constructOpt56 and params.constructOpt56 or 0),

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

transform = transf.rotZTransl(4.71238898,vec3.new(-21, 0, 0.00000))
base/content/depots/water/water/water_depot.script.lua:419
transf = transf.rotZTransl(math.pi, vec3.new(0, 0, 0)),
base/content/depots/water/water/water_maint_station.script.lua:311
transf = transf.rotZTransl(math.pi, vec3.new(0, 0, 0)),
base/content/infrastructure/traffic_light/traffic_light/trafficlightutil.lua:188
result[#result + 1] = transf.mul(p, transf.rotZTransl(rot, vec3.new(0, o, 0)))
base/content/landmarks/hq/hq/headquarter.script.tl:427
addFence(mat4.rotZTransl(0, vec3.new((i + 0.5) * GridSize.x, j * GridSize.y, 0)))
base/content/landmarks/landmark_util_serialized.tl:413
transf = mat4.rotZTransl(math.pi, vec3.new(0, 10, 0)),
… 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

transf = mat4.rotZYXTransl(vec3.degToRad(orientation and orientation * 90 or 0, 0, 0), center),
base/content/scripts/scripts/construction/modulesutil.lua:188
transf = transf.rotZYXTransl(rot, pos),
base/content/stations/air/air/airfield.script.lua:261
transf = transf.rotZYXTransl(vec3.degToRad(0.0, 0.0, 0.0),  vec3.new( 140, 0, 0))
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
transf = transf.rotZYXTransl(vec3.degToRad(0.0, 0.0, 0.0), vec3.new(-26.8, 37.6, 0)),
base/content/stations/rail/rail/modular_station/modular_station.script.lua:534
transf = transf.rotZYXTransl(vec3.degToRad(0.0, 0.0, 0.0), vec3.new(i * platformWidth + offset, j * platformLength, 0)),
… 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

transform = transf.scaleRotZTransl(1.0, 0, vec3.new(0.0, -200.0, 0.0)),
base/content/game_mechanics/game_mechanics/company/company.css.lua:36
transform = transf.scaleRotZTransl(1.0, 0, vec3.new(0.0, 200.0, 0.0)),
base/content/game_mechanics/game_mechanics/finance/finances.css.lua:41
transform = transf.scaleRotZTransl(1.0, 0, vec3.new(0.0, 200.0, 0.0)),
base/content/game_mechanics/game_mechanics/notifications/gui/notifications.css.lua:52
transform = transf.scaleRotZTransl(1.0, 0, vec3.new(0.0, -100.0, 0.0)),
base/content/gui/gui/construction/construction.css.lua:35
transform = transf.scaleRotZTransl(0.1, 0, vec3.new(0.0, 300.0, 0.0)),
base/content/gui/gui/context_helper/context_helper.css.lua:19
transform = transf.scaleRotZTransl(0.1, 0, vec3.new(0.0, 0.0, 0.0)),
… 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

local modelTransf = transf.scaleXYZRotZTransl(scaleVec, .0, posVec)
base/content/infrastructure/bridge/bridge/bridgeutil2.lua:234
local modelTransf = transf.scaleXYZRotZTransl(scaleVec, .0, posVec)
base/content/scripts/scripts/construction/constructionutil.lua:487
transf = transf.scaleXYZRotZTransl(vec3.new(remainder, 1, 1), vec3.xyAngle(fenceVector) + (angle or 0), fence_point),

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
function data.updateFn(captureParams : table, result : HeadquarterUtilSerialized.HeadquarterConstructionResult, transform : Mat4Serialized.Mat4, tag : string, s

Funktionen

metamethod __add(m1 : Mat4, m2 : Mat4) : Mat4 base/tealdef/scripts/mat4.d.tl:5

Hinweise

Elementweise Summe m1 + m2.

Rückgabe Mat4

metamethod __sub(m1 : Mat4, m2 : Mat4) : Mat4 base/tealdef/scripts/mat4.d.tl:6

Hinweise

Elementweise Differenz m1 - m2.

Rückgabe Mat4

metamethod __mul(m1 : Mat4, m2 : Mat4) : Mat4 base/tealdef/scripts/mat4.d.tl:7

Hinweise

Matrixprodukt m1 * m2. Auf einen Punkt angewendet wirkt erst m2, dann m1 (Spaltenvektoren).

Rückgabe Mat4