예제 #1
0
 public void BeginRender()
 {
     Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
     Gl.glMatrixMode(Gl.GL_PROJECTION);
     Gl.glLoadIdentity();
     Glu.gluPerspective(100, engine.GetWidth() / engine.GetHeight(), 0.1f, 1000.0f);
     Glu.gluLookAt(engine.GetCamera().posX, engine.GetCamera().posY, engine.GetCamera().posZ,
                   engine.GetCamera().lookX, engine.GetCamera().lookY, engine.GetCamera().lookZ,
                   0, 1, 0);
     Gl.glMatrixMode(Gl.GL_MODELVIEW);
 }
예제 #2
0
파일: Form1.cs 프로젝트: Winster332/Paint3D
        private void Form1_Load(object sender, EventArgs e)
        {
            glControl.Location = new Point(0, 0);
            glControl.Size     = new Size(this.Width, this.Height);
            engine             = new Core.GEngine(glControl);
            engine.Run();

            glControl.KeyDown += (o, ee) =>
            {
                if (ee.KeyCode == Keys.Escape)
                {
                    if (engine.GetCamera().IsMouseLock)
                    {
                        engine.GetCamera().IsMouseLock = false;
                        Cursor.Show();
                        ShowUI();
                    }
                    else
                    {
                        engine.GetCamera().IsMouseLock = true;
                        Cursor.Hide();
                        HideUI();
                    }
                }
            };

            menuPanel         = new Core.UI.GMenuPanel(glControl, engine);
            menuPanel.Clicks += (o, ee) =>
            {
                string name = ((Button)o).Text.ToString();

                switch (name)
                {
                case "Продолжить":
                    engine.GetCamera().IsMouseLock = true;
                    Cursor.Hide();
                    HideUI();
                    glControl.Focus();
                    break;

                case "Загрузить":
                    OpenFileDialog ofd = new OpenFileDialog();
                    ofd.Multiselect = false;
                    DialogResult res = ofd.ShowDialog(this);
                    if (res == DialogResult.OK)
                    {
                        string file = ofd.FileName;

                        List <Core.Models.GSaveObject> objs = (List <Core.Models.GSaveObject>)
                                                              engine.GetManagerFile().GetDataXMLFile(file, typeof(List <Core.Models.GSaveObject>));

                        for (int i = 0; i < objs.Count; i++)
                        {
                            if (objs[i].type == Core.Models.GSaveObject.TYPE.Cube)
                            {
                                engine.GetWorld().AddBox(objs[i].x, objs[i].y, objs[i].z, objs[i].rad, objs[i].r, objs[i].g, objs[i].b);
                            }
                            else if (objs[i].type == Core.Models.GSaveObject.TYPE.Sphere)
                            {
                                engine.GetWorld().AddSphere(objs[i].x, objs[i].y, objs[i].z, objs[i].rad, objs[i].r, objs[i].g, objs[i].b);
                            }
                        }
                    }

                    break;

                case "Сохранить":
                    Core.UI.SaveObjects so = new Core.UI.SaveObjects(engine);
                    so.ShowDialog(this);
                    break;

                case "Выйти": Application.Exit(); break;
                }
            };
            bool IsCube = true;

            propPanel         = new Core.UI.GPropPanel(glControl);
            propPanel.Clicks += (o, ee) =>
            {
                string   name  = ((Button)o).Text.ToString();
                double[] color = propPanel.GetColor();

                switch (name)
                {
                case "Кубик":
                    IsCube = true;
                    break;

                case "Сфера":
                    IsCube = false;
                    break;
                }
                ;

                this.Text = name + " размер[" + propPanel.GetSize() + "] Цвет[R:" + color[0] + " G:" + color[1] + " B:" + color[2] + "]";
            };

            glControl.MouseDown += (o, ee) =>
            {
                if (engine.GetCamera().IsMouseLock)
                {
                    double[] color = propPanel.GetColor();
                    float    size  = propPanel.GetSize();
                    glControl.Focus();

                    if (IsCube)
                    {
                        engine.GetWorld().AddBox(engine.GetCamera().posX + engine.GetCamera().lookX / 50, engine.GetCamera().posY + engine.GetCamera().lookY / 50, engine.GetCamera().posZ + engine.GetCamera().lookZ / 50, size, (float)color[0], (float)color[1], (float)color[2]);
                    }
                    else
                    {
                        engine.GetWorld().AddSphere(engine.GetCamera().posX + engine.GetCamera().lookX / 50, engine.GetCamera().posY + engine.GetCamera().lookY / 50, engine.GetCamera().posZ + engine.GetCamera().lookZ / 50, size, (float)color[0], (float)color[1], (float)color[2]);
                    }
                }
            };
        }