示例#1
0
        private void pbPrincipal_MouseMove(object sender, MouseEventArgs e)
        {
            x2 = e.X;
            y2 = e.Y;
            int dx = x2 - x1;
            int dy = y2 - y1;

            if (e.Button == MouseButtons.Left)
            {
                //x, y rotation
                if (Math.Abs(dx) > 7 || Math.Abs(dy) > 7)
                {
                    Bitmap b = new Bitmap(pbPrincipal.Width, pbPrincipal.Height);
                    actobj.rotationX(dy);
                    actobj.rotationY(-dx);
                    actobj.setNFaces();
                    if (tbDistancia.Text == "")
                    {
                        actobj.setNewActuals();
                        desenhaObjeto('a');
                    }
                    else
                    {
                        desenhaObjeto('p');
                    }

                    x1 = x2;
                    y1 = y2;
                }
            }
            else if (e.Button == MouseButtons.Right && actobj != null)
            {
                //x, y translation
                if (Math.Abs(dx) > 15 || Math.Abs(dy) > 15)
                {
                    Bitmap b = new Bitmap(pbPrincipal.Width, pbPrincipal.Height);
                    actobj.translation(dx, dy, 0);
                    actobj.setNFaces();
                    if (tbDistancia.Text == "")
                    {
                        actobj.setNewActuals();
                        desenhaObjeto('a');
                    }
                    else
                    {
                        desenhaObjeto('p');
                    }

                    x1 = x2;
                    y1 = y2;
                }
            }
        }
示例#2
0
        public static Object3D readObj(StreamReader sr)
        {
            Object3D obj = new Object3D();

            String[] s, s1;
            Face     f;
            String   line = sr.ReadLine();

            while (line != null)
            {
                s = line.Split(' ');
                //add vertex
                if (s[0].Equals("v"))
                {
                    obj.addOriginals(new Vertex(Convert.ToDouble(s[1].Replace(".", ",")), Convert.ToDouble(s[2].Replace(".", ",")), Convert.ToDouble(s[3].Replace(".", ","))));
                }

                //add face
                else if (s[0].Equals("f"))
                {
                    f = new Face();
                    if (s[s.Length - 1] == "")
                    {
                        Array.Resize(ref s, 3);
                    }
                    for (int i = 1; i < s.Length; i++)
                    {
                        s1 = s[i].Split('/');

                        f.addVertex(Convert.ToInt32(s1[0]) - 1);
                    }
                    obj.addFaces(f);
                }
                //add texture
                //else if ()

                line = sr.ReadLine();
            }
            obj.setActuals(obj.getOriginals());
            obj.setNFaces();

            return(obj);
        }