Exemplo n.º 1
0
        /// <summary>
        /// Render a teapot in modern opengl.
        /// </summary>
        /// <returns></returns>
        public static MultiTargetTeapotNode Create(bool adjacent = false)
        {
            IBufferSource model; vec3 size;

            if (adjacent)
            {
                var m = new AdjacentTeapot(); size = m.GetModelSize(); model = m;
            }
            else
            {
                var m = new Teapot(); size = m.GetModelSize(); model = m;
            }
            string position = adjacent ? AdjacentTeapot.strPosition : Teapot.strPosition;
            string color    = adjacent ? AdjacentTeapot.strColor : Teapot.strColor;

            var vs       = new VertexShader(vertexCode);
            var fs       = new FragmentShader(fragmentCode);
            var provider = new ShaderArray(vs, fs);
            var map      = new AttributeMap();

            map.Add(inPosition, position);
            map.Add(inColor, color);
            var builder = new RenderMethodBuilder(provider, map);
            var node    = new MultiTargetTeapotNode(model, position, builder);

            node.Initialize();
            node.ModelSize = size;

            return(node);
        }
Exemplo n.º 2
0
        private void FormMain_Load(object sender, EventArgs e)
        {
            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.Perspective, this.winGLCanvas1.Width, this.winGLCanvas1.Height);

            this.scene = new Scene(camera)
            ;

            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();

            var manipulater = new FirstPerspectiveManipulater();

            manipulater.Bind(camera, this.winGLCanvas1);

            //string folder = System.Windows.Forms.Application.StartupPath;
            //string filename = System.IO.Path.Combine(folder + @"\..\..\..\..\Infrastructure\CSharpGL.Models", "vnfHanoiTower.obj_");
            //var parser = new ObjVNFParser(false);
            //ObjVNFResult result = parser.Parse(filename);
            //if (result.Error != null)
            //{
            //    MessageBox.Show(result.Error.ToString());
            //}
            //else
            //{
            //    var model = new ObjVNF(result.Mesh);
            //    var node = OITNode.Create(model, ObjVNF.strPosition, ObjVNF.strNormal, model.GetSize());
            //    float max = node.ModelSize.max();
            //    node.Scale *= 7.0f / max;
            //    node.WorldPosition = new vec3(0, 0, 0);
            //    var rootElement = this.scene.RootElement;
            //    this.scene.RootElement = node;
            //    if (rootElement != null) { rootElement.Dispose(); }
            //}
            // use teapot instead.
            var   model = new Teapot();
            var   node  = OITNode.Create(model, Teapot.strPosition, Teapot.strNormal, model.GetModelSize());
            float max   = node.ModelSize.max();

            node.Scale         *= 7.0F / max;
            node.WorldPosition  = new vec3(0, 0, 0);
            this.scene.RootNode = node;
        }
Exemplo n.º 3
0
        private SceneNodeBase GetRootElement()
        {
            var group = new GroupNode();

            {
                var model = new Teapot();
                var node  = ShadowMappingNode.Create(model, Teapot.strPosition, Teapot.strNormal, model.GetModelSize());
                node.Color       = Color.Gold.ToVec3();
                node.RotateSpeed = 1;
                group.Children.Add(node);
            }
            {
                var model = new GroundModel();
                var node  = ShadowMappingNode.Create(model, GroundModel.strPosition, GroundModel.strNormal, model.ModelSize);
                node.Color         = Color.White.ToVec3();
                node.Scale        *= 100;
                node.WorldPosition = new vec3(0, -3, 0);
                group.Children.Add(node);
            }

            return(group);
        }
Exemplo n.º 4
0
 private DepthTeapotNode(Teapot model, params RenderMethodBuilder[] builder)
     : base(model, builder)
 {
     this.ModelSize = model.GetModelSize();
 }
Exemplo n.º 5
0
        private SceneNodeBase GetRootElement()
        {
            var group         = new GroupNode();
            var lightPosition = new vec3(0, 3, 5) * 2;
            var localLight    = new SpotLight(lightPosition, new vec3(0, 0, 0), 60, 1, 500)
            {
                Color = new vec3(1, 1, 1),
            };

            {
                var lightContainer = new LightContainerNode(localLight);
                {
                    var model = new Teapot();
                    var node  = ShadowMappingNode.Create(model, Teapot.strPosition, Teapot.strNormal, model.GetModelSize());
                    node.Diffuse     = Color.Gold.ToVec3();
                    node.RotateSpeed = 1;
                    lightContainer.Children.Add(node);
                }
                {
                    var model = new GroundModel();
                    var node  = ShadowMappingNode.Create(model, GroundModel.strPosition, GroundModel.strNormal, model.ModelSize);
                    node.Diffuse       = Color.AliceBlue.ToVec3();
                    node.Scale        *= 30;
                    node.WorldPosition = new vec3(0, -3, 0);
                    lightContainer.Children.Add(node);
                }
                group.Children.Add(lightContainer);
            }
            {
                var rectangle = RectangleNode.Create();
                rectangle.TextureSource = localLight;
                rectangle.RotationAngle = 45;
                rectangle.WorldPosition = new vec3(5, 1, 5) * 3;
                rectangle.Scale        *= 4;

                group.Children.Add(rectangle);
            }
            {
                var cube = LightPostionNode.Create();
                cube.WorldPosition = lightPosition;
                cube.SetLight(localLight);
                group.Children.Add(cube);
            }
            return(group);
        }