Exemplo n.º 1
0
        public static Point3d operator +(Point3d c1, Vector3d c2)
        {
            Point3d ret = new Point3d();

            ret.Set(c1.x + c2.x, c1.y + c2.y, c1.z + c2.z);
            return(ret);
        }
Exemplo n.º 2
0
        public void FindMinMax()
        {
            Point3d first = (Point3d)this.m_lstpoints[0];

            m_min.Set(first.x, first.y, first.z, 0.0);
            m_max.Set(first.x, first.y, first.z, 0.0);
            foreach (Point3d p in this.m_lstpoints)
            {
                if (p.x < m_min.x)
                {
                    m_min.x = p.x;
                }
                if (p.y < m_min.y)
                {
                    m_min.y = p.y;
                }
                if (p.z < m_min.z)
                {
                    m_min.z = p.z;
                }

                if (p.x > m_max.x)
                {
                    m_max.x = p.x;
                }
                if (p.y > m_max.y)
                {
                    m_max.y = p.y;
                }
                if (p.z > m_max.z)
                {
                    m_max.z = p.z;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// This function is designed to move a support by it's tip
        /// it will angle up from the s5i index and position the points to intersect around the
        /// specified tip point,
        /// all points below s5i  -
        /// 1) could stay where they are
        /// 2) or move to be a relative distance from the tip - 5mm or so in the direction of vec
        /// </summary>
        /// <param name="tip"></param>
        public void MoveFromTip(Point3d tip, Vector3d vec)
        {
            //starting at s5i, center all points around this.
            Point3d diff = new Point3d();

            ScaleToHeight(tip.z * .85);
            Point3d center;

            // first, move along the vec in the direction of the vector
            center = CalcCentroid(0, s5i);
            diff.Set(tip.x + vec.x - center.x, tip.y + vec.y - center.y, 0.0f); // only slide along the x/y plane
            TranslateRange(diff, 0, s5i);

            center = CalcCentroid(s5i, m_lstpoints.Count);
            diff.Set(tip.x - center.x, tip.y - center.y, tip.z - center.z);
            TranslateRange(diff, s5i, m_lstpoints.Count);
            Update();
        }
Exemplo n.º 4
0
 public void CalcCenter()
 {
     m_center.Set(0, 0, 0, 0);
     foreach (Point3d pnt in m_points)
     {
         m_center.x += pnt.x;
         m_center.y += pnt.y;
         m_center.z += pnt.z;
     }
     m_center.x /= m_points.Length; // number of points
     m_center.y /= m_points.Length; // number of points
     m_center.z /= m_points.Length; // number of points
 }
Exemplo n.º 5
0
 //Estimating the centroid
 public void CalcCenter()
 {
     m_center = new Point3d();
     m_center.Set(0, 0, 0);
     foreach (Point3d pnt in m_points)
     {
         m_center.x += pnt.x;
         m_center.y += pnt.y;
         m_center.z += pnt.z;
     }
     m_center.x /= m_points.Count;
     m_center.y /= m_points.Count;
     m_center.z /= m_points.Count;
 }
Exemplo n.º 6
0
        public Point3d CalcCenter()
        {
            Point3d center = new Point3d();

            center.Set(0, 0, 0, 0);
            foreach (Point3d p in m_lstpoints)
            {
                center.x += p.x;
                center.y += p.y;
                center.z += p.z;
            }

            center.x /= m_lstpoints.Count;
            center.y /= m_lstpoints.Count;
            center.z /= m_lstpoints.Count;

            return(center);
        }
Exemplo n.º 7
0
        public void CalcCenter()
        {
            try
            {
                m_center.Set(0, 0, 0);

                foreach (Point3d pnt in m_points)
                {
                    m_center.x += pnt.x;
                    m_center.y += pnt.y;
                    m_center.z += pnt.z;
                }
                m_center.x /= m_points.Length; // number of points
                m_center.y /= m_points.Length; // number of points
                m_center.z /= m_points.Length; // number of points
            }catch (Exception ex)
            {
                DebugLogger.Instance().LogError(ex.Message);
            }
        }
Exemplo n.º 8
0
        private Object3d ConvertFrom(List<csgjs_polygon> lstply) 
        {
            Object3d obj = new Object3d();
            for (int i = 0; i < lstply.Count; i++)
            {
                csgjs_polygon poly = lstply[i];

                for (int j = 2; j < poly.vertices.Count; j++)
                {
                    Polygon ply = new Polygon(); // create a new polygon
                    ply.m_points = new Point3d[3];
                    obj.m_lstpolys.Add(ply); //add it to the list

                    Point3d p0 = new Point3d();
                    Point3d p1 = new Point3d();
                    Point3d p2 = new Point3d();

                    p0.Set(poly.vertices[0].pos.x, poly.vertices[0].pos.y, poly.vertices[0].pos.z);
                    p1.Set(poly.vertices[j - 1].pos.x, poly.vertices[j - 1].pos.y, poly.vertices[j - 1].pos.z);
                    p2.Set(poly.vertices[j].pos.x, poly.vertices[j].pos.y, poly.vertices[j].pos.z);

                    ply.m_points[0] = p0;
                    ply.m_points[1] = p1;
                    ply.m_points[2] = p2;

                    obj.m_lstpoints.Add(p0);
                    obj.m_lstpoints.Add(p1);
                    obj.m_lstpoints.Add(p2);
                }
            }
            obj.Update();
            return obj;
        }
Exemplo n.º 9
0
        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 (UVDLPApp.Instance().SelectedObject != null)
            {
                if (m_movingobjectmode) // if we're moving an object
                {
                    List<ISectData> hits = TestHitTest(e.X, e.Y); // really only need to hit-test ground
                    // 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);
                            //UVDLPApp.Instance().Engine3D.UpdateLists();
                            //UpdateView();
                        }

                    }
                    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);
                        bool foundObject = false;
                        foreach (ISectData htd in iss)
                        {
                            if (htd.obj.tag == Object3d.OBJ_NORMAL)  // if this is not another support or the ground
                            {
                                // this should be it...
                                tmpsup.ScaleToHeight(htd.intersect.z);
                                //set the parent object
                                 tmpsup.m_supporting = htd.obj;
                                htd.obj.AddSupport(tmpsup);
                                foundObject = true;
                                break;
                            }
                        }
                        if (!foundObject && (tmpsup.m_parrent != null))
                        {
                            tmpsup.m_parrent.RemoveSupport(tmpsup);
                        }
                    }
                    UpdateView();
                }                
            }
            //UpdateView(false);
        }
Exemplo n.º 10
0
        private List<ISectData> TestHitTest(int X, int Y)
        {
            if (!loaded)
                return null;
           // String mess = "";
           // mess = "Screen X,Y = (" + X.ToString() + "," + Y.ToString() + ")\r\n";

            /*
            (Note that most window systems place the mouse coordinate origin in the upper left of the window instead of the lower left. 
            That's why window_y is calculated the way it is in the above code. When using a glViewport() that doesn't match the window height,
            the viewport height and viewport Y are used to determine the values for window_y and norm_y.)

            The variables norm_x and norm_y are scaled between -1.0 and 1.0. Use them to find the mouse location on your zNear clipping plane like so:

            float y = near_height * norm_y;
            float x = near_height * aspect * norm_x;
            Now your pick ray vector is (x, y, -zNear).             
             */
            int w = glControl1.Width;
            int h = glControl1.Height;
          //  mess += "Screen Width/Height = " + w.ToString() + "," + h.ToString() + "\r\n";
            float aspect = ((float)glControl1.Width) / ((float)glControl1.Height);
            //mess += "Screen Aspect = " + aspect.ToString() + "\r\n";

            int window_y = (h - Y) - h / 2;
            double norm_y = (double)(window_y) / (double)(h / 2);
            int window_x = X - w / 2;
            double norm_x = (double)(window_x) / (double)(w / 2);
            float near_height = .2825f; // no detectable error

            float y = (float)(near_height * norm_y);
            float x = (float)(near_height * aspect * norm_x);

            /*
            To transform this eye coordinate pick ray into object coordinates, multiply it by the inverse of the ModelView matrix in use 
            when the scene was rendered. When performing this multiplication, remember that the pick ray is made up of a vector and a point, 
            and that vectors and points transform differently. You can translate and rotate points, but vectors only rotate. 
            The way to guarantee that this is working correctly is to define your point and vector as four-element arrays, 
            as the following pseudo-code shows:

            float ray_pnt[4] = {0.f, 0.f, 0.f, 1.f};
            float ray_vec[4] = {x, y, -near_distance, 0.f};
            The one and zero in the last element determines whether an array transforms as a point or a vector when multiplied by the 
            inverse of the ModelView matrix.*/
            Vector4 ray_pnt = new Vector4(0.0f, 0.0f, 0.0f, 1.0f);
            //Vector4 ray_vec = new Vector4((float)norm_x, (float)norm_y, -1.0f, 0);
            Vector4 ray_vec = new Vector4((float)x, (float)y, -1f, 0);
            ray_vec.Normalize();

            //mess += "Eye Pick Vec =  (" + String.Format("{0:0.00}", ray_vec.X) + ", " + String.Format("{0:0.00}", ray_vec.Y) + "," + String.Format("{0:0.00}", ray_vec.Z) + ")\r\n";

            Matrix4 modelViewMatrix;
            GL.GetFloat(GetPName.ModelviewMatrix, out modelViewMatrix);
            Matrix4 viewInv = Matrix4.Invert(modelViewMatrix);

            Vector4 t_ray_pnt = new Vector4();
            Vector4 t_ray_vec = new Vector4();

            Vector4.Transform(ref ray_vec, ref viewInv, out t_ray_vec);
            Vector4.Transform(ref ray_pnt, ref viewInv, out t_ray_pnt);
            //mess += "World Pick Vec =  (" + String.Format("{0:0.00}", t_ray_vec.X) + ", " + String.Format("{0:0.00}", t_ray_vec.Y) + "," + String.Format("{0:0.00}", t_ray_vec.Z) + ")\r\n";
            //mess += "World Pick Pnt =  (" + String.Format("{0:0.00}", t_ray_pnt.X) + ", " + String.Format("{0:0.00}", t_ray_pnt.Y) + "," + String.Format("{0:0.00}", t_ray_pnt.Z) + ")\r\n";

            Point3d origin = new Point3d();
            Point3d intersect = new Point3d();
            Engine3D.Vector3d dir = new Engine3D.Vector3d();

            origin.Set(t_ray_pnt.X, t_ray_pnt.Y, t_ray_pnt.Z);
            dir.Set(t_ray_vec.X, t_ray_vec.Y, t_ray_vec.Z); // should this be scaled?

            List<ISectData> isects = RTUtils.IntersectObjects(dir, origin, UVDLPApp.Instance().Engine3D.m_objects, true);
            if (isects.Count > 0)
            {

                foreach (ISectData isect in isects)
                {
                    if (!float.IsNaN(isect.intersect.x)) // check for NaN
                    {
                        m_ix = (float)isect.intersect.x; // show the closest
                        m_iy = (float)isect.intersect.y;
                        m_iz = (float)isect.intersect.z;
                        isect.poly.CalcNormal();
                        m_isectnormal.x = isect.poly.m_normal.x;
                        m_isectnormal.y = isect.poly.m_normal.y;
                        m_isectnormal.z = isect.poly.m_normal.z;

                        break;
                    }
                }

                //ISectData isect = (ISectData)isects[0]; // get the first
                // check for NaN

            }

            return isects;
        }
Exemplo n.º 11
0
 public static Point3d operator +(Point3d c1, Vector3d c2)
 {
     Point3d ret = new Point3d();
     ret.Set(c1.x + c2.x, c1.y + c2.y, c1.z + c2.z);
     return ret;
 }
Exemplo n.º 12
0
        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();
                }
        }
Exemplo n.º 13
0
 public void Set(Vector3d normal, Point3d pnt)
 {
     _normal.Set(normal.x, normal.y, normal.z);
     _pnt.Set(pnt);
 }