private static ISectData ISectGroundPlane(Vector3d direction, Point3d origin)
        {
            ISectData isect = null;

            direction.Normalize();
            direction.Scale(10000.0f);

            GPendp.Set(origin);
            GPendp.x += direction.x;
            GPendp.y += direction.y;
            GPendp.z += direction.z;
            // intersect with the imaginary groundplane object;
            if (m_gp == null)
            {
                CreateGroundPlane();
            }
            if (IntersectSphere(origin, GPendp, ref GPintersect, m_gp.m_center, m_gp.m_radius))
            {
                foreach (Polygon p in m_gp.m_lstpolys)
                {
                    //GPintersect = new Point3d();
                    // try a less- costly sphere intersect here
                    if (IntersectSphere(origin, GPendp, ref GPintersect, p.m_center, p.m_radius))
                    {
                        // if it intersects,
                        if (RTUtils.IntersectPoly(p, origin, GPendp, ref GPintersect))
                        {
                            isect = new ISectData(m_gp, p, GPintersect, origin, direction);
                        }
                    }
                }
            }
            return(isect);
        }
Beispiel #2
0
        private static ISectData ISectObjSelPlane(Vector3d direction, Point3d origin)
        {
            ISectData isect = null;

            if (m_selplane == null)
            {
                return(null);
            }
            direction.Normalize();
            direction.Scale(10000.0f);

            ObSelendp.Set(origin);
            ObSelendp.x += direction.x;
            ObSelendp.y += direction.y;
            ObSelendp.z += direction.z;
            // intersect with the imaginary object selection plane
            if (IntersectSphere(origin, ObSelendp, ref ObSelintersect, m_selplane.m_center, m_selplane.m_radius))
            {
                foreach (Polygon p in m_selplane.m_lstpolys)
                {
                    // try a less- costly sphere intersect here
                    if (IntersectSphere(origin, ObSelendp, ref ObSelintersect, p.m_center, p.m_radius))
                    {
                        // if it intersects,
                        if (RTUtils.IntersectPoly(p, origin, ObSelendp, ref ObSelintersect))
                        {
                            isect = new ISectData(m_selplane, p, ObSelendp, origin, direction);
                        }
                    }
                }
            }
            return(isect);
        }
Beispiel #3
0
        /// <summary>
        /// For now this is the editing mode for the currently selected support
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void glControl1_Click(object sender, EventArgs e)
        {
            // single click on GL Control
            Object3d obj = UVDLPApp.Instance().SelectedObject;

            if (obj == null)
            {
                return;
            }
            if (ctrldown == false)
            {
                return;                    // ctrl need to be held down
            }
            // this object is a support
            if (obj.tag == Object3d.OBJ_SUPPORT)
            {
                Support sup = (Support)obj;// we can cast safely
                // now we have to see if we clicked on an object
                MouseEventArgs   me           = e as MouseEventArgs;
                MouseButtons     buttonPushed = me.Button;
                int              xPos         = me.X;
                int              yPos         = me.Y;
                List <ISectData> isects       = TestHitTest(xPos, yPos);
                if (isects.Count == 0)
                {
                    return;                    // no intersections
                }
                ISectData isd1 = null;
                foreach (ISectData isd in isects)
                {
                    // find the closest object we clicked
                    if (isd.obj.tag == Object3d.OBJ_NORMAL)
                    {
                        isd1 = isd; //  save it
                        break;
                    }
                }
                if (isd1 == null)
                {
                    return;               // no object intersection
                }
                isd1.poly.CalcNormal();
                m_isectnormal.x = isd1.poly.m_normal.x;
                m_isectnormal.y = isd1.poly.m_normal.y;
                m_isectnormal.z = isd1.poly.m_normal.z;
                // ok, we've got the normal, we know where we've intersected
                // my best guess is that we should move the support 5mm in the direction of the camera
                // the tip of the support should touch the intersection point
                // let's start with scaling the height...
                //sup.ScaleToHeight(isd1.intersect.z);
                //m_camera.m_eye
                Engine3D.Vector3d towardseye = new Engine3D.Vector3d();
                towardseye = m_isectnormal; // -m_camera.m_eye;
                towardseye.Normalize();     // make the unit length of 1
                towardseye.Scale(4.0f);     // scale to 5 mm
                sup.MoveFromTip(isd1.intersect, towardseye);
                UpdateView();
                //sup.
            }
        }
        public static List <ISectData> IntersectObjects(Vector3d direction, Point3d origin, List <Object3d> objects, bool supports)
        {
            //List<ISectData> m_isectlst = new List<ISectData>();

            try
            {
                if (!vecinit)
                {
                    Initvecs();
                }
                m_isectlst.Clear();
                direction.Normalize();
                direction.Scale(10000.0f);


                IOendp.Set(origin);
                IOendp.x += direction.x;
                IOendp.y += direction.y;
                IOendp.z += direction.z;
                lock (lck)
                {
                    foreach (Object3d obj in objects)
                    {
                        if (obj.tag == Object3d.OBJ_SUPPORT && !supports)
                        {
                            continue;
                        }
                        // try a less- costly sphere intersect here
                        if (IntersectSphere(origin, IOendp, ref IOintersect, obj.m_center, obj.m_radius))
                        {
                            foreach (Polygon p in obj.m_lstpolys)
                            {
                                //IOintersect = new Point3d();
                                // try a less- costly sphere intersect here
                                if (IntersectSphere(origin, IOendp, ref IOintersect, p.m_center, p.m_radius))
                                {
                                    // if it intersects,
                                    if (RTUtils.IntersectPoly(p, origin, IOendp, ref IOintersect))
                                    {
                                        m_isectlst.Add(new ISectData(obj, p, IOintersect, origin, direction));
                                    }
                                }
                            }
                        }
                    }
                }
                ISectData gp = ISectGroundPlane(direction, origin);
                if (gp != null)
                {
                    m_isectlst.Add(gp);
                }
                m_isectlst.Sort();
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex.Message);
            }
            return(m_isectlst);
        }
Beispiel #5
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();

            //
        }
Beispiel #6
0
        public static List <ISectData> IntersectObject(Vector3d direction, Point3d origin, Object3d objectin,
                                                       bool supports)
        {
            try
            {
                if (!vecinit)
                {
                    Initvecs();
                }
                //m_isectlst.Clear();
                direction.Normalize();
                direction.Scale(10000.0f);


                IOendp.Set(origin);
                IOendp.x += direction.x;
                IOendp.y += direction.y;
                IOendp.z += direction.z;
                if (objectin.tag == Object3d.OBJ_SUPPORT && !supports)
                {
                    return(null);
                }
                // try a less- costly sphere intersect here
                if (IntersectSphere(origin, IOendp, ref IOintersect, objectin.m_center, objectin.m_radius))
                {
                    List <Polygon> interSectionObjects = objectin.IntersectForUpVector(origin, direction);
                    m_isectlst.AddRange(from p in interSectionObjects where RTUtils.IntersectPoly(p, origin, IOendp, ref IOintersect) select new ISectData(objectin, p, IOintersect, origin, direction));
                }
                //intersect the ground plane
                ISectData gp = ISectGroundPlane(direction, origin);
                if (gp != null)
                {
                    m_isectlst.Add(gp);
                }

                /*
                 * //intersect the object selection plane
                 * ISectData obsel = ISectObjSelPlane(direction, origin);
                 * if (obsel != null)
                 * {
                 *  m_isectlst.Add(obsel);
                 * }
                 */
                m_isectlst.Sort();
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex.Message);
            }
            return(m_isectlst);
        }
Beispiel #7
0
        public static List <ISectData> IntersectObject(Vector3d direction, Point3d origin, List <Object3d> objectsin,
                                                       bool supports, Object3d obj)
        {
            m_isectlst.Clear();
            try
            {
                if (IntersectSphere(origin, IOendp, ref IOintersect, obj.m_center, obj.m_radius))
                {
                    List <Polygon> interSectionObjects = obj.IntersectForUpVector(origin, direction);

                    foreach (Polygon p in interSectionObjects)
                    {
                        //IOintersect = new Point3d();
                        // try a less- costly sphere intersect here
                        //if (IntersectSphere(origin, IOendp, ref IOintersect, p.m_center, p.m_radius))
                        //{
                        // if it intersects,
                        if (RTUtils.IntersectPoly(p, origin, IOendp, ref IOintersect))
                        {
                            m_isectlst.Add(new ISectData(obj, p, IOintersect, origin, direction));
                        }
                        //}
                    }
                }
                ISectData gp = ISectGroundPlane(direction, origin);
                if (gp != null)
                {
                    m_isectlst.Add(gp);
                }

                /*
                 * //intersect the object selection plane
                 * ISectData obsel = ISectObjSelPlane(direction, origin);
                 * if (obsel != null)
                 * {
                 *  m_isectlst.Add(obsel);
                 * }
                 */
                m_isectlst.Sort();
            }
            catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex.Message);
            }
            return(m_isectlst);
        }
        /// <summary>
        /// For now this is the editing mode for the currently selected support
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void glControl1_Click(object sender, EventArgs e)
        {
            // single click on GL Control
            if (UVDLPApp.Instance().SupportEditMode == UVDLPApp.eSupportEditMode.eAddSupport)
            {
                // if we're adding supports
                MouseEventArgs me = e as MouseEventArgs;
                // MouseButtons buttonPushed = me.Button;
                int xPos = me.X;
                int yPos = me.Y;
                List <ISectData> isects = TestHitTest(xPos, yPos);
                if (isects.Count == 0)
                {
                    return;                    // no intersections
                }
                ISectData isd1 = null;
                foreach (ISectData isd in isects)
                {
                    // find the closest object we clicked
                    if (isd.obj.tag == Object3d.OBJ_NORMAL)
                    {
                        isd1 = isd; //  save it
                        break;
                    }
                }
                if (isd1 == null)
                {
                    return;               // no object intersection
                }
                //add a support
                Support sup = AddNewSupport(isd1.intersect.x, isd1.intersect.y, isd1.intersect.z, isd1.obj);
                sup.SelectionType = Support.eSelType.eTip;
                sup.MoveFromTip(isd1);
                sup.SelectionType = Support.eSelType.eWhole;

                UpdateView();
                return;
            }
        }
        private static ISectData ISectGroundPlane(Vector3d direction, Point3d origin)
        {
            ISectData isect = null;
            direction.Normalize();
            direction.Scale(10000.0f);

            GPendp.Set(origin);
            GPendp.x += direction.x;
            GPendp.y += direction.y;
            GPendp.z += direction.z;
            // intersect with the imaginary groundplane object;
            if (m_gp == null) 
            {
                CreateGroundPlane();
            }
            if (IntersectSphere(origin, GPendp, ref GPintersect, m_gp.m_center, m_gp.m_radius))
            {
                foreach (Polygon p in m_gp.m_lstpolys)
                {
                    //GPintersect = new Point3d();
                    // try a less- costly sphere intersect here   
                    if (IntersectSphere(origin, GPendp, ref GPintersect, p.m_center, p.m_radius))
                    {
                        // if it intersects,
                        if (RTUtils.IntersectPoly(p, origin, GPendp, ref GPintersect))
                        {
                           isect = new ISectData(m_gp, p, GPintersect, origin, direction);
                        }
                    }
                }
            }
            return isect;
        }
Beispiel #10
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();
        }
        private static ISectData ISectObjSelPlane(Vector3d direction, Point3d origin)
        {
            ISectData isect = null;
            if (m_selplane == null)
                return null;
            direction.Normalize();
            direction.Scale(10000.0f);

            ObSelendp.Set(origin);
            ObSelendp.x += direction.x;
            ObSelendp.y += direction.y;
            ObSelendp.z += direction.z;
            // intersect with the imaginary object selection plane
            if (IntersectSphere(origin, ObSelendp, ref ObSelintersect, m_selplane.m_center, m_selplane.m_radius))
            {
                foreach (Polygon p in m_selplane.m_lstpolys)
                {
                    // try a less- costly sphere intersect here
                    if (IntersectSphere(origin, ObSelendp, ref ObSelintersect, p.m_center, p.m_radius))
                    {
                        // if it intersects,
                        if (RTUtils.IntersectPoly(p, origin, ObSelendp, ref ObSelintersect))
                        {
                            isect = new ISectData(m_selplane, p, ObSelendp, origin, direction);
                        }
                    }
                }
            }
            return isect;
        }