refactor matrix muls when computing transform
This commit is contained in:
parent
65dd5eb0b8
commit
9964260e0d
|
@ -109,15 +109,14 @@ module Mat2A = struct
|
||||||
dst.a5 <- src.a5;
|
dst.a5 <- src.a5;
|
||||||
end
|
end
|
||||||
|
|
||||||
let[@inline] mul (lhs : t) (rhs : t) : unit =
|
let[@inline] multiply (dst : t) (lhs : t) (rhs : t) : unit =
|
||||||
let { a0; a1; a2; a3; a4; a5 } = lhs in
|
|
||||||
begin
|
begin
|
||||||
lhs.a0 <- (a0 * rhs.a0) + (a1 * rhs.a3);
|
dst.a0 <- (lhs.a0 * rhs.a0) + (lhs.a1 * rhs.a3);
|
||||||
lhs.a1 <- (a0 * rhs.a1) + (a1 * rhs.a4);
|
dst.a1 <- (lhs.a0 * rhs.a1) + (lhs.a1 * rhs.a4);
|
||||||
lhs.a2 <- (a0 * rhs.a2) + (a1 * rhs.a5) + a2;
|
dst.a2 <- (lhs.a0 * rhs.a2) + (lhs.a1 * rhs.a5) + lhs.a2;
|
||||||
lhs.a3 <- (a3 * rhs.a0) + (a4 * rhs.a3);
|
dst.a3 <- (lhs.a3 * rhs.a0) + (lhs.a4 * rhs.a3);
|
||||||
lhs.a4 <- (a3 * rhs.a1) + (a4 * rhs.a4);
|
dst.a4 <- (lhs.a3 * rhs.a1) + (lhs.a4 * rhs.a4);
|
||||||
lhs.a5 <- (a3 * rhs.a2) + (a4 * rhs.a5) + a5;
|
dst.a5 <- (lhs.a3 * rhs.a2) + (lhs.a4 * rhs.a5) + lhs.a5;
|
||||||
end
|
end
|
||||||
|
|
||||||
(*
|
(*
|
||||||
|
|
22
src/n2/n2.ml
22
src/n2/n2.ml
|
@ -15,7 +15,7 @@ module Transform_graph = struct
|
||||||
| Null
|
| Null
|
||||||
| Node of {
|
| Node of {
|
||||||
idx : int;
|
idx : int;
|
||||||
parent : node;
|
parent_tf : mat2a option;
|
||||||
model_tf : mat2a;
|
model_tf : mat2a;
|
||||||
world_tf : mat2a;
|
world_tf : mat2a;
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,15 @@ module Transform_graph = struct
|
||||||
|
|
||||||
let add t parent =
|
let add t parent =
|
||||||
let model_tf = mat2a 0.0 0.0 1.0 1.0 in
|
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 =
|
let node =
|
||||||
Node {
|
Node {
|
||||||
idx = t.size;
|
idx = t.size;
|
||||||
parent;
|
parent_tf;
|
||||||
model_tf;
|
model_tf;
|
||||||
world_tf;
|
world_tf;
|
||||||
}
|
}
|
||||||
|
@ -53,14 +57,10 @@ module Transform_graph = struct
|
||||||
let buf = t.buffer in
|
let buf = t.buffer in
|
||||||
for i = 0 to t.size - 1 do
|
for i = 0 to t.size - 1 do
|
||||||
match buf.(i) with
|
match buf.(i) with
|
||||||
| Null -> ()
|
| Node { model_tf; world_tf; parent_tf = Some parent_tf; _ } ->
|
||||||
| Node n ->
|
Mat2A.multiply world_tf parent_tf model_tf
|
||||||
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;
|
|
||||||
done
|
done
|
||||||
|
|
||||||
let world = function
|
let world = function
|
||||||
|
|
Loading…
Reference in New Issue