private void glControl1_MouseMove(object sender, MouseEventArgs e)
        {
            double dx = 0, dy = 0;

            if (lmdown || rmdown || mmdown)
            {
                dx  = e.X - mdx;
                dy  = e.Y - mdy;
                mdx = e.X;
                mdy = e.Y;
            }
            dx /= 2;
            dy /= 2;

            if (lmdown)
            {
                m_camera.RotateRightFlat((float)dx);
                m_camera.RotateUp((float)dy);
                m_axisCam.RotateRightFlat((float)dx);
                m_axisCam.RotateUp((float)dy);

                UpdateView();
            }
            else if (mmdown)
            {
                m_camera.MoveForward((float)dy);
                UpdateView();
            }
            else if (rmdown)
            {
                m_camera.Move((float)dx, (float)dy);
                UpdateView();
            }

            // if no object selected, bail
            if (UVDLPApp.Instance().SelectedObject == null)
            {
                return;
            }

            if (m_movingobjectmode)                            // if we're moving an object - shift key down
            {
                List <ISectData> hits = TestHitTest(e.X, e.Y); // hit-test all
                // examine the last isect data
                foreach (ISectData dat in hits)
                {
                    //remember to break out of this foreach loop after executing a movement.

                    // either we're moving a support
                    if (UVDLPApp.Instance().SelectedObject.tag == Object3d.OBJ_SUPPORT)
                    {
                        // if it's the base we're moving,
                        //allow the base to change types
                        // see if it intersects with the ground, or an object
                        //cast as a support object
                        Support sup = (Support)UVDLPApp.Instance().SelectedObject;
                        if (sup.SelectionType == Support.eSelType.eWhole)
                        {
                            // we're in modify mode, but we're still moving the whole support
                            if (dat.obj.tag == Object3d.OBJ_SEL_PLANE)
                            {
                                //we should really try a top/ bottom intersection / scale to hieg
                                // move the support
                                sup.Translate(
                                    (float)(dat.intersect.x - UVDLPApp.Instance().SelectedObject.m_center.x),
                                    (float)(dat.intersect.y - UVDLPApp.Instance().SelectedObject.m_center.y),
                                    0.0f);
                                // now we've moved the object approximately to where it needs to be
                                //turn it back into a base
                                sup.SubType = Support.eSubType.eBase;
                                //get the center location
                                Point3d           centroid = sup.Centroid();
                                Engine3D.Vector3d upvec    = new Engine3D.Vector3d();
                                upvec.Set(0, 0, 1);
                                Point3d origin = new Point3d();
                                origin.Set(centroid.x, centroid.y, .001f);    // above the ground plane
                                List <ISectData> isects = RTUtils.IntersectObjects(upvec, origin, UVDLPApp.Instance().Engine3D.m_objects, false);
                                foreach (ISectData isd in isects)
                                {
                                    if (isd.obj.tag == Object3d.OBJ_NORMAL)    // if we've intersected a normal object upwards
                                    {
                                        sup.SelectionType = Support.eSelType.eTip;
                                        sup.MoveFromTip(isd);
                                        sup.SelectionType = Support.eSelType.eWhole;
                                        break;
                                    }
                                }
                                //starting at the x/y ground plane, hittest upward
                                break;
                            }
                        }
                        else if (sup.SelectionType == Support.eSelType.eBase)
                        {
                            //going to change this to test for intersection with object, or ground plane
                            // if intersected with an object, change to intra type
                            // and set the base on the object
                            // if intersected with ground, change to base type and put on ground
                            if (dat.obj.tag == Object3d.OBJ_GROUND)
                            {
                                // make sure we're a base tip
                                sup.SubType = Support.eSubType.eBase;
                                // position the bottom to the intersection point
                                sup.PositionBottom(dat);
                                break;
                            }
                            else if (dat.obj.tag == Object3d.OBJ_NORMAL)     // intersected with an object
                            {
                                //should check with the normal of the object to see if it's facing upwards
                                sup.SubType = Support.eSubType.eIntra;
                                // position the bottom to the intersection point
                                sup.PositionBottom(dat);
                                break;
                            }
                        }
                        else if (sup.SelectionType == Support.eSelType.eTip)
                        {
                            if (dat.obj.tag == Object3d.OBJ_NORMAL)     // intersected with an object
                            {
                                sup.MoveFromTip(dat);
                                UpdateView();
                                break;
                            }
                        }
                    }
                    else     // or a normal object based on object selection plane
                    {
                        if (dat.obj.tag == Object3d.OBJ_SEL_PLANE)
                        {
                            UVDLPApp.Instance().SelectedObject.Translate(
                                (float)(dat.intersect.x - UVDLPApp.Instance().SelectedObject.m_center.x),
                                (float)(dat.intersect.y - UVDLPApp.Instance().SelectedObject.m_center.y),
                                0.0f);
                        }
                        break;
                    }
                }
                UpdateView();
            }
        }
        private void glControl1_MouseMove(object sender, MouseEventArgs e)
        {
            List <ISectData> hits = TestHitTest(e.X, e.Y);
            double           dx = 0, dy = 0;

            if (lmdown || rmdown || mmdown)
            {
                dx  = e.X - mdx;
                dy  = e.Y - mdy;
                mdx = e.X;
                mdy = e.Y;
            }
            dx /= 2;
            dy /= 2;

            if (lmdown)
            {
                m_camera.RotateRightFlat((float)dx);
                m_camera.RotateUp((float)dy);
            }
            else if (mmdown)
            {
                m_camera.MoveForward((float)dy);
            }
            else if (rmdown)
            {
                m_camera.Move((float)dx, (float)dy);
            }

            if (UVDLPApp.Instance().SelectedObject != null)
            {
                if (m_movingobjectmode) // if we're moving an object
                {
                    // examine the last isect data
                    foreach (ISectData dat in hits)
                    {
                        if (dat.obj.tag == Object3d.OBJ_GROUND) //found the ground plane
                        {
                            UVDLPApp.Instance().SelectedObject.Translate(
                                (float)(dat.intersect.x - UVDLPApp.Instance().SelectedObject.m_center.x),
                                (float)(dat.intersect.y - UVDLPApp.Instance().SelectedObject.m_center.y),
                                0.0f);
                        }
                    }
                    if (UVDLPApp.Instance().SelectedObject.tag == Object3d.OBJ_SUPPORT)  // if the current selected object is a support
                    {
                        Support tmpsup = (Support)UVDLPApp.Instance().SelectedObject;
                        Point3d pnt    = new Point3d();
                        pnt.Set(tmpsup.m_center.x, tmpsup.m_center.y, 0);
                        Engine3D.Vector3d vec = new Engine3D.Vector3d();
                        vec.Set(0, 0, 1); // create a vector striaght up
                        // hit test from the selected objects center x/y/0 position straight up
                        //see if it hits any object in the scene,
                        // if it does, scale the object from the ground plane to the closest intersection point
                        List <ISectData> iss = RTUtils.IntersectObjects(vec, pnt, UVDLPApp.Instance().Engine3D.m_objects, false);
                        foreach (ISectData htd in iss)
                        {
                            if (htd.obj.tag != Object3d.OBJ_SUPPORT)  // if this is not another support or the ground
                            {
                                if (htd.obj.tag != Object3d.OBJ_GROUND)
                                {
                                    // this should be it...
                                    tmpsup.ScaleToHeight(htd.intersect.z);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            //glControl1.Invalidate();
            UpdateView();
        }