Beispiel #1
0
        public static SceneOb FindSceneOb(SceneOb so, string name)
        {
            // Check parameters
            if (so == null)
            {
                return(null);
            }
            if (so.Children == null)
            {
                return(null);
            }

            foreach (var child in so.Children)
            {
                if (child.Name != null && child.Name.Equals(name))
                {
                    return(child);
                }

                var gChild = FindSceneOb(child, name);

                if (gChild != null)
                {
                    return(gChild);
                }
            }
            return(null); // SceneObject not found
        }
Beispiel #2
0
        // Init is called on startup.
        public override void Init()
        {
            // Initialize the shader(s)
            var shader = RC.CreateShader(_vertexShader, _pixelShader);

            RC.SetShader(shader);
            _albedoParam = RC.GetShaderParam(shader, "albedo");

            // Load meshes
            Mesh cube = LoadMesh("Cube.fus");

            InitLevelArray();

            // Setup a list of objects
            _root = new SceneOb {
                Children = new List <SceneOb>()
            };
            for (int ix = 0; ix < levelArray.GetLength(0); ix++)
            {
                for (int iy = 0; iy < levelArray.GetLength(1); iy++)
                {
                    for (int iz = 0; iz < levelArray.GetLength(2); iz++)
                    {
                        _root.Children.Add(new SceneOb {
                            Mesh = cube, Pos = ((levelArray[ix, iy, iz].pos) * 1.05f), Albedo = levelArray[ix, iy, iz].albedo
                        });
                    }
                }
            }

            // Set the clear color for the backbuffer
            RC.ClearColor = new float4(1, 1, 1, 1);
        }
Beispiel #3
0
        // Init is called on startup.
        public override void Init()
        {
            var vertsh = AssetStorage.Get <string>("VertexShader.vert");
            var pixsh  = AssetStorage.Get <string>("PixelShader.frag");

            // Initialize the shader(s)
            var shader = RC.CreateShader(vertsh, pixsh);

            RC.SetShader(shader);
            _albedoParam = RC.GetShaderParam(shader, "albedo");

            // Load some meshes
            Mesh cube     = LoadMesh("Cube.fus");
            Mesh cylinder = LoadMesh("Cylinder.fus");
            Mesh sphere   = LoadMesh("Sphere.fus");

            // Setup a list of objects
            _root = new SceneOb {
                Children = new List <SceneOb>(new []
                {
                    // Body
                    new SceneOb {
                        Mesh = cube, Pos = new float3(0, 2.75f, 0), ModelScale = new float3(0.5f, 1, 0.25f), Albedo = new float3(0.2f, 0.6f, 0.3f)
                    },
                    // Legs
                    new SceneOb {
                        Mesh = cylinder, Pos = new float3(-0.25f, 1, 0), ModelScale = new float3(0.15f, 1, 0.15f),
                    },
                    new SceneOb {
                        Mesh = cylinder, Pos = new float3(0.25f, 1, 0), ModelScale = new float3(0.15f, 1, 0.15f),
                    },
                    // Shoulders
                    new SceneOb {
                        Mesh = sphere, Pos = new float3(-0.75f, 3.5f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f),
                    },
                    new SceneOb {
                        Mesh = sphere, Pos = new float3(0.75f, 3.5f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f),
                    },
                    // Arms
                    new SceneOb {
                        Mesh = cylinder, Pos = new float3(-0.75f, 2.5f, 0), ModelScale = new float3(0.15f, 1, 0.15f),
                    },
                    new SceneOb {
                        Mesh = cylinder, Pos = new float3(0.75f, 2.5f, 0), ModelScale = new float3(0.15f, 1, 0.15f),
                    },
                    // Head
                    new SceneOb
                    {
                        Mesh   = sphere, Pos = new float3(0, 4.2f, 0), ModelScale = new float3(0.35f, 0.5f, 0.35f),
                        Albedo = new float3(0.9f, 0.6f, 0.5f)
                    },
                })
            };

            // Set the clear color for the backbuffer
            RC.ClearColor = new float4(1, 1, 1, 1);
        }
Beispiel #4
0
        void RenderSceneOb(SceneOb so, float4x4 modelView)
        {
            modelView = modelView * ModelXForm(so.Pos, so.Rot, so.Pivot) * float4x4.CreateScale(so.Scale);
            if (so.Mesh != null)
            {
                RC.ModelView = modelView * float4x4.CreateScale(so.ModelScale);
                RC.SetShaderParam(_albedoParam, so.Albedo);
                RC.Render(so.Mesh);
            }

            if (so.Children != null)
            {
                foreach (var child in so.Children)
                {
                    RenderSceneOb(child, modelView);
                }
            }
        }
Beispiel #5
0
        // Init is called on startup.
        public override void Init()
        {
            // Initialize the shader(s)
            var shader = RC.CreateShader(_vertexShader, _pixelShader);

            RC.SetShader(shader);
            _albedoParam = RC.GetShaderParam(shader, "albedo");

            // Load some meshes
            Mesh cone     = LoadMesh("Cone.fus");
            Mesh cube     = LoadMesh("Cube.fus");
            Mesh cylinder = LoadMesh("Cylinder.fus");
            Mesh pyramid  = LoadMesh("Pyramid.fus");
            Mesh sphere   = LoadMesh("Sphere.fus");

            // Setup a list of objects
            _root = new SceneOb {
                name = "root"
            };

            // Add Body
            _root.Children.Add(new SceneOb {
                Mesh = cube, Albedo = new float3(0, 0, 0), Pos = new float3(0, 2.75f, 0), ModelScale = new float3(0.5f, 1, 0.25f), name = "body"
            });

            // Add Legs
            _root.Children.Add(new SceneOb {
                Mesh = cylinder, Albedo = new float3(0, 0, 0), Pos = new float3(-0.25f, 1, 0), ModelScale = new float3(0.15f, 0.75f, 0.15f), name = "rightupperleg"
            });
            FindSceneOb(_root, "rightupperleg").Children.Add(new SceneOb {
                Mesh = sphere, Albedo = new float3(1, 0.5f, 0), Pos = new float3(0, -0.75f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f), name = "rightknee"
            });
            FindSceneOb(_root, "rightknee").Children.Add(new SceneOb {
                Mesh = cylinder, Albedo = new float3(0, 0, 0), Pos = new float3(0, -0.5f, 0), ModelScale = new float3(0.15f, 0.5f, 0.15f), name = "rightlowerleg"
            });
            FindSceneOb(_root, "rightlowerleg").Children.Add(new SceneOb {
                Mesh = sphere, Albedo = new float3(1, 0.5f, 0), Pos = new float3(0, -0.70f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f), name = "rightfoot"
            });

            _root.Children.Add(new SceneOb {
                Mesh = cylinder, Albedo = new float3(0, 0, 0), Pos = new float3(0.25f, 1, 0), Pivot = new float3(0, 0.75f, 0), ModelScale = new float3(0.15f, 0.75f, 0.15f), name = "leftupperleg"
            });
            FindSceneOb(_root, "leftupperleg").Children.Add(new SceneOb {
                Mesh = sphere, Albedo = new float3(1, 0.5f, 0), Pos = new float3(0, -0.75f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f), name = "leftknee"
            });
            FindSceneOb(_root, "leftknee").Children.Add(new SceneOb {
                Mesh = cylinder, Albedo = new float3(0, 0, 0), Pos = new float3(0, -0.5f, 0), ModelScale = new float3(0.15f, 0.5f, 0.15f), name = "leftlowerleg"
            });
            FindSceneOb(_root, "leftlowerleg").Children.Add(new SceneOb {
                Mesh = sphere, Albedo = new float3(1, 0.5f, 0), Pos = new float3(0, -0.70f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f), name = "leftfoot"
            });

            // Add Arms
            _root.Children.Add(new SceneOb {
                Mesh = sphere, Albedo = new float3(1, 0.5f, 0), Pos = new float3(-0.75f, 3.5f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f), name = "rightshoulder"
            });
            FindSceneOb(_root, "rightshoulder").Children.Add(new SceneOb {
                Mesh = cylinder, Albedo = new float3(0, 0, 0), Pos = new float3(0, -0.5f, 0), ModelScale = new float3(0.15f, 0.5f, 0.15f), name = "rightupperarm"
            });
            FindSceneOb(_root, "rightupperarm").Children.Add(new SceneOb {
                Mesh = sphere, Albedo = new float3(1, 0.5f, 0), Pos = new float3(0, -0.5f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f), name = "rightellbow"
            });
            FindSceneOb(_root, "rightellbow").Children.Add(new SceneOb {
                Mesh = cylinder, Albedo = new float3(0, 0, 0), Pos = new float3(0, -0.5f, 0), ModelScale = new float3(0.15f, 0.5f, 0.15f), name = "rightlowerarm"
            });
            FindSceneOb(_root, "rightlowerarm").Children.Add(new SceneOb {
                Mesh = sphere, Albedo = new float3(1, 0.5f, 0), Pos = new float3(0, -0.5f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f), name = "rightwrist"
            });

            _root.Children.Add(new SceneOb {
                Mesh = sphere, Albedo = new float3(1, 0.5f, 0), Pos = new float3(0.75f, 3.5f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f), name = "leftshoulder"
            });
            FindSceneOb(_root, "leftshoulder").Children.Add(new SceneOb {
                Mesh = cylinder, Albedo = new float3(0, 0, 0), Pos = new float3(0, -0.5f, 0), ModelScale = new float3(0.15f, 0.5f, 0.15f), name = "leftupperarm"
            });
            FindSceneOb(_root, "leftupperarm").Children.Add(new SceneOb {
                Mesh = sphere, Albedo = new float3(1, 0.5f, 0), Pos = new float3(0, -0.5f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f), name = "leftellbow"
            });
            FindSceneOb(_root, "leftellbow").Children.Add(new SceneOb {
                Mesh = cylinder, Albedo = new float3(0, 0, 0), Pos = new float3(0, -0.5f, 0), ModelScale = new float3(0.15f, 0.5f, 0.15f), name = "leftlowerarm"
            });
            FindSceneOb(_root, "leftlowerarm").Children.Add(new SceneOb {
                Mesh = sphere, Albedo = new float3(1, 0.5f, 0), Pos = new float3(0, -0.5f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f), name = "leftwrist"
            });

            // Add Head
            _root.Children.Add(new SceneOb {
                Mesh = sphere, Albedo = new float3(0, 1, 0), Pos = new float3(0, 4.2f, 0), ModelScale = new float3(0.35f, 0.5f, 0.35f), name = "head"
            });

            // Set the clear color for the backbuffer
            RC.ClearColor = new float4(1, 1, 1, 1);
        }
Beispiel #6
0
 public static SceneOb FindSceneOb(SceneOb so, string name)
 {
     return(so.name == name ? so : so.Children.Select(child => FindSceneOb(child, name)).FirstOrDefault(result => result != null && result.name == name));
 }
Beispiel #7
0
        // Init is called on startup.
        public override void Init()
        {
            // Load some meshes
            Mesh cone     = LoadMesh("Cone.fus");
            Mesh cube     = LoadMesh("Cube.fus");
            Mesh cylinder = LoadMesh("Cylinder.fus");
            Mesh pyramid  = LoadMesh("Pyramid.fus");
            Mesh sphere   = LoadMesh("Sphere.fus");


            SceneItem si1 = new Transform {
                Pos = new float3(1, 2, 3)
            };
            SceneItem si2 = new Geometry {
                Mesh = cylinder
            };

            si1.Render(RC);



            // Initialize the shader(s)
            var shader = RC.CreateShader(_vertexShader, _pixelShader);

            RC.SetShader(shader);
            _albedoParam = RC.GetShaderParam(shader, "albedo");


            // Setup a list of objects
            _root = new SceneOb {
                Children = new List <SceneOb>(new []
                {
                    // Body
                    new SceneOb {
                        Mesh = cube, Pos = new float3(0, 2.75f, 0), ModelScale = new float3(0.5f, 1, 0.25f),
                    },
                    // Legs
                    new SceneOb {
                        Mesh = cylinder, Pos = new float3(-0.25f, 1, 0), ModelScale = new float3(0.15f, 1, 0.15f),
                    },
                    new SceneOb {
                        Mesh = cylinder, Pos = new float3(0.25f, 1, 0), ModelScale = new float3(0.15f, 1, 0.15f),
                    },
                    // Shoulders
                    new SceneOb {
                        Mesh = sphere, Pos = new float3(-0.75f, 3.5f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f),
                    },
                    new SceneOb {
                        Mesh = sphere, Pos = new float3(0.75f, 3.5f, 0), ModelScale = new float3(0.25f, 0.25f, 0.25f),
                    },
                    // Arms
                    new SceneOb {
                        Mesh = cylinder, Pos = new float3(-0.75f, 2.5f, 0), ModelScale = new float3(0.15f, 1, 0.15f),
                    },
                    new SceneOb {
                        Mesh = cylinder, Pos = new float3(0.75f, 2.5f, 0), ModelScale = new float3(0.15f, 1, 0.15f),
                    },
                    // Head
                    new SceneOb
                    {
                        Mesh   = sphere, Pos = new float3(0, 4.2f, 0), ModelScale = new float3(0.35f, 0.5f, 0.35f),
                        Albedo = new float3(0.9f, 0.6f, 0.5f)
                    },
                })
            };

            // Set the clear color for the backbuffer
            RC.ClearColor = new float4(1, 1, 1, 1);
        }