let init r =
let index = ref 0 in
let add_bones i father =
let xi,yi,zi = pos.(i) in
Array.iteri
(fun j connected ->
if connected && j <> father then
let xj,yj,zj = pos.(j) in
let x,y,z = xj-.xi,yj-.yi,zj-.zi in
let d = sqrt (x*.x+.y*.y+.z*.z) in
bones.(!index) <- (i,j,d) ;
incr index ;
Printf.printf "Bone (%d,%d,%f)\n" i j d) skel.(i)
in
let rec round backup =
let new_backup = !index in
for i = backup to !index - 1 do
let (a,b,_) = bones.(i) in
try
add_bones b a
with
| Invalid_argument ("index out of bounds") ->
failwith "Skel is cyclic!"
done ;
if new_backup <> !index then
round new_backup
in
if !root <> r then
begin
root := r ;
add_bones r (-1) ;
round 0 ;
if !index <> nb_bones then
failwith "Skel is not connex!" ;
update_angles () ;
Printf.printf "Root changed to %d.\n" !root
end