Ejemplo n.º 1
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            var position = new vec3(5, 3, 4) * 2f;
            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 light = new PointLight(new vec3(1, 1, 1) * 30);
                this.scene.Lights.Add(light);
            }
            {
                var group = new GroupNode();
                {
                    var node = ParticleNode.Create(6000);
                    group.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;
                        group.Children.Add(node);
                    }
                }

                this.scene.RootNode = group;
            }

            {
                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);
        }
Ejemplo n.º 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);
            (new FormProperyGrid(this.scene)).Show();
            {
                var light = new DirectionalLight(new vec3(1, 1, 1));
                this.scene.Lights.Add(light);
            }

            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  = NoShadowNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                float max   = node.ModelSize.max();
                node.Scale         *= 16.0f / max;
                this.scene.RootNode = node;
                (new FormProperyGrid(node)).Show();
            }

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

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

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

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);
        }
Ejemplo n.º 3
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);
        }