Raylib Vector3 vs my own Vector3 implementation

I am using integers for my project, therefor I implemented a struct in my math.zig

math.zig:

pub const Vec3i = struct {
    x: i32,
    y: i32,
    z: i32,

    pub fn init(x: i32, y: i32, z: i32) Vec3i {
        return Vec3i {
            .x = x,
            .y = y,
            .z = z,
        };
    }

    pub fn dot(self: Vec3i, other: Vec3i) i32 {
        return self.x * other.x + self.y * other.y + self.z * other.z;
    }

    pub fn toVec3(self: Vec3i) rl.Vector3 {
        return @as(rl.Vector3, self);
    }
};

main.zig:

const rl = @import("raylib");
const math = @import("math.zig");
...
    const cube_pos = math.Vec3i.init(0, 0, 0);
    const ray_cube = math.Vec3i.toVec3(cube_pos);
...
            rl.drawCube(ray_cube, 2, 2, 2, rl.Color.red);

The compiler says that it still needs the rl.Vector3. I tried to cast the struct’s elements individually like:

    pub fn toVec3(self: Vec3i) rl.Vector3 {
        return rl.Vector3{
            .x = rl.Vector3.x,
            .y = rl.Vector3.y,
            .z = rl.Vector3.z,
        };
    }

But compiled to unused function parameter error.

What is it I’m missing? I searched for this unused function parameter and found a comment from Andrew K. that it’s a built in friction for the programmers, but honestly it’s a bit high level for me to understand yet.

The unused function parameter is self.
rl.Vector3 has f32 as it’s component type.

return rl.Vector3 {
    .x = @floatFromInt(self.x)
    .y = @floatFromInt(self.y)
    .z = @floatFromInt(self.z)
}
1 Like

Ah now I see, I never used self… Thanks.