Add Mesh translate function
This commit is contained in:
parent
8ecc49ac79
commit
600753dc0b
1 changed files with 39 additions and 4 deletions
|
|
@ -110,6 +110,13 @@ pub fn rotateMeshAroundPoint(mesh: *Mesh, p: vec3.Vec3F64, q: vec3.QuatF64) void
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn translateMesh(mesh: *Mesh, p: vec3.Vec3F64) void {
|
||||||
|
for (mesh.vertices.items) |*vertex| {
|
||||||
|
vertex.* = vec3.vec3Add(vertex.*, p);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
test "Verify fixed point conversion works" {
|
test "Verify fixed point conversion works" {
|
||||||
const vec = vec3.Vec3F64.init(1.0, 2.134, 1010.11);
|
const vec = vec3.Vec3F64.init(1.0, 2.134, 1010.11);
|
||||||
const fixed_point = vecToFixedPoint(vec, 2);
|
const fixed_point = vecToFixedPoint(vec, 2);
|
||||||
|
|
@ -175,9 +182,7 @@ test "Test binary stl is parsed correctly" {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
test "mesh is rotated correctly" {
|
fn createDummyMesh(allocator: std.mem.Allocator) !Mesh {
|
||||||
const allocator = std.testing.allocator;
|
|
||||||
|
|
||||||
var vertices: std.ArrayList(vec3.Vec3F64) = .empty;
|
var vertices: std.ArrayList(vec3.Vec3F64) = .empty;
|
||||||
try vertices.appendSlice(allocator, &.{
|
try vertices.appendSlice(allocator, &.{
|
||||||
vec3.Vec3F64.init(0, 0, 0),
|
vec3.Vec3F64.init(0, 0, 0),
|
||||||
|
|
@ -193,11 +198,16 @@ test "mesh is rotated correctly" {
|
||||||
var tri_indices: std.ArrayList([3]usize) = .empty;
|
var tri_indices: std.ArrayList([3]usize) = .empty;
|
||||||
try tri_indices.appendSlice(allocator, &.{.{ 0, 1, 2 }});
|
try tri_indices.appendSlice(allocator, &.{.{ 0, 1, 2 }});
|
||||||
|
|
||||||
var mesh: Mesh = .{
|
return .{
|
||||||
.vertices = vertices,
|
.vertices = vertices,
|
||||||
.triangle_normals = triangle_normals,
|
.triangle_normals = triangle_normals,
|
||||||
.triangle_vertices = tri_indices,
|
.triangle_vertices = tri_indices,
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
test "mesh is rotated correctly" {
|
||||||
|
const allocator = std.testing.allocator;
|
||||||
|
|
||||||
|
var mesh = try createDummyMesh(allocator);
|
||||||
defer mesh.deinit(allocator);
|
defer mesh.deinit(allocator);
|
||||||
|
|
||||||
var orig_mesh: Mesh = .{
|
var orig_mesh: Mesh = .{
|
||||||
|
|
@ -229,3 +239,28 @@ test "mesh is rotated correctly" {
|
||||||
1e-12,
|
1e-12,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "mesh is translated correctly" {
|
||||||
|
const allocator = std.testing.allocator;
|
||||||
|
|
||||||
|
var mesh = try createDummyMesh(allocator);
|
||||||
|
defer mesh.deinit(allocator);
|
||||||
|
|
||||||
|
translateMesh(&mesh, vec3.Vec3F64.init(1, 1, 1));
|
||||||
|
|
||||||
|
try std.testing.expect(vec3.vec3ApproxEq(
|
||||||
|
mesh.vertices.items[0],
|
||||||
|
vec3.Vec3F64.init(1, 1, 1),
|
||||||
|
1e-12,
|
||||||
|
));
|
||||||
|
try std.testing.expect(vec3.vec3ApproxEq(
|
||||||
|
mesh.vertices.items[1],
|
||||||
|
vec3.Vec3F64.init(1.5, 1 + std.math.sqrt(3.0) / 2.0, 1),
|
||||||
|
1e-12,
|
||||||
|
));
|
||||||
|
try std.testing.expect(vec3.vec3ApproxEq(
|
||||||
|
mesh.vertices.items[2],
|
||||||
|
vec3.Vec3F64.init(2, 1, 1),
|
||||||
|
1e-12,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue