示例#1
0
        private SceneNodeBase GetRootNode(ICamera modelCamera)
        {
            var root = new GroupNode();

            // render 'scene' to franebuffer.
            {
                int width = this.winGLCanvas1.Width, height = this.winGLCanvas1.Height;
                var rtt = new RenderToTexttureNode(width, height, modelCamera, new ColoredFramebufferProvider());
                rtt.BackgroundColor = Color.SkyBlue;
                {
                    var teapot = TeapotNode.Create();
                    teapot.RenderWireframe = false;
                    rtt.Children.Add(teapot);// rendered to framebuffer, then to texture.
                }
                root.Children.Add(rtt);
                this.rtt = rtt;
            }
            {
                var group = new GroupNode();
                // display 'scene' in rectangle.
                {
                    var node = RectangleNode.Create();
                    node.TextureSource = this.rtt;
                    node.Scale         = new vec3(1, 1, 1) * 6;
                    node.RotationAxis  = new vec3(-1, 0, 0);
                    node.RotationAngle = 90;
                    group.Children.Add(node);
                }
                const float radius = 3;
                // arcball.
                {
                    var model             = new HalfSphere(radius, 40, 40);
                    var node              = NoShadowNode.Create(model, HalfSphere.strPosition, HalfSphere.strNormal, model.Size);
                    var list              = node.RenderUnit.Methods[0].SwitchList;
                    var list1             = node.RenderUnit.Methods[1].SwitchList;
                    var polygonModeSwitch = new PolygonModeSwitch(PolygonMode.Line);
                    var offsetSwitch      = new PolygonOffsetFillSwitch();
                    list.Add(polygonModeSwitch);
                    list1.Add(polygonModeSwitch);
                    var cmd = node.RenderUnit.Methods[0].VertexArrayObjects[0].DrawCommand as DrawElementsCmd;
                    cmd.VertexCount = cmd.VertexCount / 2; // render only half a sphere.
                    group.Children.Add(node);
                }
                // lines.
                {
                    var node = LinesNode.Create(radius);
                    group.Children.Add(node);
                    this.linesNode = node;
                }
                // fan
                {
                    var node = FanNode.Create(radius);
                    group.Children.Add(node);
                    this.fanNode = node;
                }
                root.Children.Add(group);
                this.groupNode = group;
            }
            return(root);
        }
示例#2
0
        public static LinesNode Create(float radius)
        {
            var vs    = new VertexShader(vertexCode);
            var fs    = new FragmentShader(fragmentCode);
            var array = new ShaderArray(vs, fs);
            var map   = new AttributeMap();

            //map.Add("inPosition", LinesModel.strPosition);
            map.Add("inColor", LinesModel.strColor);
            //var depthTestSwitch = new DepthTestSwitch(false);
            var lineWidthSwith = new LineWidthSwitch(5);
            var builder        = new RenderMethodBuilder(array, map, lineWidthSwith);

            var model = new LinesModel(radius);
            var node  = new LinesNode(model, builder);

            node.radius = radius;
            node.Initialize();

            return(node);
        }