Exemplo n.º 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);
        }
Exemplo n.º 2
0
        public override SplineObject GetContour(BaseObject op, BaseDocument doc, double lod, BaseThread bt)
        {
            BaseContainer bc = op.GetDataInstance();
            SplineObject  bp = GenerateCircle(bc.GetFloat(CIRCLEOBJECT_RAD));

            if (bp == null)
            {
                return(null);
            }
            BaseContainer bb = bp.GetDataInstance();

            bb.SetInt32(C4dApi.SPLINEOBJECT_INTERPOLATION, bc.GetInt32(C4dApi.SPLINEOBJECT_INTERPOLATION));
            bb.SetInt32(C4dApi.SPLINEOBJECT_SUB, bc.GetInt32(C4dApi.SPLINEOBJECT_SUB));
            bb.SetFloat(C4dApi.SPLINEOBJECT_ANGLE, bc.GetFloat(C4dApi.SPLINEOBJECT_ANGLE));
            bb.SetFloat(C4dApi.SPLINEOBJECT_MAXIMUMLENGTH, bc.GetFloat(C4dApi.SPLINEOBJECT_MAXIMUMLENGTH));

            OrientObject(bp, bc.GetInt32(C4dApi.PRIM_PLANE), bc.GetBool(C4dApi.PRIM_REVERSE));

            return(bp);
        }