Пример #1
0
        public int CompareTo(object c)
        {
            ISectData c1 = this;
            ISectData c2 = (ISectData)c;
            double    d1 = (c1.origin.x - c1.intersect.x) * (c1.origin.x - c1.intersect.x) +
                           (c1.origin.y - c1.intersect.y) * (c1.origin.y - c1.intersect.y) +
                           (c1.origin.z - c1.intersect.z) * (c1.origin.z - c1.intersect.z);

            double d2 = (c2.origin.x - c2.intersect.x) * (c2.origin.x - c2.intersect.x) +
                        (c2.origin.y - c2.intersect.y) * (c2.origin.y - c2.intersect.y) +
                        (c2.origin.z - c2.intersect.z) * (c2.origin.z - c2.intersect.z);

            if (d1 > d2)
            {
                return(1);
            }
            if (d1 < d2)
            {
                return(-1);
            }
            else
            {
                return(0);
            }
        }
Пример #2
0
        /// <summary>
        /// This functiuon positions the base at the location 'intersect'
        /// The idir is the direction that was used to intersect
        /// </summary>
        /// <param name="intersect"></param>
        /// <param name="idir"></param>
        /// <param name="inorm"></param>
        public void PositionBottom(ISectData dat)
        {
            // the bottom could be a tip or base
            // need to orient the bottom and position it.
            Point3d center;
            // for a base support, just slide it around
            if (m_subtype == eSubType.eBase)
            {
                center = Centroid(); // get the centroid of the selected portion of the object
                MinMax mm = CalcMinMaxRange(s1i, s4i);
                float dist = (float)((mm.m_max - mm.m_min) / 2);
                Translate(
                    (float)(dat.intersect.x - center.x),
                    (float)(dat.intersect.y - center.y),
                    (float)(dat.intersect.z - center.z + dist));
            }
            else if (m_subtype == eSubType.eIntra)  // bottom tip
            {
                // for a base tip, find the angle and angle it in
                Vector3d isectnorm = new Vector3d();
                //save the polygon intersection normal
                isectnorm.x = dat.poly.m_normal.x;
                isectnorm.y = dat.poly.m_normal.y;
                isectnorm.z = dat.poly.m_normal.z;
                isectnorm.Normalize();

                if (isectnorm.z < 0)
                {
                    isectnorm.z *= -1.0f;
                }
                // limit the z down to 45 degrees
                if (isectnorm.z < .75)
                {
                    isectnorm.z = .75f;
                }

                // re-genrate the points on the bottom of the foot
                ReGenSegmentPoints(mSC.htrad, mSC.cdivs, s1i, 0, true); // bottom of foot is the tip radius
                Matrix3D tMat = new Matrix3D();
                Vector3d vup = new Vector3d(0, 1, 0);
                Vector3d dir = new Vector3d(isectnorm.x, isectnorm.y, isectnorm.z);
                dir.Normalize();

                //direction should be upward at this point.
                //create a matrix transform
                tMat.LookAt(dir, vup);
                //transform the si1-s2i points to look at the vector
                TransformRange(tMat, s1i, s2i);
                //move the range of points to be touching the intersection point
                STranslateRange(dat.intersect.x, dat.intersect.y, dat.intersect.z, s1i, s2i);

                //now, get the center of s4i to s5i
                Point3d cnt = CalcCentroid(s2i, s4i);
                //translate to 0,0,0
                STranslateRange(-cnt.x, -cnt.y, -cnt.z, s2i, s4i);
                //reset the points,
                ReGenSegmentPoints(mSC.hbrad, mSC.cdivs, s2i, 0, false); // top of foot
                ReGenSegmentPoints(mSC.hbrad, mSC.cdivs, s3i, 0, false); // top of foot
                Point3d newp = new Point3d();
                newp.x = dat.intersect.x + (isectnorm.x * 2);
                newp.y = dat.intersect.y + (isectnorm.y * 2);
                newp.z = dat.intersect.z + (isectnorm.z * 2);
                STranslateRange(newp.x,newp.y,newp.z, s2i, s4i);

                Update();
            }
            //Update();
        }
Пример #3
0
        public void MoveFromTip(ISectData dat)
        {
            Point3d center;
            center = Centroid(); // get the centroid of the selected portion of the object
            Vector3d isectnorm = new Vector3d();
            //save the polygon intersection normal
            isectnorm.x = dat.poly.m_normal.x;
            isectnorm.y = dat.poly.m_normal.y;
            isectnorm.z = dat.poly.m_normal.z;

            MinMax mm = CalcMinMaxRange(s4i, m_lstpoints.Count);
            float dist = (float)((mm.m_max - mm.m_min) );
            ResetTip();
            Matrix3D tMat = new Matrix3D();
            Vector3d vup = new Vector3d(0,1,0);
            //always make sure the z is heading downward
            if (isectnorm.z > 0)
            {
                isectnorm.z *= -1.0f;
            }
            // limit the z down to 45 degrees
            if (isectnorm.z > -.75)
            {
                isectnorm.z = -.75f;
            }
            //reverse the direction to get the reflection
            Vector3d dir = new Vector3d(-isectnorm.x, -isectnorm.y, -isectnorm.z);
            dir.Normalize();
            //create a matrix transform
            tMat.LookAt(dir, vup);
            Transform(tMat);
            Translate(
                (float)(dat.intersect.x),
                (float)(dat.intersect.y),
                (float)(dat.intersect.z));

            //now, get the center of s4i to s5i
            Point3d cnt = CalcCentroid(s4i, s5i);
            //translate to 0
            TranslateRange(-cnt.x, -cnt.y, -cnt.z, s4i, s5i);
            //reset the points,
            ReGenSegmentPoints(mSC.hbrad, mSC.cdivs, s4i, 0, false); // bottom of head
            //move back
            TranslateRange(cnt.x, cnt.y, cnt.z, s4i, s5i);
            Update();

            //
        }