コード例 #1
0
ファイル: Ribbons.cs プロジェクト: twobob/UnityMol-Releases
    private void ConstructControlPoints(List <Dictionary <string, Vector3> > residueDicts, int res, int ss, int handedness)
    {
        //Debug.Log("Ribbons.cs::ConstructControlPoints > Beginning.");
        Vector3 ca0, ox0, ca1;
        Vector3 p0, p1, p2, p3;

        p1 = p2 = p3 = Vector3.zero;

        Dictionary <string, Vector3> res0, res1;

        res0 = res1 = null;

        if (res == 0)
        {
            // The control points 2 and 3 are created
            flipTestV = Vector3.zero;

            res0 = residueDicts[res];
            res1 = residueDicts[res + 1];

            bool success = true;
            success = success && res0.TryGetValue("CA", out ca0);
            success = success && res0.TryGetValue("O", out ox0);
            success = success && res1.TryGetValue("CA", out ca1);

            if (!success)
            {
                Debug.Log("Ribbons.cs::ConstructControlPoints > Failed to get all the vectors.");
            }

            AddControlPoints(ca0, ox0, ca1, ss, handedness);
            splineSide1.CopyCPoints(3, 2);
            splineCenter.CopyCPoints(3, 2);
            splineSide2.CopyCPoints(3, 2);

            res0    = residueDicts[res + 1];
            res1    = residueDicts[res + 2];
            success = true;
            success = success && res0.TryGetValue("CA", out ca0);
            success = success && res0.TryGetValue("O", out ox0);
            success = success && res1.TryGetValue("CA", out ca1);
            if (!success)
            {
                Debug.Log("Ribbons.cs::ConstructControlPoints > Failed to get all the vectors.");
            }
            AddControlPoints(ca0, ox0, ca1, ss, handedness);

            // We still need the two first control points
            // Moving backwards along the cp_center[2] - cp_center[3] direction
            splineCenter.GetCPoint(2, out p2);
            splineCenter.GetCPoint(3, out p3);

            p1 = LinearComb(2f, p2, -1f, p3);
            splineCenter.SetCPoint(1, p1);
            splineSide1.SetCPoint(1, LinearComb(1f, p1, ribbonWidth[ss], flipTestV));
            splineSide2.SetCPoint(1, LinearComb(1f, p1, -ribbonWidth[ss], flipTestV));

            p0 = LinearComb(2f, p1, -1f, p2);


            splineCenter.SetCPoint(0, p0);
            splineSide1.SetCPoint(0, LinearComb(1f, p0, ribbonWidth[ss], flipTestV));
            splineSide2.SetCPoint(0, LinearComb(1f, p0, -ribbonWidth[ss], flipTestV));
        }
        else
        {
            ShiftControlPoints();
            if ((residueDicts.Count - 1 == res) || (residueDicts.Count - 2 == res))
            {
                // Moving forward along the cp_center[1] - cp_center[2] direction
                splineCenter.GetCPoint(1, out p1);
                splineCenter.GetCPoint(2, out p2);

                p3 = LinearComb(2f, p2, -1f, p1);
                splineCenter.SetCPoint(3, p3);
                splineSide1.SetCPoint(3, LinearComb(1f, p3, ribbonWidth[ss], flipTestV));
                splineSide2.SetCPoint(3, LinearComb(1f, p3, -ribbonWidth[ss], flipTestV));
            }
            else
            {
                res0 = residueDicts[res + 1];
                res1 = residueDicts[res + 2];
                bool success = true;
                success = success && res0.TryGetValue("CA", out ca0);
                success = success && res0.TryGetValue("O", out ox0);
                success = success && res1.TryGetValue("CA", out ca1);
                if (!success)
                {
                    Debug.Log("Ribbons.cs::ConstructControlPoints > Failed to get all the vectors.");
                }
                AddControlPoints(ca0, ox0, ca1, ss, handedness);
            }
        }
        splineSide1.UpdateMatrix3();
        splineCenter.UpdateMatrix3();
        splineSide2.UpdateMatrix3();
    }     // End of ConstructControlPoints