Beispiel #1
0
        public SplineObject GenerateCircle(double rad)
        {
            const double TANG = 0.415;

            double sn, cs;
            int    i, sub = 4;

            SplineObject op = SplineObject.Alloc(sub * 2, SPLINETYPE.SPLINETYPE_BEZIER);

            if (null == op || null == op.MakeVariableTag(C4dApi.Tsegment, 2))
            {
                C4dApi.blDelete_cs(op);
                return(null);
            }

            op.GetDataInstance().SetBool(C4dApi.SPLINEOBJECT_CLOSED, true);

            Segment seg = new Segment();

            seg.closed = true;
            seg.cnt    = sub;
            op.SetSegmentAt(0, seg);
            op.SetSegmentAt(1, seg);

            for (i = 0; i < sub; i++)
            {
                double angle = 2.0 * Math.PI * (double)i / (double)sub;
                sn = Math.Sin(angle);
                cs = Math.Cos(angle);

                double3 vOuter         = new double3(cs * rad, sn * rad, 0.0);
                double3 vOuterTangentL = new double3(sn * rad * TANG, -cs * rad * TANG, 0.0);
                double3 vOuterTangentR = -vOuterTangentL;
                double3 vInner         = vOuter * 0.5;
                double3 vInnerTangentL = vOuterTangentL * 0.5;
                double3 vInnerTangentR = -vInnerTangentL;

                op.SetPointAt(i, vOuter);
                Tangent outerTangent = new Tangent();
                outerTangent.vl = vOuterTangentL;
                outerTangent.vr = vOuterTangentR;
                op.SetTangentAt(i, outerTangent);

                op.SetPointAt(i + sub, vInner);
                Tangent innerTangent = new Tangent();
                innerTangent.vl = vInnerTangentL;
                innerTangent.vr = vInnerTangentR;
                op.SetTangentAt(i + sub, innerTangent);
            }
            op.Message(C4dApi.MSG_UPDATE);

            return(op);
        }