Exemplo n.º 1
0
        private void FormSphere_Load(object sender, EventArgs e)
        {
            // earth on a plane.
            //var position = new vec3(0, -1, 0);
            //var center = new vec3(0, 0, 0);
            //var up = new vec3(-1, 0, 0);
            var     position = new vec3(5, 3, 4) * 0.3f;
            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);
            Texture texture  = GetTexture();

            this.sphereNode = SphereNode.Create(texture);
            var scene = new Scene(camera);

            scene.RootNode = sphereNode;
            this.scene     = scene;

            (new FormProperyGrid(this.sphereNode)).Show();

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

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

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

            // uncomment these lines to enable manipualter of camera!
            var manipulater = new FirstPerspectiveManipulater();

            manipulater.BindingMouseButtons = GLMouseButtons.Right;
            manipulater.Bind(camera, this.winGLCanvas1);
        }
Exemplo n.º 2
0
        public static SphereNode Create(Texture texture)
        {
            // vertex buffer and index buffer.
            var model = new Sphere(1, 20, 40);
            // vertex shader and fragment shader.
            var vs    = new VertexShader(vertexCode);
            var fs    = new FragmentShader(fragmentCode);
            var array = new ShaderArray(vs, fs);
            // which vertex buffer maps to which attribute in shader.
            var map = new AttributeMap();

            map.Add("inPosition", Sphere.strPosition);
            map.Add("inTexCoord", Sphere.strUV);
            // build a render method.
            var builder = new RenderMethodBuilder(array, map);
            // create node.
            var node = new SphereNode(model, builder);

            node.SetTexture(texture);
            // initialize node.
            node.Initialize();

            return(node);
        }