vec3¶
Source: base/tealdef/scripts/vec3.d.tl
Notes
Types of the plain-Lua 3D vector library /scripts/vec3.tl (Vec3Serialized): vectors are ordinary
tables {x = ..., y = ..., z = ...} with +, -, * (number times vector) and / (vector by number).
Construction scripts use it together with /scripts/mat4.tl.
Load it with local vec3 = ug_require "/scripts/vec3.tl" as Vec3Serialized.
Vec3iSerialized¶
record global base/tealdef/scripts/vec3.d.tl:3
global record Vec3iSerialized
Notes
Namespace of the integer 3D vector type Vec3i.
Vec3iSerialized.Vec3i¶
record base/tealdef/scripts/vec3.d.tl:4
record Vec3i
Notes
3D vector with integer components, as a plain table {x = ..., y = ..., z = ...}.
Fields
| Name | Type | Description |
|---|---|---|
x |
integer |
X component. |
y |
integer |
Y component. |
z |
integer |
Z component (height in world coordinates). |
Vec3Serialized¶
record global base/tealdef/scripts/vec3.d.tl:11
global record Vec3Serialized
Load: local vec3 = require "/scripts/vec3.tl"
Notes
The 3D vector library returned by ug_require "/scripts/vec3.tl", and the namespace of its Vec3 type.
Functions
new(x : number, y : number, z : number) : Vec3 base/tealdef/scripts/vec3.d.tl:25
Call as vec3.new
Notes
Creates a 3D vector with arithmetic operators attached.
| Parameter | Type | Description |
|---|---|---|
x |
number |
X component. |
y |
number |
Y component. |
z |
number |
Z component. |
Returns Vec3: The new vector.
Example
Used in the base game: 1051 times in 85 files
base/content/industries/fieldutil.lua:265
base/content/industries/industryutil.lua:334
local length = vec3.length(vec3.new( curve[2][1] - curve[1][1], curve[2][2] - curve[1][2], curve[2][3] - curve[1][3] ))
base/content/landmarks/landmark_util_serialized.tl:156
base/content/warehouses/warehouses/warehouse.script.lua:109
base/content/warehouses/warehouses/modules.script.lua:28
base/content/landmarks/hq/hq/headquarter.script.tl:332
… and 79 more files.
degToRad(dx : number, dy : number, dz : number) : Vec3 base/tealdef/scripts/vec3.d.tl:26
Call as vec3.degToRad
Notes
Converts three angles from degrees to radians and returns them as a vector.
| Parameter | Type | Description |
|---|---|---|
dx |
number |
Angle in degrees, stored in x. |
dy |
number |
Angle in degrees, stored in y. |
dz |
number |
Angle in degrees, stored in z. |
Returns Vec3: Vector of the angles in radians.
Used in the base game: 34 times in 7 files
base/content/warehouses/warehouses/warehouse.script.lua:233
base/content/warehouses/warehouses/modules.script.lua:29
base/content/landmarks/hq/hq/headquarter.script.tl:337
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)),
base/content/stations/air/air/airfield.script.lua:261
base/content/stations/air/air/airport.script.lua:172
… and 1 more files.
add(v1 : Vec3, v2 : Vec3) : Vec3 base/tealdef/scripts/vec3.d.tl:28
Call as vec3.add
Notes
Returns v1 + v2.
Returns Vec3
Used in the base game: 14 times in 5 files
base/content/infrastructure/street_construction/street_construction/street_constructions.script.lua:47
base/content/mission/mission/mission_task_util.tl:194
base/content/stations/rail/rail/modular_station/modular_station.script.lua:692
base/content/stations/water/water/modules.script.lua:894
base/content/scripts/scripts/construction/constructionutil.lua:475
sub(v1 : Vec3, v2 : Vec3) : Vec3 base/tealdef/scripts/vec3.d.tl:29
Call as vec3.sub
Notes
Returns v1 - v2.
Returns Vec3
Used in the base game: 7 times in 5 files
base/content/infrastructure/street_construction/street_construction/street_constructions.script.lua:49
base/content/mission/mission/mission_task_util.tl:224
base/content/stations/rail/rail/modular_station/modular_station.script.lua:684
base/content/scripts/scripts/construction/constructionutil.lua:475
local fence_point = vec3.sub(vec3.add(vec3.new(xStart, yStart, zStart), vec3.mul(build_fence, fenceVectorSegment)), vec3.mul(0.5, fenceVectorSegment))
base/content/scripts/scripts/construction/street_util_serialized.tl:23
mul(f : number, v : Vec3) : Vec3 base/tealdef/scripts/vec3.d.tl:30
Call as vec3.mul
Notes
Returns the vector v scaled by the number f.
Returns Vec3
Used in the base game: 20 times in 6 files
base/content/infrastructure/street_construction/street_construction/street_constructions.script.lua:43
base/content/mission/mission/mission_task_util.tl:194
base/content/scripts/scripts/construction/constructionutil.lua:475
local fence_point = vec3.sub(vec3.add(vec3.new(xStart, yStart, zStart), vec3.mul(build_fence, fenceVectorSegment)), vec3.mul(0.5, fenceVectorSegment))
base/content/scripts/scripts/construction/laneutil.lua:50
base/content/scripts/scripts/construction/street_util_serialized.tl:38
dlcs/urbangames_deluxe_upgrade_pack/content/animal/animal/animal.script.lua:15
div(v : Vec3, d : number) : Vec3 base/tealdef/scripts/vec3.d.tl:31
Call as vec3.div
Notes
Returns the vector v with each component divided by d.
Returns Vec3
dot(v1 : Vec3, v2 : Vec3) : number base/tealdef/scripts/vec3.d.tl:33
Call as vec3.dot
Notes
Dot product v1.x * v2.x + v1.y * v2.y + v1.z * v2.z.
Returns number
cross(v1 : Vec3, v2 : Vec3) : Vec3 base/tealdef/scripts/vec3.d.tl:34
Call as vec3.cross
Notes
Cross product v1 × v2 (right-handed).
Returns Vec3
length(v : Vec3) : number base/tealdef/scripts/vec3.d.tl:39
Call as vec3.length
Get the length (magnitude) of the vector.
| Parameter | Type | Description |
|---|---|---|
v |
Vec3 |
vector |
Returns number: length of the vector
Used in the base game: 3 times in 3 files
base/content/industries/industryutil.lua:334
local length = vec3.length(vec3.new( curve[2][1] - curve[1][1], curve[2][2] - curve[1][2], curve[2][3] - curve[1][3] ))
base/content/infrastructure/street_construction/street_construction/street_constructions.script.lua:22
base/content/scripts/scripts/construction/constructionutil.lua:466
distance(v1 : Vec3, v2 : Vec3) : number base/tealdef/scripts/vec3.d.tl:44
Call as vec3.distance
Get the distance between two vectors.
| Parameter | Type | Description |
|---|---|---|
v1 |
Vec3 |
first vector |
v2 |
Vec3 |
second vector |
Returns number: distance between the vectors
Used in the base game: 7 times in 5 files
base/content/industries/fieldutil.lua:269
base/content/infrastructure/street_construction/street_construction/street_constructions.script.lua:38
base/content/mission/mission/mission_task_util.tl:197
base/content/scripts/scripts/construction/laneutil.lua:46
local length = vec3.distance(vec3.new(points[j+0][1], points[j+0][2], points[j+0][3]), vec3.new(points[j+3][1], points[j+3][2],points[j+3][3]))
base/content/scripts/scripts/construction/street_util_serialized.tl:36
distance2(v1 : Vec3, v2 : Vec3) : number base/tealdef/scripts/vec3.d.tl:49
Call as vec3.distance2
Get the squared distance between two vectors.
| Parameter | Type | Description |
|---|---|---|
v1 |
Vec3 |
first vector |
v2 |
Vec3 |
second vector |
Returns number: squared distance between the vectors
normalize(v : Vec3) : Vec3 base/tealdef/scripts/vec3.d.tl:54
Call as vec3.normalize
Normalize the vector (make it unit length).
| Parameter | Type | Description |
|---|---|---|
v |
Vec3 |
vector to normalize |
Returns Vec3: normalized vector
Used in the base game: 7 times in 3 files
base/content/infrastructure/street_construction/street_construction/street_constructions.script.lua:35
base/content/scripts/scripts/construction/laneutil.lua:44
base/content/scripts/scripts/construction/street_util_serialized.tl:37
normalizeWithFallback(v : Vec3, f : Vec3) : Vec3 base/tealdef/scripts/vec3.d.tl:59
Call as vec3.normalizeWithFallback
Normalize the vector with a fallback if zero length.
| Parameter | Type | Description |
|---|---|---|
v |
Vec3 |
vector to normalize |
f |
Vec3 |
fallback vector |
Returns Vec3: normalized vector or fallback
angleUnit(v1 : Vec3, v2 : Vec3) : number base/tealdef/scripts/vec3.d.tl:65
Call as vec3.angleUnit
Get the angle between two unit vectors.
| Parameter | Type | Description |
|---|---|---|
v1 |
Vec3 |
first unit vector |
v2 |
Vec3 |
second unit vector |
Returns number: angle in radians
Used in the base game: 3 times in 3 files
base/content/infrastructure/street_construction/street_construction/street_constructions.script.lua:39
base/content/scripts/scripts/construction/laneutil.lua:47
base/content/scripts/scripts/construction/street_util_serialized.tl:59
angle(v1 : Vec3, v2 : Vec3) : number base/tealdef/scripts/vec3.d.tl:70
Call as vec3.angle
Get the angle between two vectors.
| Parameter | Type | Description |
|---|---|---|
v1 |
Vec3 |
first vector |
v2 |
Vec3 |
second vector |
Returns number: angle in radians
xyAngle(v : Vec3) : number base/tealdef/scripts/vec3.d.tl:74
Call as vec3.xyAngle
Get the angle in the XY plane.
| Parameter | Type | Description |
|---|---|---|
v |
Vec3 |
vector |
Returns number: angle in radians
toArray(v : Vec3) : Table3 base/tealdef/scripts/vec3.d.tl:79
Call as vec3.toArray
Convert vector to an array of three numbers.
| Parameter | Type | Description |
|---|---|---|
v |
Vec3 |
vector |
Returns Table3: array with x, y, z components
fromArray(t : Table3) : Vec3 base/tealdef/scripts/vec3.d.tl:83
Call as vec3.fromArray
Create vector from an array of three numbers.
| Parameter | Type | Description |
|---|---|---|
t |
Table3 |
array with x, y, z components |
Returns Vec3: vector
print(v : Vec3) : string base/tealdef/scripts/vec3.d.tl:88
Call as vec3.print
Convert vector to a string representation.
| Parameter | Type | Description |
|---|---|---|
v |
Vec3 |
vector |
Returns string: string representation
Vec3Serialized.Table3¶
record base/tealdef/scripts/vec3.d.tl:12
record Table3 is {number}
of lenght 3
Used in the base game: 2 times in 1 file
base/content/scripts/scripts/vec3.tl:95
Vec3Serialized.Vec3¶
record base/tealdef/scripts/vec3.d.tl:14
record Vec3
Notes
3D vector as a plain table {x = ..., y = ..., z = ...}. Vectors made by new (and by the operators)
carry a metatable, so v1 + v2, v1 - v2, f * v and v / d work.
Used in the base game: 100 times in 7 files
base/content/landmarks/hq/hq/headquarter.script.tl:314
base/content/mission/mission/mission_task_util.tl:159
base/content/scripts/scripts/vec3.tl:3
base/content/scripts/scripts/mat4.tl:94
base/content/scripts/scripts/construction/street_util_serialized.tl:19
base/content/scripts/scripts/construction/collider_util_serialized.tl:6
… and 1 more files.
Fields
| Name | Type | Description |
|---|---|---|
x |
number |
X component. |
y |
number |
Y component. |
z |
number |
Z component (up in world and model coordinates). |
Functions
metamethod __add(v1 : Vec3, v2 : Vec3) : Vec3 base/tealdef/scripts/vec3.d.tl:19
Notes
Component-wise sum v1 + v2.
Returns Vec3
metamethod __sub(v1 : Vec3, v2 : Vec3) : Vec3 base/tealdef/scripts/vec3.d.tl:20
Notes
Component-wise difference v1 - v2.
Returns Vec3