Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/foundations/math/matrix.zig
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ pub inline fn rotationX(angle: f32) matrix {

pub inline fn rotationY(angle: f32) matrix {
return mc(.{
@cos(angle), 0, @sin(angle), 0,
0, 1, 0, 0,
-@sin(angle), 0, @cos(angle), 0,
0, 0, 0, 1,
@cos(angle), 0, -@sin(angle), 0,
0, 1, 0, 0,
@sin(angle), 0, @cos(angle), 0,
0, 0, 0, 1,
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/foundations/object/object_circle/ObjectCircle.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ fn data() struct { positions: [num_vertices][3]f32, indices: [num_indices]u32 }
while (i < num_vertices) : (i += 1) {
if (i > 2) {
// Complete circle every with previous index and origin
indices[indices_index] = 0;
indices_index += 1;
indices[indices_index] = last_index;
indices_index += 1;
indices[indices_index] = 0;
indices_index += 1;
}
p[i] = current_vector;
last_index += 1;
Expand Down
43 changes: 25 additions & 18 deletions src/foundations/object/object_cube/ObjectCube.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,59 @@ const Cube = @This();

pub const default_positions: [36][3]f32 = .{
// z pos
.{ -1, -1, 1 },
.{ -1, 1, 1 },

.{ 1, -1, 1 },
.{ -1, 1, 1 },
.{ 1, 1, 1 },
.{ -1, -1, 1 },

.{ 1, -1, 1 },
.{ 1, 1, 1 },
.{ -1, 1, 1 },

// z neg
.{ 1, -1, -1 },
.{ 1, 1, -1 },
.{ -1, 1, -1 },
.{ 1, 1, -1 },
.{ 1, -1, -1 },
.{ -1, 1, -1 },

.{ -1, -1, -1 },
.{ -1, 1, -1 },
.{ 1, -1, -1 },

// y pos
.{ 1, 1, -1 },
.{ 1, 1, 1 },
.{ -1, 1, 1 },
.{ 1, 1, 1 },
.{ 1, 1, -1 },
.{ -1, 1, 1 },

.{ -1, 1, -1 },
.{ -1, 1, 1 },
.{ 1, 1, -1 },

// y neg
.{ -1, -1, -1 },
.{ -1, -1, 1 },
.{ 1, -1, -1 },
.{ -1, -1, 1 },
.{ 1, -1, 1 },
.{ 1, -1, -1 },
.{ -1, -1, -1 },

// x pos
.{ 1, -1, -1 },
.{ 1, -1, 1 },
.{ -1, -1, 1 },

// x pos
.{ 1, 1, -1 },
.{ 1, -1, 1 },
.{ 1, 1, 1 },
.{ 1, -1, -1 },

.{ 1, 1, -1 },
.{ 1, 1, 1 },
.{ 1, -1, 1 },

// x neg
.{ -1, 1, -1 },
.{ -1, 1, 1 },
.{ -1, -1, 1 },
.{ -1, 1, 1 },
.{ -1, 1, -1 },
.{ -1, -1, 1 },

.{ -1, -1, -1 },
.{ -1, -1, 1 },
.{ -1, 1, -1 },
};

pub const normals: [36][3]f32 = .{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ fn addIndicesPerSurface(
) usize {
// first surface triangle
indices[offset] = far_corner0;
indices[offset + 1] = shared_1;
indices[offset + 2] = shared_0;
indices[offset + 2] = shared_1;
indices[offset + 1] = shared_0;
// second surface triangle
indices[offset + 3] = far_corner1;
indices[offset + 4] = shared_0;
indices[offset + 5] = shared_1;
indices[offset + 5] = shared_0;
indices[offset + 4] = shared_1;
return offset + 6;
}

Expand Down
6 changes: 3 additions & 3 deletions src/foundations/object/object_quad/ObjectQuad.zig
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ const Quad = @This();

pub const default_deprecated_positions: [6][3]f32 = .{
.{ 1, -1, 0 },
.{ -1, 1, 0 },
.{ -1, -1, 0 },
.{ -1, 1, 0 },

.{ 1, -1, 0 },
.{ 1, 1, 0 },
.{ -1, 1, 0 },
.{ 1, 1, 0 },
};

pub const default_correct_positions: [4][3]f32 = .{
Expand All @@ -23,7 +23,7 @@ pub const default_correct_positions: [4][3]f32 = .{
};

pub const default_correct_indices: [6]u32 = .{
0, 1, 2, 3, 1, 2,
2, 1, 0, 2, 1, 3,
};

pub fn init(
Expand Down
52 changes: 12 additions & 40 deletions src/foundations/object/object_sphere/ObjectSphere.zig
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ fn data() struct { attribute_data: [num_vertices]rhi.attributeData, indices: [nu
var pii: u32 = 1;
while (i < num_triangles) : (i += 1) {
indices[ii] = 0;
indices[ii + 1] = pii + 1;
indices[ii + 2] = pii + 2;
indices[ii + 1] = pii + 2;
indices[ii + 2] = pii + 1;
ii += 3;
pii += 1;
}
indices[ii] = 0;
indices[ii + 1] = pii + 1;
indices[ii + 2] = 2;
indices[ii + 1] = pii + 2;
indices[ii + 2] = 1;
ii += 3;
pii += 2;

Expand Down Expand Up @@ -121,13 +121,13 @@ fn data() struct { attribute_data: [num_vertices]rhi.attributeData, indices: [nu

// Triangle 1
indices[ii] = @intCast(tl);
indices[ii + 1] = @intCast(bl);
indices[ii + 2] = @intCast(br);
indices[ii + 1] = @intCast(br);
indices[ii + 2] = @intCast(bl);

// Triangle 2
indices[ii + 3] = @intCast(tl);
indices[ii + 4] = @intCast(br);
indices[ii + 5] = @intCast(tr);
indices[ii + 4] = @intCast(tr);
indices[ii + 5] = @intCast(br);

ii += 6;
iii += 1;
Expand All @@ -152,14 +152,14 @@ fn data() struct { attribute_data: [num_vertices]rhi.attributeData, indices: [nu
const closer = pii;
while (i < num_triangles) : (i += 1) {
indices[ii + 2] = 1;
indices[ii + 1] = pii + 0;
indices[ii] = pii + 1;
indices[ii + 1] = pii + 1;
indices[ii] = pii + 0;
ii += 3;
pii += 1;
}
indices[ii + 2] = 1;
indices[ii + 1] = pii;
indices[ii] = closer;
indices[ii + 1] = closer;
indices[ii] = pii;
var adi: usize = 0;

while (adi < pi) : (adi += 1) {
Expand All @@ -170,34 +170,6 @@ fn data() struct { attribute_data: [num_vertices]rhi.attributeData, indices: [nu
return .{ .attribute_data = attribute_data, .indices = indices };
}

fn addVertexData(
positions: [num_vertices]math.vector.vec3,
indices: []u32,
attribute_data: []rhi.attributeData,
tr: usize,
br: usize,
tl: usize,
bl: usize,
ii: usize,
) void {
const tr_coordinates = positions[tr];
const br_coordinates = positions[br];
const tl_coordinates = positions[tl];
const bl_coordinates = positions[bl];
attribute_data[tr] = .{ .position = tr_coordinates, .normals = math.vector.normalize(tr_coordinates) };
attribute_data[br] = .{ .position = br_coordinates, .normals = math.vector.normalize(br_coordinates) };
attribute_data[tl] = .{ .position = tl_coordinates, .normals = math.vector.normalize(tl_coordinates) };
attribute_data[bl] = .{ .position = bl_coordinates, .normals = math.vector.normalize(bl_coordinates) };
// Triangle 1
indices[ii] = @intCast(tl);
indices[ii + 1] = @intCast(br);
indices[ii + 2] = @intCast(tr);
// Triangle 2
indices[ii + 3] = @intCast(tl);
indices[ii + 4] = @intCast(bl);
indices[ii + 5] = @intCast(br);
}

const std = @import("std");
const c = @import("../../c.zig").c;
const rhi = @import("../../rhi/rhi.zig");
Expand Down
2 changes: 1 addition & 1 deletion src/foundations/object/object_strip/ObjectStrip.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ pub fn init(
// zig fmt: off
const positions: [3][3]f32 = .{
.{ -1, 0, -1, },
.{ -1, 0, 1, },
.{ 1, 0, 0, },
.{ -1, 0, 1, },
};
// zig fmt: on
var indices: [3]u32 = .{ 0, 1, 2 };
Expand Down
2 changes: 1 addition & 1 deletion src/foundations/object/object_triangle/ObjectTriangle.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const Triangle = @This();

pub const default_positions: [3][3]f32 = .{
.{ -0.025, -0.025, 0 },
.{ 0.025, -0.025, 0 },
.{ 0.0, 0.025, 0 },
.{ 0.025, -0.025, 0 },
};

pub const default_colors: [3][4]f32 = .{
Expand Down
2 changes: 1 addition & 1 deletion src/foundations/rhi/rhi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn init(allocator: std.mem.Allocator) void {
c.glDebugMessageCallback(&messageCallback, null);
c.glClipControl(c.GL_LOWER_LEFT, c.GL_NEGATIVE_ONE_TO_ONE);
c.glEnable(c.GL_DEPTH_TEST);
c.glFrontFace(c.GL_CCW);
c.glFrontFace(c.GL_CW);
c.glEnable(c.GL_CULL_FACE);
c.glClipControl(c.GL_LOWER_LEFT, c.GL_ZERO_TO_ONE);
rhi = allocator.create(RHI) catch @panic("OOM");
Expand Down
2 changes: 1 addition & 1 deletion src/foundations/scenes/scenes.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn init(allocator: std.mem.Allocator, cfg: *config) *Scenes {
.allocator = allocator,
.cfg = cfg,
};
scenes.initScene(ui.ui_state.scene_type.frustum_planes);
scenes.initScene(ui.ui_state.scene_type.math_vector_arithmetic);
return scenes;
}

Expand Down