Esempio n. 1
0
        public ctl3DView()
        {
            InitializeComponent();
            //Visible = false;
            //SetupSceneTree();
            m_modelAnimTmr = null;
            m_camera       = new GLCamera();
            m_axisCam      = new GLCamera();
            ResetCameraView();
            m_isectnormal = new Engine3D.Vector3d();

            mainViewSplitContainer.Panel1Collapsed = true;

            UVDLPApp.Instance().m_undoer.AsociateUndoButton(buttUndo);
            UVDLPApp.Instance().m_undoer.AsociateRedoButton(buttRedo);

            //glControl1. = new GraphicsMode(GraphicsMode.Default.ColorFormat, GraphicsMode.Default.Depth, 8);
            gr2d                    = UVDLPApp.Instance().m_2d_graphics;
            ctlBgndList             = new List <ctlBgnd>();
            guiconf                 = UVDLPApp.Instance().m_gui_config;
            guiconf.TopLevelControl = mainViewSplitContainer.Panel2;
            UpdateButtonList();
            //guiconf.LoadConfiguration(global::UV_DLP_3D_Printer.Properties.Resources.GuiConfig);
            RearrangeGui();

            // toplevel controls must point to this

            glControl1.PaintCallback += new ctlGL.delPaint(DisplayFunc);

            m_sliceTex = -1;
            RegisterCallbacks();

            UVDLPApp.Instance().m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
            UVDLPApp.Instance().AppEvent += new AppEventDelegate(AppEventDel);
        }
Esempio n. 2
0
 //dot product
 public double Dot(Vector3d v)
 {
     double dp = ( x * v.x ) +
                ( y * v.y ) +
      	       ( z * v.z );
     return dp;
 }
Esempio n. 3
0
        public ctl3DView()
        {
            InitializeComponent();
            //Visible = false;
            //SetupSceneTree();
            m_modelAnimTmr = null;
            m_camera = new GLCamera();
            m_axisCam = new GLCamera();
            ResetCameraView();
            m_isectnormal = new Engine3D.Vector3d();

            mainViewSplitContainer.Panel1Collapsed = true;

            UVDLPApp.Instance().m_undoer.AsociateUndoButton(buttUndo);
            UVDLPApp.Instance().m_undoer.AsociateRedoButton(buttRedo);

            //glControl1. = new GraphicsMode(GraphicsMode.Default.ColorFormat, GraphicsMode.Default.Depth, 8);
            gr2d = UVDLPApp.Instance().m_2d_graphics;
            ctlBgndList = new List<ctlBgnd>();
            guiconf = UVDLPApp.Instance().m_gui_config;
            guiconf.TopLevelControl = mainViewSplitContainer.Panel2;
            UpdateButtonList();
            //guiconf.LoadConfiguration(global::UV_DLP_3D_Printer.Properties.Resources.GuiConfig);
            RearrangeGui();

            // toplevel controls must point to this

            glControl1.PaintCallback += new ctlGL.delPaint(DisplayFunc);            

            m_sliceTex = -1;
            RegisterCallbacks();

            UVDLPApp.Instance().m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
            UVDLPApp.Instance().AppEvent += new AppEventDelegate(AppEventDel);
        }
        public ctl3DView()
        {
            InitializeComponent();
            //Visible = false;
            //SetupSceneTree();
            m_modelAnimTmr = null;
            m_camera       = new GLCamera();
            m_axisCam      = new GLCamera();
            ResetCameraView();
            m_isectnormal = new Engine3D.Vector3d();

            mainViewSplitContainer.Panel1Collapsed = true;

            UVDLPApp.Instance().m_undoer.AsociateUndoButton(buttUndo);
            UVDLPApp.Instance().m_undoer.AsociateRedoButton(buttRedo);

            //glControl1. = new GraphicsMode(GraphicsMode.Default.ColorFormat, GraphicsMode.Default.Depth, 8);
            gr2d                    = UVDLPApp.Instance().m_2d_graphics;
            ctlBgndList             = new List <ctlBgnd>();
            guiconf                 = UVDLPApp.Instance().m_gui_config; // set from the main program GUIConfig
            guiconf.TopLevelControl = mainViewSplitContainer.Panel2;
            UpdateButtonList();
            RearrangeGui(); // once the GUIConfig is loaded from the plugins and from the main GUIConfig, the screen is re-arranged

            // toplevel controls must point to this

            glControl1.PaintCallback += new ctlGL.delPaint(DisplayFunc);

            m_sliceTex = -1;
            RegisterCallbacks();

            UVDLPApp.Instance().m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
            UVDLPApp.Instance().AppEvent += new AppEventDelegate(AppEventDel);
        }
Esempio n. 5
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.
            }
        }
Esempio n. 6
0
        public double Dot(Vector3d v) //dot product 
        {
	        double dp = ( x * v.x ) +
		               ( y * v.y ) +
		     	       ( z * v.z );
	        return dp;
        }
Esempio n. 7
0
        public ctl3DView()
        {
            InitializeComponent();
            //Visible = false;
            //SetupSceneTree();
            m_modelAnimTmr = null;
            m_camera = new GLCamera();
            m_axisCam = new GLCamera();
            ResetCameraView();
            m_isectnormal = new Engine3D.Vector3d();

            mainViewSplitContainer.Panel1Collapsed = true;

            UVDLPApp.Instance().m_undoer.AsociateUndoButton(buttUndo);
            UVDLPApp.Instance().m_undoer.AsociateRedoButton(buttRedo);

            //glControl1. = new GraphicsMode(GraphicsMode.Default.ColorFormat, GraphicsMode.Default.Depth, 8);
            gr2d = UVDLPApp.Instance().m_2d_graphics;
            ctlBgndList = new List<ctlBgnd>();
            guiconf = UVDLPApp.Instance().m_gui_config; // set from the main program GUIConfig
            guiconf.TopLevelControl = mainViewSplitContainer.Panel2;
            UpdateButtonList();
            RearrangeGui(); // once the GUIConfig is loaded from the plugins and from the main GUIConfig, the screen is re-arranged

            // toplevel controls must point to this

            glControl1.PaintCallback += new ctlGL.delPaint(DisplayFunc);

            m_sliceTex = -1;
            RegisterCallbacks();

            UVDLPApp.Instance().m_slicer.Slice_Event += new Slicer.SliceEvent(SliceEv);
            UVDLPApp.Instance().AppEvent += new AppEventDelegate(AppEventDel);
        }
Esempio n. 8
0
 public Vector3d Cross(Vector3d v) 
 {
     Vector3d cr = new Vector3d();
     cr.x = y * v.z - z * v.y;
     cr.y = z * v.x - x * v.z;
     cr.z = x * v.y - y * v.x;
     return cr;
 }
Esempio n. 9
0
        public bool m_wire; // draw wireframe

        #endregion Fields

        #region Constructors

        public Polygon()
        {
            m_normal = new Vector3d();
            m_color = Color.Gray;
            m_linecolor = Color.Blue;
            m_solid = true;
            m_wire = true;
            m_center = new Point3d();
        }
        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;
        }
Esempio n. 11
0
        static Vector3d newlen = new Vector3d(); // for calculating the radius of this poly

        #endregion Fields

        #region Constructors

        public Polygon()
        {
            m_normal = new Vector3d();
            m_radius = 0.0f;
            m_color = Color.Gray;
            m_center = new Point3d();
            m_minmax = new MinMax(); // really should be bounding box
            m_hidden = false;
            tag = TAG_REGULAR;
        }
Esempio n. 12
0
 public GLCamera()
 {
     viewmat = new Matrix3D();
     deg2rad = (float)(2.0 * Math.PI / 360.0);
     m_zaxis = new Vector3d(0, 0, 1);
     m_dx = m_dy = m_dz = 0;
     m_dir = 1.0f;
     m_bvscalexy = 4.0f;
     m_bvscaleh = 1.2f;
 }
Esempio n. 13
0
        public ctl3DView()
        {
            InitializeComponent();

            //SetupSceneTree();
            m_modelAnimTmr = null;
            m_camera = new GLCamera();
            ResetCameraView();
            m_isectnormal = new Engine3D.Vector3d();
            ctlViewOptions.TreeViewHolder = mainViewSplitContainer;
            ctlViewOptions.LayerNumberScroll = numLayer;
            ctlViewOptions.ObjectInfoPanel = objectInfoPanel;
            ctlViewOptions.SceneControl = ctlScene1;
            mainViewSplitContainer.Panel1Collapsed = true;

            UVDLPApp.Instance().m_undoer.AsociateUndoButton(buttUndo);
            UVDLPApp.Instance().m_undoer.AsociateRedoButton(buttRedo);

            //glControl1. = new GraphicsMode(GraphicsMode.Default.ColorFormat, GraphicsMode.Default.Depth, 8);
            gr2d = UVDLPApp.Instance().m_2d_graphics;
            ctlBgndList = new List<ctlBgnd>();
            guiconf = UVDLPApp.Instance().m_gui_config;
            guiconf.TopLevelControl = mainViewSplitContainer.Panel2;
            UpdateButtonList();
            guiconf.LoadConfiguration(global::UV_DLP_3D_Printer.Properties.Resources.GuiConfig);
            RearrangeGui();

            ctlObjScale.c3d = this;
            ctlObjRotate.c3d = this;
            ctlObjMove.c3d = this;
            ctlSupport.c3d = this;
            objectInfoPanel.c3d = this;
            ctlViewOptions.c3d = this;
            ctlMeshTools1.c3d = this;
            ctlScene1.c3d = this;

            /*ctlImageButton imbtn = new ctlImageButton();
            imbtn.BackColor = System.Drawing.Color.Navy;
            imbtn.CheckImage = null;
            imbtn.Image = global::UV_DLP_3D_Printer.Properties.Resources.homeButt;
            imbtn.Location = new System.Drawing.Point(200, 200);
            imbtn.Name = "buttGlHome";
            imbtn.Size = new System.Drawing.Size(48, 48);
            imbtn.TabIndex = 16;
            imbtn.Visible = true;

            mainViewSplitContainer.Panel2.Controls.Add(imbtn);
            imbtn.BringToFront();*/
            //buttGlHome.GLVisible = true;
            //buttGlHome.BackColor = Color.Transparent;
            //buttGlHome.FixStyle();
            //buttGlHome.BackColor = Color.FromArgb(60,0,0,0);

            m_sliceTex = -1;
        }
Esempio n. 14
0
 public ISectData(Object3d o, Polygon p, Point3d isect, Point3d orgin, Vector3d dir) 
 {
     intersect = new Point3d();
     intersect.Set(isect);
     origin = new Point3d();
     direction = new Vector3d();
     origin.Set(orgin);
     direction.Set(dir);
     obj = o;
     poly = p;
 }
Esempio n. 15
0
 public Polygon()
 {
     m_normal = new Vector3d();
     m_radius = 0.0;
     m_color = Color.Gray;
     m_linecolor = Color.Blue;
     m_solid = true;
     m_wire = true;
     m_center = new Point3d();
     m_minmax = null;
     plane = new Plane();
 }
 // create a look-at rotation matrix
 public void LookAt(Vector3d dir, Vector3d up)
 {
     //Vector3d dir = new Vector3d(direction.x, direction.y, direction.z);
     //dir.Normalize();
     Vector3d vx = up.Cross(dir);
     vx.Normalize();
     Vector3d vy = dir.Cross(vx);
     vy.Normalize();
     Matrix[0, 0] = vx.x;  Matrix[0, 1] = vx.y;  Matrix[0, 2] = vx.z;  Matrix[0, 3] = 0;
     Matrix[1, 0] = vy.x;  Matrix[1, 1] = vy.y;  Matrix[1, 2] = vy.z;  Matrix[1, 3] = 0;
     Matrix[2, 0] = dir.x; Matrix[2, 1] = dir.y; Matrix[2, 2] = dir.z; Matrix[2, 3] = 0;
     Matrix[3, 0] = 0;     Matrix[3, 1] = 0;     Matrix[3, 2] = 0;     Matrix[3, 3] = 1;
 }
        /*
        public class Config
        {
            int xres, yres;
           // double
        }
         * */
        public static bool FindIntersection(Vector3d direction, Point3d origin, ref Point3d intersect)
        {
            UVDLPApp.Instance().CalcScene();
            //bool intersected = false;

              //  Point3d bpoint, tpoint;
              //  Point3d lowest = new Point3d(); // the lowest point of intersection on the z axis
            direction.Normalize();
            direction.Scale(100.0);
            Point3d endp = new Point3d();
            endp.Set(origin);
            endp.x += direction.x;
            endp.y += direction.y;
            endp.z += direction.z;
            /*
            intersect = new Point3d();
            intersect.x = 0.0d;
            intersect.y = 0.0d;
            intersect.z = 0.0d;
            */
            //intersect the scene with a ray

               // intersected = false;
            foreach (Polygon p in UVDLPApp.Instance().Scene.m_lstpolys)
            {
                intersect = new Point3d();
                // try a less- costly sphere intersect here
                if (RTUtils.IntersectSphere(origin, endp, ref intersect, p.m_center, p.m_radius))
                {
                    // if it intersects,
                    if (RTUtils.IntersectPoly(p, origin, endp, ref intersect))
                    {
                        return true;
                        /*
                        // and it's the lowest one
                        if (intersect.z <= lowest.z)
                        {
                            //save this point
                            intersected = true;
                            lowest.Set(intersect);
                        }
                         * */
                    }
                }
            }

            return false;
        }
Esempio n. 18
0
        public void MoveForward(float dist)
        {
            float factor = Vector3d.length(m_eye - m_lookat) / 200.0f;
            if (factor < 0.3)
                factor = 0.3f;
            dist = dist * factor;

            Vector3d diff = (m_eye - m_lookat);
            float len = Vector3d.length(diff) - dist;
            if ((len <= 0) || (len >= 1000))
                return;
            diff.Normalize();
            diff = diff * (float)dist;
            m_eye = m_eye - diff;
            UpdateView();
        }
Esempio n. 19
0
 static void Initvecs() 
 {
     vecinit = true;
     u = new Vector3d();
     v = new Vector3d();
     n = new Vector3d();
     dir = new Vector3d();
     w0 = new Vector3d();
     w = new Vector3d();
     V = new Vector3d();
     temp = new Vector3d();
     IOendp = new Point3d();
     IOintersect = new Point3d();
     GPendp = new Point3d();
     GPintersect = new Point3d();
     m_isectlst = new List<ISectData>();
 }
Esempio n. 20
0
        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;
        }
Esempio n. 21
0
 // set rotation direction based on mouse location projected to 3D space
 public void UpdateDirection(float ix, float iy)
 {
     Vector3d mouse = new Vector3d(ix, iy, 0);
     Vector3d horizon = new Vector3d(m_right.x, m_right.y, 0);
     Vector3d perp = Vector3d.cross(mouse, horizon);
     m_dir = Math.Sign(perp.z);
 }
Esempio n. 22
0
 /*
  Test function to mark polygons facing doward a different color         
  */
 public void MarkPolysDown(double angle) 
 {
     Vector3d upvec = new Vector3d();
     double inc = 1.0 / 90.0;
     angle = -(1 - (angle * inc));
     upvec.Set(new Point3d(0,0,1));
     foreach (Polygon p in this.m_lstpolys) 
     {
         p.CalcNormal();
         double d = p.m_normal.Dot(upvec);
         if (d <= angle)  // facing down
         {
             p.tag = Polygon.TAG_MARKDOWN;
         }
         else 
         {
             p.tag = Polygon.TAG_REGULAR;
         }
     }
     InvalidateList();
 }
Esempio n. 23
0
        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();
        }
Esempio n. 24
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);
        }
Esempio n. 25
0
        public bool GenerateFromBitmap(string file, Vector3d f) 
        {
            try
            {
                m_name = Path.GetFileName(file);
                Bitmap bm = new Bitmap(file);
                // add 3d points
                for (int y = 0; y < bm.Height; y++) 
                {
                    for (int x = 0; x < bm.Width; x++) 
                    {
                        Color clr = bm.GetPixel(x, y);
                        Point3d pnt = new Point3d();
                        pnt.x = f.x * ((float)x);
                        pnt.y = f.y * ((float)y);
                        pnt.z = f.z * ((float)clr.R);
                        m_lstpoints.Add(pnt);
                    }
                }
                // now generate polys
                for (int y = 0; y < bm.Height  ; y++)
                {
                    for (int x = 0; x < bm.Width ; x++)
                    {
                        if (y == (bm.Height - 1)) continue;
                        if (x == (bm.Width - 1)) continue;
                        Polygon ply = new Polygon();
                        ply.m_points = new Point3d[3];
                        int idx1 = (y * bm.Width) + x;
                        int idx2 = (y * bm.Width) + x + 1;
                        int idx3 = (y * bm.Width) + x + bm.Width ;
                        ply.m_points[0] = (Point3d)m_lstpoints[idx1];
                        ply.m_points[1] = (Point3d)m_lstpoints[idx2];
                        ply.m_points[2] = (Point3d)m_lstpoints[idx3];
                        ply.CalcCenter();
                        ply.CalcNormal();
                        m_lstpolys.Add(ply);
                        
                       
                        Polygon ply2 = new Polygon();
                        ply2.m_points = new Point3d[3];
                        idx1 = (y * bm.Width) + x + 1;
                        idx2 = (y * bm.Width) + x + bm.Width + 1;
                        idx3 = (y * bm.Width) + x + bm.Width;
                        ply2.m_points[0] = (Point3d)m_lstpoints[idx1];
                        ply2.m_points[1] = (Point3d)m_lstpoints[idx2];
                        ply2.m_points[2] = (Point3d)m_lstpoints[idx3];

                        ply2.CalcCenter();
                        ply2.CalcNormal();
                        m_lstpolys.Add(ply2);
                         
                    }
                }
                Update();
                return true;
            }
            catch (Exception) 
            {
                return false;
            }
        }
Esempio n. 26
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.
            }
        }
Esempio n. 27
0
 public void RotateRightFlat(float deg, float dir)
 {
     Matrix3D rotMat = Rotate(m_zaxis, deg * dir);
     m_target = rotMat.Transform(m_target);
     m_right = rotMat.Transform(m_right);
     m_up = rotMat.Transform(m_up);
     /*m_target = m_lookat - m_eye;    // The "look-at" unit vector.
     m_target.Normalize();
     m_right = Vector3d.cross(m_target, m_up);*/
     UpdateView();
 }
        public List<Object3d> GenerateSupportObjects()
        {
            // iterate over the platform size by indicated mm step; // projected resolution in x,y
            // generate a 3d x/y point on z=0,
            // generate another on the z=zmax
            // use this ray to intersect the scene
            // foreach intersection point, generate a support
            // we gott make sure supports don't collide
            // I also have to take into account the
            // interface between the support and the model
            List<Object3d> lstsupports = new List<Object3d>();

            float ZVal = (float)UVDLPApp.Instance().m_printerinfo.m_PlatZSize;
            m_model.Update();
            float MinX = m_model.m_min.x;
            float MaxX = m_model.m_max.x;
            float MinY = m_model.m_min.y;
            float MaxY = m_model.m_max.y;

               // bool intersected = false;
            int scnt = 0; // support count
            // iterate from -HX to HX step xtep;
            double dts = (MaxX - MinX) / m_sc.xspace;
            int its = (int)dts;
            int curstep = 0;

            for (float x = (float)(MinX + (m_sc.xspace / 2.0f)); x < MaxX; x += (float)m_sc.xspace)
            {
                // say we're doing stuff
                RaiseSupportEvent(UV_DLP_3D_Printer.SupportEvent.eProgress, "" + curstep + "/" + its, null);
                curstep++;
                for (float y = (float)(MinY + (m_sc.yspace / 2)); y < MaxY; y += (float)m_sc.yspace)
                {
                    Point3d origin;
                    origin = new Point3d(); // bottom point
                    origin.Set(x, y, 0.0f);
                    //intersected = false; // reset the intersected flag to be false

                    Vector3d up = new Vector3d(); // the up vector
                    up.x = 0.0f;
                    up.y = 0.0f;
                    up.z = 1.0f;

                    List<ISectData> lstISects = RTUtils.IntersectObjects(up, origin, UVDLPApp.Instance().Engine3D.m_objects, false);
                    //check for cancelling
                    if (m_cancel)
                    {
                        RaiseSupportEvent(UV_DLP_3D_Printer.SupportEvent.eCancel, "Support Generation Cancelled", null);
                        return lstsupports;
                    }

                    foreach (ISectData htd in lstISects)
                    {
                        if (htd.obj.tag != Object3d.OBJ_SUPPORT)  // if this is not another support or the ground
                        {
                            if (htd.obj.tag != Object3d.OBJ_GROUND) // if it's not the ground
                            {
                                if (m_sc.m_onlydownward && htd.poly.tag != Polygon.TAG_MARKDOWN)
                                    break; // not a downward facing and we're only doing downward
                                // this should be the closest intersected
                                Support s = new Support();
                                float lz = (float)htd.intersect.z;
                                s.Create((float)m_sc.fbrad, (float)m_sc.ftrad, (float)m_sc.hbrad, (float)m_sc.htrad, lz * .2f, lz * .6f, lz * .2f, 11);
                                s.Translate((float)x, (float)y, 0);
                                s.Name = "Support " + scnt;
                                s.SetColor(Color.Yellow);
                                scnt++;
                                lstsupports.Add(s);
                                RaiseSupportEvent(UV_DLP_3D_Printer.SupportEvent.eSupportGenerated, s.Name, s);
                                break; // only need to make one support
                            }
                        }
                    }

                }
            }
            // return objects;
            RaiseSupportEvent(UV_DLP_3D_Printer.SupportEvent.eCompleted, "Support Generation Completed", lstsupports);
            m_generating = false;
            return lstsupports;
        }
Esempio n. 29
0
 public static Vector3d operator -(Point3d c1, Point3d c2)
 {
     Vector3d ret = new Vector3d();
     ret.Set(c1.x - c2.x, c1.y - c2.y, c1.z - c2.z);
     return ret;
 }
Esempio n. 30
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();
            }
        }
Esempio n. 31
0
 public void RotateUp(float deg)
 {
     Rotate(m_right, deg);
     // update target and up
     m_target = m_lookat - m_eye;    // The "look-at" unit vector.
     m_target.Normalize();
     m_up = Vector3d.cross(m_right, m_target);
     UpdateView();
 }
Esempio n. 32
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);
        }
Esempio n. 33
0
 public Vector3d Transform(Vector3d V)
 {
     Point3d pnt = new Point3d(V.x, V.y, V.z);
     pnt = Transform(pnt);
     return new Vector3d(pnt.x, pnt.y, pnt.z);
 }
        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)
            {
                orbitypos += (float)dx;
                orbitxpos += (float)dy;
                Vector2 vec = new Vector2(mdx,mdy);
                m_quat += arcball.Drag(vec);
                arcball.Click(vec);
                m_camera.RotateRightFlat((float)dx);
                m_camera.RotateUp((float)dy);
                //arcball.Click(vec);
                //ArcBall.drag(&MousePt, &ThisQuat);                  // Update End Vector And Get Rotation As Quaternion
                /*
                Matrix3fSetRotationFromQuat4f(&ThisRot, &ThisQuat);         // Convert Quaternion Into Matrix3fT
                Matrix3fMulMatrix3f(&ThisRot, &LastRot);                // Accumulate Last Rotation Into This One
                Matrix4fSetRotationFromMatrix3f(&Transform, &ThisRot);          // Set Our Final
                 * */
                // do the rotation
            }
            else if (mmdown)
            {
                orbitdist += (float)dy;
                m_camera.MoveForward((float)dy);
            }
            else if (rmdown)
            {
                yoffset += (float)dy / 2;
                xoffset += (float)dx / 2;
                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;
                                }
                            }
                        }
                    }
                }
            }
            DisplayFunc();
        }
        private List<ISectData> TestHitTest(int X, int Y)
        {
            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)
            {
                ISectData isect = (ISectData)isects[0]; // get the first
                ix = (float)isect.intersect.x; // show the closest
                iy = (float)isect.intersect.y;
                iz = (float)isect.intersect.z;
            }

            return isects;
        }
Esempio n. 36
0
        // rotate eye deg degrees arround rotAxis pivoting at target (m_lookat)
        protected Matrix3D Rotate(Vector3d rotAxis, float deg)
        {
            float rad = deg2rad * deg;
            float c = (float)Math.Cos(rad);
            float s = (float)Math.Sin(rad);
            float t = 1.0f - c;
            float x = rotAxis.x;
            float y = rotAxis.y;
            float z = rotAxis.z;
            Matrix3D rotMat= new Matrix3D(new float [] {
                t*x*x+c, t*x*y-s*z, t*x*z+s*y, 0,
                t*x*y+s*z, t*y*y+c, t*y*z-s*x, 0,
                t*x*z-s*y, t*y*z+s*x, t*z*z+c, 0,
                0,0,0,1
            });

            m_eye = rotMat.Transform(m_eye - m_lookat);
            m_eye = m_eye + m_lookat;
            return rotMat;
        }