示例#1
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, "nanosuit.obj_");
            var          parser      = new ObjVNFParser(false);
            ObjVNFResult result      = parser.Parse(objFilename);

            if (result.Error != null)
            {
                MessageBox.Show(result.Error.ToString());
            }
            else
            {
                var light = new CSharpGL.PointLight(new vec3(1, 1, 1));
                var model = new ObjVNF(result.Mesh);
                this.node = PointLightNode.Create(light, model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
                float max = node.ModelSize.max();
                this.node.Scale *= 16.0f / max;
                this.lightNode   = LightPostionNode.Create();
                lightNode.SetLight(light);
                lightNode.WorldPosition = new vec3(1, 1, 1) * 4;
                var groupNode = new GroupNode(node, lightNode);
                this.scene.RootElement = groupNode;
                (new FormProperyGrid(groupNode)).Show();
            }

            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);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="position"></param>
        /// <param name="normal"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static PointLightNode Create(CSharpGL.PointLight light, IBufferSource model, string position, string normal, vec3 size)
        {
            var vs       = new VertexShader(pointLightVert);
            var fs       = new FragmentShader(pointLightFrag);
            var provider = new ShaderArray(vs, fs);
            var map      = new AttributeMap();

            map.Add(inPosition, position);
            map.Add(inNormal, normal);
            var builder = new RenderMethodBuilder(provider, map);

            var node = new PointLightNode(model, position, builder);

            node.light     = light;
            node.ModelSize = size;
            node.Children.Add(new LegacyBoundingBoxNode(size));

            node.Initialize();

            return(node);
        }