コード例 #1
0
ファイル: FormMain.Load.cs プロジェクト: chantsunman/CSharpGL
 private void InitializeScene()
 {
     var camera = new Camera(new vec3(1, 2, 3), new vec3(0, 0, 0), new vec3(0, 1, 0),
        CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
     this.scene = new Scene(camera);
     var cameraManipulater = new FirstPerspectiveManipulater();
     cameraManipulater.Bind(camera, this.glCanvas1);
     this.cameraManipulater = cameraManipulater;
 }
コード例 #2
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(1, 0.6f, 1) * 14;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera)
            ;

            string       folder      = System.Windows.Forms.Application.StartupPath;
            string       objFilename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", "vnfHanoiTower.obj_");
            var          parser      = new ObjVNFParser(true);
            ObjVNFResult result      = parser.Parse(objFilename);

            if (result.Error != null)
            {
                MessageBox.Show(result.Error.ToString());
            }
            else
            {
                var   model = new ObjVNF(result.Mesh);
                var   node  = NormalNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                float max   = node.ModelSize.max();
                node.Scale         *= 16.0f / max;
                this.scene.RootNode = node;
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
コード例 #3
0
ファイル: FormMain.cs プロジェクト: weimingtom/CSharpGL
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(8, 6, 4) * 4;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.teapot = TeapotNode.Create(); this.teapot.Scale *= 3;
            teapot.Children.Add(new LegacyBoundingBoxNode(teapot.ModelSize));
            string folder   = System.Windows.Forms.Application.StartupPath;
            var    totalBmp = new Bitmap(System.IO.Path.Combine(folder, @"cubemaps_skybox.png"));

            this.skybox = SkyboxNode.Create(totalBmp); this.skybox.Scale *= 60;
            var group = new GroupNode(this.teapot, this.skybox);

            this.scene = new Scene(camera, this.winGLCanvas1)
            {
                RootElement = group,
            };

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);

            this.pickingAction = new PickingAction(scene);

            this.triangleTip = new LegacyTriangleNode();
            this.quadTip     = new LegacyQuadNode();
            this.chkRenderWireframe_CheckedChanged(this.chkRenderWireframe, EventArgs.Empty);
            this.chkRenderBody_CheckedChanged(this.chkRenderBody, EventArgs.Empty);
        }
コード例 #4
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(5, 3, 4) * 0.5f;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera, this.winGLCanvas1);
            {
                string       objFilename = "quad2.obj_";
                var          parser      = new ObjVNFParser(true);
                ObjVNFResult result      = parser.Parse(objFilename);
                if (result.Error != null)
                {
                    MessageBox.Show(result.Error.ToString());
                }
                else
                {
                    var   model = new ObjVNF(result.Mesh);
                    var   node  = BasicTessellationNode.Create(model);
                    float max   = node.ModelSize.max();
                    node.Scale                  *= 16.0f / max;
                    node.WorldPosition           = new vec3(0, 0, 0);
                    this.scene.RootElement       = node;
                    this.propGrid.SelectedObject = node;
                }
            }
            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
コード例 #5
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(1, 0.6f, 1) * 16;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene          = new Scene(camera);
            this.scene.RootNode = GetRootNode();
            // add lights.
            {
                var   lightList = this.lights;
                float angle     = 0;
                foreach (var light in lightList)
                {
                    this.scene.Lights.Add(light);
                    var node = LightPositionNode.Create(light, angle);
                    angle += 360.0f / lightList.Count;
                    this.scene.RootNode.Children.Add(node);
                }
            }
            var list            = new ActionList();
            var transformAction = new TransformAction(scene.RootNode);

            list.Add(transformAction);
            var blinnPhongAction = new BlinnPhongAction(scene);

            list.Add(blinnPhongAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            Match(this.trvScene, scene.RootNode);
            this.trvScene.ExpandAll();

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
コード例 #6
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var rootElement = GetTree();

            var position = new vec3(5, 3, 4);
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera)

            {
                RootElement = rootElement,
                ClearColor  = Color.SkyBlue.ToVec4(),
            };

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var billboardSortAction = new BillboardSortAction(scene);

            list.Add(billboardSortAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            var billboardRenderAction = new BillboardRenderAction(scene, billboardSortAction);

            list.Add(billboardRenderAction);
            this.actionList = list;

            Match(this.trvScene, scene.RootElement);
            this.trvScene.ExpandAll();

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.StepLength = 0.1f;
            manipulater.Bind(camera, this.winGLCanvas1);
        }
コード例 #7
0
ファイル: FormMain.cs プロジェクト: yh200212121212/CSharpGL
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(1, 0.6f, 1) * 14;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera, this.winGLCanvas1);

            string       objFilename = "nanosuit.obj_";
            var          parser      = new ObjVNFParser(true);
            ObjVNFResult result      = parser.Parse(objFilename);

            if (result.Error != null)
            {
                MessageBox.Show(result.Error.ToString());
            }
            else
            {
                var   model = new ObjVNF(result.Mesh);
                var   node  = NormalNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                float max   = node.ModelSize.max();
                node.Scale            *= 16.0f / max;
                this.scene.RootElement = node;
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
コード例 #8
0
ファイル: FormMain.cs プロジェクト: KiwiPapa/some_c_projects
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(1, 0.6f, 1) * 16;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene          = new Scene(camera);
            this.scene.RootNode = GetRootNode();

            var list = new ActionList();

            list.Add(new TransformAction(scene));
            list.Add(new RenderAction(scene));
            this.actionList = list;

            this.pickingAction = new Picking(scene);

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
コード例 #9
0
ファイル: FormMain.cs プロジェクト: KiwiPapa/some_c_projects
        private void FormMain_Load(object sender, EventArgs e)
        {
            var rootElement = GetRootElement();

            var position = new vec3(-3, 3, 4) * 0.5f;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera)
            {
                RootNode   = rootElement,
                ClearColor = Color.SkyBlue.ToVec4(),
            };

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            this.pickingAction = new Picking(scene);
            this.triangleTip   = new LegacyTriangleNode();
            this.quadTip       = new LegacyQuadNode();
            this.tipList.Add(this.triangleTip);
            this.tipList.Add(this.quadTip);

            Match(this.trvScene, scene.RootNode);
            this.trvScene.ExpandAll();

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.BindingMouseButtons = GLMouseButtons.Right;
            manipulater.Bind(camera, this.winGLCanvas1);
        }
コード例 #10
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(5, 4, 3) * 20;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene             = new Scene(camera, this.winGLCanvas1);
            this.scene.RootElement = GetRootElement();
            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
            manipulater.StepLength = 0.1f;
        }
コード例 #11
0
        public void gInit(Camera pcam, DateTime time, SceneNodeBase rootElement, Client client, Server server, FirstPerspectiveManipulater camManip, ActionList actionlist, Scene scene, WinGLCanvas canvas)
        {
            var position = new vec3(5, 3, 4);
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);

            pcam        = new Camera(position, center, up, CameraType.Perspective, canvas.Width, canvas.Height); // create the camera
            rootElement = new GroupNode();                                                                       // this will be the rootnode of the scene
            //CreateGameTree(rootElement);
            scene = new Scene(pcam)                                                                              // initialises the scene, use pcam as camera
            {
                RootNode   = rootElement,
                ClearColor = Color.Black.ToVec4(),
            };
            actionlist = new ActionList();
            //treeView1.ExpandAll();
            time = new DateTime();

            var list            = new ActionList();           // iniitialise the actionlist
            var transformAction = new TransformAction(scene); // transform action

            list.Add(transformAction);
            var billboardSortAction = new BillboardSortAction(scene.RootNode, scene.Camera); // billboard sort

            list.Add(billboardSortAction);
            var renderAction = new RenderAction(scene); // render

            list.Add(renderAction);
            var billboardRenderAction = new BillboardRenderAction(scene.Camera, billboardSortAction); // billboard render

            list.Add(billboardRenderAction);
            actionlist = list;
            camManip   = new FirstPerspectiveManipulater(); // allows moving the camera
            camManip.BindingMouseButtons = GLMouseButtons.Right;
            camManip.StepLength          = 0.1f;
            camManip.Bind(pcam, canvas);
        }
コード例 #12
0
ファイル: FormMain.cs プロジェクト: jackyped/CSharpGL
        private void FormMain_Load(object sender, EventArgs e)
        {
            var rootElement = GetTree();

            var position = new vec3(1, 1, 4);
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera)
            {
                RootNode   = rootElement,
                ClearColor = Color.SkyBlue.ToVec4(),
            };

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            Match(this.trvScene, scene.RootNode);
            this.trvScene.ExpandAll();
            var m = new FirstPerspectiveManipulater();

            m.Bind(camera, this.winGLCanvas1);

            BlendSrcFactor sf; BlendDestFactor df;

            helper.GetNext(out sf, out df);
            initialSF = sf; initialDF = df;
            this.winGLCanvas1.KeyPress += winGLCanvas1_KeyPress;
        }
コード例 #13
0
ファイル: FormMain.cs プロジェクト: skyformat99/CSharpGL
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(1, 0.6f, 1) * 14;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera)
            ;
            this.scene.RootElement = SmallQuadNode.Create();

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
コード例 #14
0
        private void Form_Load(object sender, EventArgs e)
        {
            foreach (var item in Enum.GetValues(typeof(PickingGeometryType)))
            {
                this.cmbPickingGeometryType.Items.Add(item);
            }
            this.cmbPickingGeometryType.SelectedIndex = 1;

            {
                var frmBulletinBoard = new FormBulletinBoard();
                //frmBulletinBoard.Dump = true;
                frmBulletinBoard.Show();
                this.bulletinBoard = frmBulletinBoard;
            }
            {
                //this.glCanvas1.ShowSystemCursor = false;
            }
            {
                // default(perspective)
                var camera = new Camera(
                    new vec3(15, 5, 0), new vec3(0, 0, 0), new vec3(0, 1, 0),
                    CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                var rotator = new FirstPerspectiveManipulater();
                rotator.StepLength = 0.5f;
                rotator.Bind(camera, this.glCanvas1);
                var scene = new Scene(camera, this.glCanvas1);
                //scene.Cursor.Enabled = false;
                this.scene = scene;
                ViewPort rootViewPort = scene.RootViewPort;
                rootViewPort.ClearColor = Color.White;
                ViewPort viewPort = rootViewPort.Children[0];
                viewPort.ClearColor = Color.Gray;
                viewPort.BeforeLayout += viewPort_BeforeLayout;
                viewPort.AfterLayout += perspectiveViewPort_AfterLayout;
                this.glCanvas1.Resize += scene.Resize;
            }
            {
                // top
                var camera = new Camera(
                new vec3(0, 0, 25), new vec3(0, 0, 0), new vec3(0, 1, 0),
                CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                ViewPort viewPort = new ViewPort(camera, AnchorStyles.None, new Padding(), new Size());
                viewPort.ClearColor = Color.Gray;
                viewPort.BeforeLayout += viewPort_BeforeLayout;
                viewPort.AfterLayout += topViewPort_AfterLayout;
                this.scene.RootViewPort.Children.Add(viewPort);
            }
            {
                // front
                var camera = new Camera(
                new vec3(0, 25, 0), new vec3(0, 0, 0), new vec3(0, 0, -1),
                CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                ViewPort viewPort = new ViewPort(camera, AnchorStyles.None, new Padding(), new Size());
                viewPort.ClearColor = Color.Gray;
                viewPort.BeforeLayout += viewPort_BeforeLayout;
                viewPort.AfterLayout += frontViewPort_AfterLayout;
                this.scene.RootViewPort.Children.Add(viewPort);
            }
            {
                // left
                var camera = new Camera(
                new vec3(-25, 0, 0), new vec3(0, 0, 0), new vec3(0, 0, -1),
                CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                ViewPort viewPort = new ViewPort(camera, AnchorStyles.None, new Padding(), new Size());
                viewPort.ClearColor = Color.Gray;
                viewPort.BeforeLayout += viewPort_BeforeLayout;
                viewPort.AfterLayout += leftViewPort_AfterLayout;
                this.scene.RootViewPort.Children.Add(viewPort);
            }
            {
                var uiAxis = new UIAxis(AnchorStyles.Left | AnchorStyles.Bottom,
              new Padding(3, 3, 3, 3), new Size(128, 128));
                uiAxis.Initialize();
                this.scene.RootUI.Children.Add(uiAxis);
            }
            {
                var font = new Font("Courier New", 32);
                var uiText = new UIText(AnchorStyles.Left | AnchorStyles.Bottom,
                    new Padding(0, 0, 0, 0), new Size(250, 20), -100, 100,
                   font.GetFontBitmap("[index: 0123456789]").GetFontTexture());
                uiText.Text = "";
                this.uiText = uiText;
                this.scene.RootUI.Children.Add(uiText);
            }
            {
                GroundRenderer ground = GroundRenderer.Create(new GroundModel(20));
                ground.Initialize();
                ground.Scale = new vec3(20, 20, 20);
                ground.WorldPosition = new vec3(0, 0, 0);
                SceneObject obj = ground.WrapToSceneObject(name: "Ground", generateBoundingBox: true);
                this.scene.RootObject.Children.Add(obj);
            }
            {
                bool useHighlightedPickingEffect = false;
                if (MessageBox.Show("Use highlighted picking effect?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    useHighlightedPickingEffect = true;
                }
                List<PickableRenderer> list = GetPickableRenderers();
                const float distance = 10;
                float sideCount = (float)Math.Sqrt(list.Count);
                int sideCounti = (int)sideCount;
                float x = -sideCount * distance / 2;
                float z = -sideCount * distance / 2;
                //float x = 0, z = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    PickableRenderer item = list[i];
                    SceneObject obj;
                    if (useHighlightedPickingEffect)
                    {
                        var model = item.DataSource;
                        var highlightRenderer = new HighlightRenderer(model, item.PositionNameInIBufferable);
                        var renderer = new HighlightedPickableRenderer(
                            highlightRenderer, item);
                        renderer.WorldPosition = new vec3(x, 2, z);
                        renderer.Initialize();
                        obj = renderer.WrapToSceneObject(generateBoundingBox: true);
                    }
                    else
                    {
                        item.WorldPosition = new vec3(x, 2, z);
                        obj = item.WrapToSceneObject(generateBoundingBox: true);
                    }
                    this.scene.RootObject.Children.Add(obj);

                    x += distance;
                    if (i % sideCounti == sideCounti - 1)
                    { z += distance; x = -sideCount * distance / 2; }
                }
            }
            {
                this.glCanvas1.MouseDown += glCanvas1_MouseDown;
                this.glCanvas1.MouseMove += glCanvas1_MouseMove;
                this.glCanvas1.MouseUp += glCanvas1_MouseUp;
            }
            {
                var builder = new StringBuilder();
                builder.AppendLine("1: Scene's property grid.");
                builder.AppendLine("2: Canvas' property grid.");
                builder.AppendLine("3: Form's property grid.");
                builder.AppendLine("4: Save to bitmap file.");
                builder.AppendLine("Ctrl+Mouse: Picking.");
                MessageBox.Show(builder.ToString());
            }
        }
コード例 #15
0
ファイル: Form1.cs プロジェクト: winterlutos/CSharpGL
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(5, 3, 4) * 1.6f;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene            = new Scene(camera);
            this.scene.ClearColor = Color.Black.ToVec4();
            {
                var groupNode = new GroupNode();//, attractorsNode);//, cubeNode);
                {
                    var node = ParticlesNode.Create(6000 / 128);
                    groupNode.Children.Add(node);
                }
                {
                    string       folder   = System.Windows.Forms.Application.StartupPath;
                    string       filename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", "floor.obj_");
                    var          parser   = new ObjVNFParser(true);
                    ObjVNFResult result   = parser.Parse(filename);
                    if (result.Error != null)
                    {
                        MessageBox.Show(result.Error.ToString());
                    }
                    else
                    {
                        ObjVNFMesh mesh  = result.Mesh;
                        var        model = new ObjVNF(mesh);
                        var        node  = NoShadowNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                        node.WorldPosition = new vec3(0, -3, 0);
                        node.Color         = new vec3(0, 1, 0);
                        node.Name          = filename;
                        groupNode.Children.Add(node);
                    }
                }

                //var attractorsNode = AttractorsNode.Create(particlesNode);
                //var cubeNode = CubeNode.Create();
                //cubeNode.RenderUnit.Methods[0].SwitchList.Add(new PolygonModeSwitch(PolygonMode.Line));
                this.scene.RootNode = groupNode;
            }
            {
                var light = new PointLight(new vec3(1, 1, 1) * 30);
                this.scene.Lights.Add(light);
            }

            {
                var list            = new ActionList();
                var transformAction = new TransformAction(scene.RootNode);
                list.Add(transformAction);
                var renderAction = new RenderAction(scene);
                list.Add(renderAction);
                var blinnPhongAction = new BlinnPhongAction(scene);
                list.Add(blinnPhongAction);
                this.actionList = list;
            }

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
コード例 #16
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var rootElement = GetRootElement();
            //var teapot = ShadowMappingRenderer.Create();
            //var rootElement = teapot;

            var position = new vec3(5, 3, 5) * 3;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera)
            {
                RootNode   = rootElement,
                ClearColor = Color.SkyBlue.ToVec4(),
            };
            {
                // add lights.
                var    list   = new List <LightBase>();
                double radian = 120.0 / 180.0 * Math.PI;
                {
                    var light = new CSharpGL.SpotLight(new vec3(3, 3, 3), new vec3(), (float)Math.Cos(radian), new Attenuation(2, 0, 0));
                    light.Diffuse  = new vec3(1, 0, 0);
                    light.Specular = new vec3(1, 0, 0);
                    list.Add(light);
                }
                {
                    var light = new CSharpGL.SpotLight(new vec3(3, 3, 3), new vec3(), (float)Math.Cos(radian), new Attenuation(2, 0, 0));
                    light.Diffuse  = new vec3(0, 1, 0);
                    light.Specular = new vec3(0, 1, 0);
                    list.Add(light);
                }
                {
                    var light = new CSharpGL.SpotLight(new vec3(3, 3, 3), new vec3(), (float)Math.Cos(radian), new Attenuation(2, 0, 0));
                    light.Diffuse  = new vec3(0, 0, 1);
                    light.Specular = new vec3(0, 0, 1);
                    list.Add(light);
                }
                for (int i = 0; i < list.Count; i++)
                {
                    var light = list[i];
                    var node  = LightPositionNode.Create(light, i * 360.0f / list.Count);

                    this.scene.Lights.Add(light);
                    this.scene.RootNode.Children.Add(node);
                }
            }

            Match(this.trvScene, scene.RootNode);
            this.trvScene.ExpandAll();

            var tansformAction = new TransformAction(scene);

            this.shadowMappingAction = new ShadowMappingAction(scene);
            var renderAction = new RenderAction(scene);
            var actionList   = new ActionList();

            actionList.Add(tansformAction); actionList.Add(shadowMappingAction); actionList.Add(renderAction);
            this.actionList = actionList;
            (new FormProperyGrid(shadowMappingAction)).Show();

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
コード例 #17
0
ファイル: FormMain.cs プロジェクト: jackyped/CSharpGL
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(5, 6, 4) * 3;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspecitive, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera);

            //(new FormTree(scene)).Show();

            this.scene.RootNode = new GroupNode();
            {
                var axisNode = AxisNode.Create();
                axisNode.Scale = new vec3(1, 1, 1) * 30;
                this.scene.RootNode.Children.Add(axisNode);
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            this.pickingAction = new Picking(scene);

            //this.triangleTip = new LegacyTriangleNode();
            //this.quadTip = new LegacyQuadNode();
            this.tipNode = HighlightGeometryNode.Create();

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
            {
                ObjItem[] items = HanoiTower.GetDataSource();
                for (int i = 0; i < items.Length; i++)
                {
                    var item     = items[i];
                    var filename = "item" + (i) + ".obj";
                    item.model.DumpObjFile(filename, "item" + (i));
                    var          parser = new ObjVNFParser(false);
                    ObjVNFResult result = parser.Parse(filename);
                    if (result.Error != null)
                    {
                        //Console.WriteLine("Error: {0}", result.Error);
                    }
                    else
                    {
                        ObjVNFMesh mesh = result.Mesh;
                        var        node = ObjVNFNode.Create(mesh);
                        node.Children.Add(new LegacyBoundingBoxNode(node.ModelSize));
                        //float max = node.ModelSize.max();
                        //node.Scale *= 7.0f / max;
                        node.WorldPosition = item.position;
                        node.Diffuse       = item.color;
                        var rootElement = this.scene.RootNode;
                        this.scene.RootNode.Children.Add(node);
                        //if (rootElement != null) { rootElement.Dispose(); }
                    }
                }
            }
        }
コード例 #18
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(9.3968f, -0.7408f, 2.9288f);
            var center   = new vec3(-0.0710f, -2.2829f, 1.3023f);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera);
            var rootNode = new GroupNode();

            this.scene.RootNode = rootNode;

            Texture texBRDF = LoadBRDFTexture();

            texBRDF.TextureUnitIndex = 2;
            Texture prefilterMap = LoadPrefilterMap();

            prefilterMap.TextureUnitIndex = 1;
            Texture irradianceMap = LoadIrradianceMap();

            irradianceMap.TextureUnitIndex = 0;
            Texture envCubemap = LoadEnvCubeMap();
            Texture texHDR     = LoadHDRTexture("environment.hdr");

            {
                var node = CubemapNode.Create(envCubemap, texHDR);
                rootNode.Children.Add(node);
            }
            {
                var node = IrradianceNode.Create(irradianceMap, envCubemap);
                rootNode.Children.Add(node);
            }
            {
                var node = PrefilterNode.Create(prefilterMap, envCubemap);
                rootNode.Children.Add(node);
            }
            {
                var node = BRDFNode.Create(texBRDF);
                rootNode.Children.Add(node);
            }
            {
                var textureGroups = new string[] { "cerberus", "cerberus", "gold", "grass", "plastic", "rock", "rusted_iron", "wall", "wood" };
                var models        = new ObjVNF[textureGroups.Length];
                {
                    var          filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "cerberus.obj_");
                    var          parser   = new ObjVNFParser(false, false);
                    ObjVNFResult result   = parser.Parse(filename);
                    if (result.Error != null)
                    {
                        MessageBox.Show(string.Format("Error: {0}", result.Error));
                        return;
                    }
                    ObjVNFMesh mesh = result.Mesh;
                    // scale it to 0.1 percent.
                    for (int i = 0; i < mesh.vertexes.Length; i++)
                    {
                        mesh.vertexes[i] = mesh.vertexes[i] / 10;
                    }
                    //// Dump texture coordinates' layout.
                    //{
                    //    vec2[] texCoords = mesh.texCoords;
                    //    int polygon = (mesh.faces[0] is ObjVNFTriangle) ? 3 : 4;
                    //    int index = 0;
                    //    var indices = new uint[polygon * mesh.faces.Length];
                    //    foreach (var face in mesh.faces) {
                    //        foreach (var vertexIndex in face.VertexIndexes()) {
                    //            indices[index++] = vertexIndex;
                    //        }
                    //    }
                    //    var bmp = TexCoordAnalyzer.DumpLines(texCoords, indices, 1024);
                    //    bmp.Save("cerberus.texCoords.png");
                    //}
                    var model = new ObjVNF(mesh);
                    models[0] = model;
                }
                {
                    var sphere   = new Sphere2();//(1, 40, 80);
                    var filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "sphere2.obj_");
                    sphere.DumpObjFile(filename, "sphere2");
                    var          parser = new ObjVNFParser(false, true);
                    ObjVNFResult result = parser.Parse(filename);
                    if (result.Error != null)
                    {
                        MessageBox.Show(string.Format("Error: {0}", result.Error));
                        return;
                    }
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new ObjVNF(mesh);
                    for (int i = 1; i < textureGroups.Length; i++)
                    {
                        models[i] = model;
                    }
                }

                for (int i = 0; i < textureGroups.Length; i++)
                {
                    ObjVNF model = models[i];
                    string group = textureGroups[i];
                    var    node  = PBRNode.Create(model, model.GetSize(),
                                                  ObjVNF.strPosition, ObjVNF.strTexCoord, ObjVNF.strNormal);
                    node.IrradianceMap = irradianceMap;
                    node.PrefilterMap  = prefilterMap;
                    node.texBRDF       = texBRDF;
                    Texture albedo = GetTexture(string.Format(@"Textures\{0}\albedo.png", group), 3);
                    node.AlbedoMap = albedo;
                    Texture ao = GetTexture(string.Format(@"Textures\{0}\ao.png", group), 4);
                    node.AOMap = ao;
                    Texture metallic = GetTexture(string.Format(@"Textures\{0}\metallic.png", group), 5);
                    node.MetallicMap = metallic;
                    Texture normal = GetTexture(string.Format(@"Textures\{0}\normal.png", group), 6);
                    node.NormalMap = normal;
                    Texture roughness = GetTexture(string.Format(@"Textures\{0}\roughness.png", group), 7);
                    node.RoughnessMap = roughness;
                    if (i == 0)
                    {
                        node.WorldPosition = new vec3(0, -5, 0);
                    }
                    else
                    {
                        node.WorldPosition = new vec3(
                            0.0f,
                            0.0f,
                            ((textureGroups.Length / 2.0f) - i) * spacing);
                    }
                    rootNode.Children.Add(node);
                }
            }
            {
                var backgroundNode = BackgroundNode.Create(envCubemap);
                rootNode.Children.Add(backgroundNode);
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
コード例 #19
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(-0.2f, 0, 1) * 14;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera);
            var rootNode = new GroupNode();

            this.scene.RootNode = rootNode;

            Texture texEnvCubemap = LoadEnvCubeMap();
            Texture texHDR        = LoadHDRTexture("newport_loft.hdr");

            {
                var cubemapNode = CubemapNode.Create(texEnvCubemap, texHDR);
                rootNode.Children.Add(cubemapNode);
            }
            {
                var sphere   = new Sphere2();//(1, 40, 80);
                var filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "sphere2.obj_");
                sphere.DumpObjFile(filename, "sphere2");
                var          parser = new ObjVNFParser(false, true);
                ObjVNFResult result = parser.Parse(filename);
                if (result.Error != null)
                {
                    Console.WriteLine("Error: {0}", result.Error);
                }
                else
                {
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new ObjVNF(mesh);
                    // render rows*column number of spheres with varying metallic/roughness values scaled by rows and columns respectively
                    for (int row = 0; row < nrRows; ++row)
                    {
                        for (int col = 0; col < nrColumns; ++col)
                        {
                            var node = PBRNode.Create(model, model.GetSize(),
                                                      ObjVNF.strPosition, ObjVNF.strTexCoord, ObjVNF.strNormal);
                            node.Metallic = (float)row / (float)nrRows;
                            // we clamp the roughness to 0.025 - 1.0 as perfectly smooth surfaces (roughness of 0.0) tend to look a bit off
                            // on direct lighting.
                            node.Roughness     = glm.clamp((float)col / (float)nrColumns, 0.05f, 1.0f);
                            node.WorldPosition = new vec3(
                                (col - (nrColumns / 2)) * spacing,
                                (row - (nrRows / 2)) * spacing,
                                0.0f);
                            rootNode.Children.Add(node);
                        }
                    }
                }
            }
            {
                var backgroundNode = BackgroundNode.Create(texEnvCubemap);
                rootNode.Children.Add(backgroundNode);
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
コード例 #20
0
ファイル: FormMain.cs プロジェクト: KiwiPapa/some_c_projects
        private void FormMain_Load(object sender, EventArgs e)
        {
            foreach (var item in Enum.GetNames(typeof(EnvironmentMappingNode.Ratio)))
            {
                this.cmbRatios.Items.Add(item);
            }

            var position = new vec3(8, 0, 4) * 3;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            string folder   = System.Windows.Forms.Application.StartupPath;
            var    totalBmp = new Bitmap(System.IO.Path.Combine(folder, @"cubemaps_skybox.png"));

            Bitmap[] bitmaps = GetBitmaps(totalBmp);
            this.skybox = SkyboxNode.Create(bitmaps); this.skybox.Scale *= 60;
            string       objFilename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", "vnfannulus.obj_");
            var          parser      = new ObjVNFParser(false);
            ObjVNFResult result      = parser.Parse(objFilename);

            if (result.Error != null)
            {
                MessageBox.Show(result.Error.ToString());
            }
            else
            {
                var model = new ObjVNF(result.Mesh);
                var node  = EnvironmentMappingNode.Create(
                    this.skybox.SkyboxTexture,
                    model, ObjVNF.strPosition, ObjVNF.strNormal);
                node.ModelSize = model.GetSize();
                float max = node.ModelSize.max();
                node.Scale        *= 20.0f / max;
                node.RotationAxis  = new vec3(0, 0, 1);
                node.RotationAngle = 90;
                node.Children.Add(new LegacyBoundingBoxNode(node.ModelSize));
                this.environmentMappingNode = node;

                var group = new GroupNode(this.environmentMappingNode, this.skybox);

                this.scene = new Scene(camera)
                {
                    RootNode = group,
                };

                var list            = new ActionList();
                var transformAction = new TransformAction(scene);
                list.Add(transformAction);
                var renderAction = new RenderAction(scene);
                list.Add(renderAction);
                this.actionList = list;

                var manipulater = new FirstPerspectiveManipulater();
                manipulater.Bind(camera, this.winGLCanvas1);

                this.pickingAction = new Picking(scene);

                this.triangleTip = new LegacyTriangleNode();
                this.quadTip     = new LegacyQuadNode();
            }
        }
コード例 #21
0
        private void Form_Load(object sender, EventArgs e)
        {
            foreach (var item in Enum.GetValues(typeof(GeometryType)))
            {
                this.cmbPickingGeometryType.Items.Add(item);
            }
            foreach (var item in Enum.GetValues(typeof(RenderModes)))
            {
                this.cmbRenderMode.Items.Add(item);
            }
            {
                var frmBulletinBoard = new FormBulletinBoard();
                //frmBulletinBoard.Dump = true;
                frmBulletinBoard.Show();
                this.bulletinBoard = frmBulletinBoard;
            }
            {
                //this.glCanvas1.ShowSystemCursor = false;
            }
            {
                var camera = new Camera(
                    new vec3(15, 5, 0), new vec3(0, 0, 0), new vec3(0, 1, 0),
                    CameraType.Perspecitive, this.glCanvas1.Width, this.glCanvas1.Height);
                var rotator = new FirstPerspectiveManipulater();
                rotator.StepLength = 0.5f;
                rotator.Bind(camera, this.glCanvas1);
                var scene = new Scene(camera, this.glCanvas1);
                //scene.Cursor.Enabled = false;
                this.scene             = scene;
                this.glCanvas1.Resize += scene.Resize;
            }
            {
                var uiAxis = new UIAxis(AnchorStyles.Left | AnchorStyles.Bottom,
                                        new Padding(3, 3, 3, 3), new Size(128, 128));
                uiAxis.Initialize();
                this.scene.UIRoot.Children.Add(uiAxis);
            }
            {
                var font   = new Font("Courier New", 32);
                var uiText = new UIText(AnchorStyles.Left | AnchorStyles.Bottom,
                                        new Padding(0, 0, 0, 0), new Size(250, 20), -100, 100,
                                        font.GetFontBitmap("[index: 0123456789]").GetFontTexture());
                uiText.Text = "";
                this.uiText = uiText;
                this.scene.UIRoot.Children.Add(uiText);
            }
            {
                GroundRenderer ground = GroundRenderer.Create(new GroundModel(20));
                ground.Initialize();
                ground.Scale         = new vec3(20, 20, 20);
                ground.WorldPosition = new vec3(0, 0, 0);
                SceneObject obj = ground.WrapToSceneObject(name: "Ground", generateBoundingBox: true);
                this.scene.RootObject.Children.Add(obj);
            }
            {
                bool useHighlightedPickingEffect = false;
                if (MessageBox.Show("Use highlighted picking effect?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    useHighlightedPickingEffect = true;
                }
                List <PickableRenderer> list     = GetPickableRenderers();
                const float             distance = 10;
                float sideCount  = (float)Math.Sqrt(list.Count);
                int   sideCounti = (int)sideCount;
                float x          = -sideCount * distance / 2;
                float z          = -sideCount * distance / 2;
                //float x = 0, z = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    PickableRenderer item = list[i];
                    SceneObject      obj;
                    if (useHighlightedPickingEffect)
                    {
                        var model             = item.Model;
                        var highlightRenderer = new HighlightRenderer(model, item.PositionNameInIBufferable);
                        var renderer          = new HighlightedPickableRenderer(
                            highlightRenderer, item);
                        renderer.WorldPosition = new vec3(x, 2, z);
                        renderer.Initialize();
                        obj = renderer.WrapToSceneObject(generateBoundingBox: true);
                    }
                    else
                    {
                        item.WorldPosition = new vec3(x, 2, z);
                        obj = item.WrapToSceneObject(generateBoundingBox: true);
                    }
                    this.scene.RootObject.Children.Add(obj);

                    x += distance;
                    if (i % sideCounti == sideCounti - 1)
                    {
                        z += distance; x = -sideCount * distance / 2;
                    }
                }
            }
            {
                this.glCanvas1.MouseDown += glCanvas1_MouseDown;
                this.glCanvas1.MouseMove += glCanvas1_MouseMove;
                this.glCanvas1.MouseUp   += glCanvas1_MouseUp;
            }
            {
                var builder = new StringBuilder();
                builder.AppendLine("1: Scene's property grid.");
                builder.AppendLine("2: Canvas' property grid.");
                builder.AppendLine("3: Form's property grid.");
                builder.AppendLine("4: Save to bitmap file.");
                MessageBox.Show(builder.ToString());
            }
        }
コード例 #22
0
ファイル: FormMain.cs プロジェクト: KiwiPapa/some_c_projects
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(-0.2f, 0, 1) * 14;
            var center   = new vec3(0, 0, 0);
            var up       = new vec3(0, 1, 0);
            var camera   = new Camera(position, center, up, CameraType.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera);
            var rootNode = new GroupNode();

            this.scene.RootNode = rootNode;

            Texture albedoMap    = GetTexture(@"Textures\albedo.png", 0);
            Texture normalMap    = GetTexture(@"Textures\normal.png", 1);
            Texture metallicMap  = GetTexture(@"Textures\metallic.png", 2);
            Texture roughnessMap = GetTexture(@"Textures\roughness.png", 3);
            Texture aoMap        = GetTexture(@"Textures\ao.png", 4);

            {
                var sphere   = new Sphere2(); // Sphere(1, 40, 80);
                var filename = Path.Combine(System.Windows.Forms.Application.StartupPath, "sphere2.obj_");
                sphere.DumpObjFile(filename, "sphere2");
                var          parser = new ObjVNFParser(false, true);
                ObjVNFResult result = parser.Parse(filename);
                if (result.Error != null)
                {
                    Console.WriteLine("Error: {0}", result.Error);
                }
                else
                {
                    ObjVNFMesh mesh  = result.Mesh;
                    var        model = new ObjVNF(mesh);
                    // render rows*column number of spheres with varying metallic/roughness values scaled by rows and columns respectively
                    for (int row = 0; row < nrRows; ++row)
                    {
                        for (int col = 0; col < nrColumns; ++col)
                        {
                            var node = PBRNode.Create(model, model.GetSize(),
                                                      ObjVNF.strPosition, ObjVNF.strTexCoord, ObjVNF.strNormal);
                            node.AlbedoMap     = albedoMap;
                            node.NormalMap     = normalMap;
                            node.MetallicMap   = metallicMap;
                            node.RoughnessMap  = roughnessMap;
                            node.AOMap         = aoMap;
                            node.WorldPosition = new vec3(
                                (col - (nrColumns / 2)) * spacing,
                                (row - (nrRows / 2)) * spacing,
                                0.0f);
                            rootNode.Children.Add(node);
                        }
                    }
                }
            }

            var list            = new ActionList();
            var transformAction = new TransformAction(scene);

            list.Add(transformAction);
            var renderAction = new RenderAction(scene);

            list.Add(renderAction);
            this.actionList = list;

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }