refactor matrix muls when computing transform

This commit is contained in:
tali 2024-01-22 12:58:48 -05:00
parent 65dd5eb0b8
commit 9964260e0d
2 changed files with 18 additions and 19 deletions

View File

@ -109,15 +109,14 @@ module Mat2A = struct
dst.a5 <- src.a5;
end
let[@inline] mul (lhs : t) (rhs : t) : unit =
let { a0; a1; a2; a3; a4; a5 } = lhs in
let[@inline] multiply (dst : t) (lhs : t) (rhs : t) : unit =
begin
lhs.a0 <- (a0 * rhs.a0) + (a1 * rhs.a3);
lhs.a1 <- (a0 * rhs.a1) + (a1 * rhs.a4);
lhs.a2 <- (a0 * rhs.a2) + (a1 * rhs.a5) + a2;
lhs.a3 <- (a3 * rhs.a0) + (a4 * rhs.a3);
lhs.a4 <- (a3 * rhs.a1) + (a4 * rhs.a4);
lhs.a5 <- (a3 * rhs.a2) + (a4 * rhs.a5) + a5;
dst.a0 <- (lhs.a0 * rhs.a0) + (lhs.a1 * rhs.a3);
dst.a1 <- (lhs.a0 * rhs.a1) + (lhs.a1 * rhs.a4);
dst.a2 <- (lhs.a0 * rhs.a2) + (lhs.a1 * rhs.a5) + lhs.a2;
dst.a3 <- (lhs.a3 * rhs.a0) + (lhs.a4 * rhs.a3);
dst.a4 <- (lhs.a3 * rhs.a1) + (lhs.a4 * rhs.a4);
dst.a5 <- (lhs.a3 * rhs.a2) + (lhs.a4 * rhs.a5) + lhs.a5;
end
(*

View File

@ -15,7 +15,7 @@ module Transform_graph = struct
| Null
| Node of {
idx : int;
parent : node;
parent_tf : mat2a option;
model_tf : mat2a;
world_tf : mat2a;
}
@ -37,11 +37,15 @@ module Transform_graph = struct
let add t parent =
let model_tf = mat2a 0.0 0.0 1.0 1.0 in
let world_tf = mat2a 0.0 0.0 1.0 1.0 in
let parent_tf, world_tf =
match parent with
| Null -> None, model_tf
| Node p -> Some p.world_tf, mat2a 0.0 0.0 1.0 1.0
in
let node =
Node {
idx = t.size;
parent;
parent_tf;
model_tf;
world_tf;
}
@ -53,14 +57,10 @@ module Transform_graph = struct
let buf = t.buffer in
for i = 0 to t.size - 1 do
match buf.(i) with
| Null -> ()
| Node n ->
match n.parent with
| Null ->
Mat2A.copy n.world_tf ~src:n.model_tf
| Node p ->
Mat2A.copy n.world_tf ~src:p.world_tf;
Mat2A.mul n.world_tf n.model_tf;
| Node { model_tf; world_tf; parent_tf = Some parent_tf; _ } ->
Mat2A.multiply world_tf parent_tf model_tf
| _ ->
()
done
let world = function