Exemplo n.º 1
0
    public void initCarryBones(MeshBone endeffector_bone)
    {
        if (bones_basis != null)
        {
            // Already bound
            return;
        }

        bones_basis = new List <MeshBoneUtil.Tuple <XnaGeometry.Vector2, XnaGeometry.Vector2> >();
        carry_bones = endeffector_bone.getAllChildren();
        carry_bones.RemoveAt(0); // Remove first end_effector bone, we do not want to carry that

        var base_vec_u = endeffector_bone.getWorldEndPt() - endeffector_bone.getWorldStartPt();

        base_vec_u.Normalize();

        var base_vec_v = new XnaGeometry.Vector4(0, 0, 0, 0);

        base_vec_v.X = -base_vec_u.Y;
        base_vec_v.Y = base_vec_u.X;

        foreach (var cur_bone in carry_bones)
        {
            var basis_start = getFromBasis(
                cur_bone.getWorldStartPt() - endeffector_bone.getWorldStartPt(),
                base_vec_u,
                base_vec_v);

            var basis_end = getFromBasis(
                cur_bone.getWorldEndPt() - endeffector_bone.getWorldStartPt(),
                base_vec_u,
                base_vec_v);

            var basis_pair =
                new MeshBoneUtil.Tuple <XnaGeometry.Vector2, XnaGeometry.Vector2>(basis_start, basis_end);

            bones_basis.Add(basis_pair);
        }
    }
Exemplo n.º 2
0
    public void poseCarryBones(MeshBone endeffector_bone)
    {
        int i = 0;

        foreach (var cur_bone in carry_bones)
        {
            var basis_pair = bones_basis[i];
            var tmp_vec    = endeffector_bone.getWorldEndPt() - endeffector_bone.getWorldStartPt();
            var base_vec_u = new XnaGeometry.Vector2(tmp_vec.X, tmp_vec.Y);
            base_vec_u.Normalize();

            var base_vec_v = new XnaGeometry.Vector2(0, 0);
            base_vec_v.X = -base_vec_u.Y;
            base_vec_v.Y = base_vec_u.X;

            var set_startpt = new XnaGeometry.Vector4(0, 0, 0, 1);
            var set_endpt   = new XnaGeometry.Vector4(0, 0, 0, 1);

            var calcVec = new XnaGeometry.Vector2(0, 0);
            calcVec = basis_pair.Item1.X * base_vec_u + basis_pair.Item1.Y * base_vec_v;

            set_startpt.X = calcVec.X;
            set_startpt.Y = calcVec.Y;
            set_startpt  += endeffector_bone.getWorldStartPt();
            set_startpt.W = 1;

            calcVec     = basis_pair.Item2.X * base_vec_u + basis_pair.Item2.Y * base_vec_v;
            set_endpt.X = calcVec.X;
            set_endpt.Y = calcVec.Y;
            set_endpt  += endeffector_bone.getWorldStartPt();
            set_endpt.W = 1;

            cur_bone.setWorldStartPt(set_startpt);
            cur_bone.setWorldEndPt(set_endpt);

            i++;
        }
    }