Esempio n. 1
0
        /// <summary>
        /// Creates a new renderer.
        /// </summary>
        public Renderer()
        {
            // Create an Embree.NET scene using our Model type

            scene = new Scene<Model>(SceneFlags.Static | SceneFlags.Coherent | SceneFlags.Incoherent | SceneFlags.Robust,
                                     TraversalFlags.Single | TraversalFlags.Packet4);

            // Load all required meshes here

            meshes.Add("buddha", ObjLoader.LoadMesh("Models/buddha.obj"));
            meshes.Add("lucy", ObjLoader.LoadMesh("Models/lucy.obj"));
            meshes.Add("ground", ObjLoader.LoadMesh("Models/ground.obj"));

            // Create a few Model instances with a given modelworld matrix which we will populate later

            var buddhaModel = new Model(Matrix.Combine(Matrix.Scaling(8),
                                                       Matrix.Rotation(-(float)Math.PI / 2, 0, 0.5f),
                                                       Matrix.Translation(new Vector(-2.5f, -1.8f, -4.5f))));

            var lucyModel = new Model(Matrix.Combine(Matrix.Scaling(1.0f / 175),
                                                     Matrix.Rotation(0, (float)Math.PI / 2 + 2.1f, 0),
                                                     Matrix.Translation(new Vector(-11, -1.56f, -5))));

            var lucyModel2 = new Model(Matrix.Combine(Matrix.Scaling(1.0f / 600),
                                                      Matrix.Rotation(0, (float)Math.PI / 2 - 1.8f, 0),
                                                      Matrix.Translation(new Vector(-2.5f, -3.98f, -8))));

            var groundModel = new Model(Matrix.Combine(Matrix.Scaling(100),
                                                       Matrix.Translation(new Vector(0, -5, 0))));

            // Now place these meshes into the world with a given material

            buddhaModel.AddMesh(meshes["buddha"], new Phong(new Vector(0.55f, 0.25f, 0.40f), 0.65f, 48));
            lucyModel.AddMesh(meshes["lucy"], new Phong(new Vector(0.35f, 0.65f, 0.15f), 0.85f, 256));
            groundModel.AddMesh(meshes["ground"], new Phong(new Vector(0.25f, 0.25f, 0.95f), 0.45f, 1024));
            lucyModel2.AddMesh(meshes["lucy"], new Diffuse(new Vector(0.95f, 0.85f, 0.05f) * 0.318f)); // instancing example

            // And finally add them to the scene (into the world)

            scene.Add(buddhaModel);
            scene.Add(lucyModel);
            scene.Add(lucyModel2);
            scene.Add(groundModel);

            // Don't forget to commit when we're done messing with the geometry

            scene.Commit();

            // Place a light source somewhere

            lightPosition = new Point(-11.85f, 11, -13);
            lightIntensity = 900;

            // Get a good shot of the world

            camera = new Camera((float)Math.PI / 5, 1,    // unknown aspect ratio for now
                                new Point(-2.5f, -0.45f, -12), // good position for the camera
                                new Vector(0, 0, 1), 0);  // view direction + no roll (upright)
        }
Esempio n. 2
0
 private void InitializeScene(RenderForm window)
 {
     scene = new Scene(device, context, window, window.ClientSize);
     scene.RotationSensitivity = (float)(Double)mainBar["rotation_sensitivity"].Value;
 }