struct Eagle::Vec4

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(x : Number, y : Number, z : Number, w : Number) #

Creates a vector from four numbers. The shorthand is v4(x, y, z, w).


def self.new #

Creates (0, 0, 0, 0).


def self.zero : Vec4 #

Returns (0, 0, 0, 0).


Instance Method Detail

def *(s : Number) : Vec4 #

Scales every component.


def +(o : Vec4) : Vec4 #

Component-wise sum.


def -(o : Vec4) : Vec4 #

Component-wise difference.


def /(s : Number) : Vec4 #

Divides every component.


def ==(o : Vec4) : Bool #

Exact equality.


def dot(o : Vec4) : Float32 #

Dot product of all four components.


def homogenized : Vec3 #

Divides x, y and z by w: the perspective divide after a projection matrix.


def inspect(io : IO) : Nil #
Description copied from struct Struct

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)"

def length : Float32 #

Length of all four components.


def to_a #

Returns [x, y, z, w].


def to_s(io : IO) : Nil #
Description copied from struct Struct

Same as #inspect(io).


def w : Float32 #

Fourth component: 1 for points, 0 for directions.


def w=(w : Float32) #

Fourth component: 1 for points, 0 for directions.


def x : Float32 #

First component.


def x=(x : Float32) #

First component.


def xy : Vec2 #

The first two components.


def xyz : Vec3 #

The first three components.


def y : Float32 #

Second component.


def y=(y : Float32) #

Second component.


def z : Float32 #

Third component.


def z=(z : Float32) #

Third component.