Пример #1
0
 internal static HandleRef getCPtr(Tangent obj) {
   return (obj == null) ? new HandleRef(null, IntPtr.Zero) : obj.swigCPtr;
 }
        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;
        }
Пример #3
0
 public void SetTangentAt(int inx, Tangent pT) {
   C4dApiPINVOKE.SplineObject_SetTangentAt(swigCPtr, inx, Tangent.getCPtr(pT));
 }
        static void OrientObject(SplineObject op, int plane, bool reverse)
        {
            // double3 padr = op.GetPointW();
            // Tangent hadr = op.GetTangentW(), h;
            int nPoints = op.GetPointCount();
            int i;

            bool bTangents = op.GetTangentCount()!= 0;

            if (plane >= 1)
            {
                switch (plane)
                {
                    case 1: // ZY
                        for (i = 0; i < nPoints; i++)
                        {
                            double3 v  = op.GetPointAt(i);
                            op.SetPointAt(i, new double3(-v.z, v.y, v.x));
                            if (!bTangents) continue;
                            Tangent t = op.GetTangentAt(i);
                            Tangent t2 = new Tangent();
                            t2.vl = new double3(-t.vl.z, t.vl.y, t.vl.x);
                            t2.vr = new double3(-t.vr.z, t.vr.y, t.vr.x);
                            op.SetTangentAt(i, t2);
                        }
                        break;

                    case 2: // XZ
                        for (i = 0; i < nPoints; i++)
                        {
                            double3 v = op.GetPointAt(i);
                            op.SetPointAt(i, new double3(v.x, -v.z, v.y));
                            if (!bTangents) continue;
                            Tangent t = op.GetTangentAt(i);
                            Tangent t2 = new Tangent();
                            t2.vl = new double3(t.vl.x, -t.vl.z, t.vl.y);
                            t2.vr = new double3(t.vr.x, -t.vr.z, t.vr.y);
                            op.SetTangentAt(i, t2);
                        }
                        break;
                }
            }

            if (reverse)
            {
                double3 p;
                int to = nPoints / 2;
                if ((nPoints % 2) != 0)
                    to++;
                for (i = 0; i < to; i++)
                {
                    p = op.GetPointAt(i);
                    op.SetPointAt(i, op.GetPointAt(nPoints - 1 - i));
                    op.SetPointAt(nPoints-1-i, p);
                    if (!bTangents)
                        continue;
                    Tangent h1 = op.GetTangentAt(i);
                    Tangent h2 = op.GetTangentAt(nPoints-1-i);
                    Tangent hTmp1 = new Tangent();
                    Tangent hTmp2 = new Tangent();
                    hTmp1.vl = new double3(h2.vr);
                    hTmp1.vr = new double3(h2.vl);
                    hTmp2.vl = new double3(h1.vr);
                    hTmp2.vr = new double3(h1.vl);
                    op.SetTangentAt(i, hTmp1);
                    op.SetTangentAt(nPoints-1-i, hTmp2);
                }
            }

            op.Message(C4dApi.MSG_UPDATE);
        }