Skip to content

Instantly share code, notes, and snippets.

@koljakube
Created August 21, 2020 12:24
Show Gist options
  • Save koljakube/2712be82e38561c56f358bccbd21b1e6 to your computer and use it in GitHub Desktop.
Save koljakube/2712be82e38561c56f358bccbd21b1e6 to your computer and use it in GitHub Desktop.
const Vec3(T) = packed union { Array: [3]T }
pub fn cPtr(self: *Self) [*c]f32 {
return @ptrCast([*c]f32, @alignCast(@alignOf([*c]f32), self));
}
pub fn constCPtr(self: *const Self) [*c]const f32 {
return @ptrCast([*c]const f32, @alignCast(@alignOf([*c]const f32), self));
}
pub const translate = @ptrCast(fn ([*c][4]f32, [*c]const f32) callconv(.C) void, cc.glmc_translate);
pub fn Mat4(comptime T: anytype) type {
return packed union {
const Self = @This();
const Dimension = 4;
const ValueType = T;
const Vec3Type = Vec3(T);
const Vec4Type = Vec4(T);
Array: [Dimension * Dimension]T,
Columns: [Dimension]Vec4Type,
Vectors: [Dimension]std.meta.Vector(Dimension, T),
pub fn translate(self: *Self, v: Vec3Type) void {
// @compileLog(@typeName(@TypeOf(cglm_call.translate)));
// @compileLog(@typeInfo(@TypeOf(&v)).Pointer.is_const);
translate(self.cPtr(), @intToPtr([*c]const f32, @ptrToInt(Vec3Type.constCPtr(&v))));
}
pub inline fn cPtr(self: *Self) [*c][4]T {
return @ptrCast([*c][4]T, @alignCast(@alignOf([*c][4]T), self));
}
}
}
/src/math/mat4.zig:60:46: error: cast discards const qualifier
cglm_call.translate(self.cPtr(), @intToPtr([*c]const f32, @ptrToInt(Vec3Type.constCPtr(&v))));
^
./src/math/mat4.zig:60:32: note: referenced here
cglm_call.translate(self.cPtr(), @intToPtr([*c]const f32, @ptrToInt(Vec3Type.constCPtr(&v))));
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment