struct
Eagle::Vec4
- Eagle::Vec4
- Struct
- Value
- Object
Overview
A 4-component vector, mostly used for homogeneous coordinates and shader uniforms.
Game code rarely needs it directly. It shows up when multiplying by a Mat4, and
Color#to_vec4 produces one for passing colors to shaders.
Defined in:
eagle/math/vec3.crConstructors
-
.new(x : Number, y : Number, z : Number, w : Number)
Creates a vector from four numbers.
-
.new
Creates
(0, 0, 0, 0). -
.zero : Vec4
Returns
(0, 0, 0, 0).
Instance Method Summary
-
#*(s : Number) : Vec4
Scales every component.
-
#+(o : Vec4) : Vec4
Component-wise sum.
-
#-(o : Vec4) : Vec4
Component-wise difference.
-
#/(s : Number) : Vec4
Divides every component.
-
#==(o : Vec4) : Bool
Exact equality.
-
#dot(o : Vec4) : Float32
Dot product of all four components.
-
#homogenized : Vec3
Divides x, y and z by w: the perspective divide after a projection matrix.
-
#inspect(io : IO) : Nil
Appends this struct's name and instance variables names and values to the given IO.
-
#length : Float32
Length of all four components.
-
#to_a
Returns
[x, y, z, w]. -
#to_s(io : IO) : Nil
Same as
#inspect(io). -
#w : Float32
Fourth component: 1 for points, 0 for directions.
-
#w=(w : Float32)
Fourth component: 1 for points, 0 for directions.
-
#x : Float32
First component.
-
#x=(x : Float32)
First component.
-
#xy : Vec2
The first two components.
-
#xyz : Vec3
The first three components.
-
#y : Float32
Second component.
-
#y=(y : Float32)
Second component.
-
#z : Float32
Third component.
-
#z=(z : Float32)
Third component.
Constructor Detail
Creates a vector from four numbers. The shorthand is v4(x, y, z, w).
Instance Method Detail
Appends this struct's name and instance variables names and values to the given IO.
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
p1 = Point.new 1, 2
p1.to_s # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"