summaryrefslogtreecommitdiff
path: root/src/vec.zig
blob: b98f9f400e280a6e318ebb896992f3814406b0c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
pub const Vec = @Vector(3, f32);

pub fn init(x: f32, y: f32, z: f32) Vec {
    return @Vector(3, f32){ x, y, z };
}

pub fn scalar(x: f32) Vec {
    return @splat(3, x);
}

pub fn unitVec(v: Vec) Vec {
    return v / scalar(length(v));
}

pub fn lengthSquared(v: Vec) f32 {
    return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
}

pub fn length(v: Vec) f32 {
    return @sqrt(lengthSquared(v));
}

pub fn dot(x: Vec, y: Vec) f32 {
    return x[0] * y[0] + x[1] * y[1] + x[2] * y[2];
}