Example #1
0
        public override void Create()
        {
            scene = new Scene(Main.Instance.Context);
            scene.CreateComponent <Octree>();
            CameraNode          = scene.CreateChild("Camera");
            camera              = CameraNode.CreateComponent <Camera>();
            camera.FarClip      = 1000;
            CameraNode.Position = new Vector3(0.0f, 2.0f, 0);
            CameraNode.LookAt(Vector3.Zero, Vector3.Up);
            Main.Instance.Renderer.SetViewport(0, new Viewport(Main.Instance.Context, scene, camera, null));

            bg = CModel.LoadPrefab(scene, "floor.xml");
            bg.SetMaterial("wormi_bg.xml");
            bg.SetTechnique("DiffUnlit.xml");
        }
Example #2
0
        public static CModel Load(Scene scene, string fileName, string materialName = "", bool castShadows = true)
        {
            CModel m = new CModel();

            m.node  = scene.CreateChild();
            m.model = m.node.CreateComponent <StaticModel>();
            var cache = Main.Instance.ResourceCache;

            m.model.Model = cache.GetModel("Models/" + fileName);
            if (materialName != "")
            {
                m.model.SetMaterial(cache.GetMaterial("Materials/" + materialName));
            }
            m.model.CastShadows = castShadows;
            return(m);
        }
Example #3
0
        public override void Create()
        {
            food.Clear();
            wormi.Clear();

            incLen   = 0;
            curSpeed = 0.1f;
            curTime  = 0;

            // 3D scene with Octree
            scene = new Scene(Main.Instance.Context);
            scene.CreateComponent <Octree>();
            scene.CreateComponent <DebugRenderer>();

            soundNode   = scene.CreateChild("Sound");
            eating      = Main.Instance.ResourceCache.GetSound("Sounds/BigExplosion.wav");
            death       = Main.Instance.ResourceCache.GetSound("Sounds/NutThrow.wav");
            soundSource = soundNode.CreateComponent <SoundSource>();

            // Create a directional light to the world. Enable cascaded shadows on it
            var lightNode = scene.CreateChild("DirectionalLight");

            lightNode.SetDirection(new Vector3(0.6f, -1.0f, 0.8f)); // The direction vector does not need to be normalized
            var light = lightNode.CreateComponent <Light>();

            light.LightType     = LightType.Directional;
            light.CastShadows   = true;
            light.ShadowBias    = new BiasParameters(0.00025f, 0.5f);
            light.ShadowCascade = new CascadeParameters(10.0f, 50.0f, 200.0f, 0.0f, 0.8f);

            CameraNode          = scene.CreateChild("Camera");
            camera              = CameraNode.CreateComponent <Camera>();
            camera.FarClip      = 1000;
            CameraNode.Position = new Vector3(0.0f, 35.0f, -35.0f);
            CameraNode.LookAt(Vector3.Zero, Vector3.Up);

            Main.Instance.Renderer.SetViewport(0, new Viewport(Main.Instance.Context, scene, camera, null));

            CModel floor = CModel.LoadPrefab(scene, "floor.xml");

            floor.GetNode().SetScale(50);
            floor.SetMaterial("Terrain.xml");

            for (int q = 0; q < 10; q++)
            {
                WormPiece p = new WormPiece();
                p.mesh = CModel.LoadPrefab(scene, "WormSphere.xml");
                p.mesh.GetNode().Position = new Vector3(-q * DIST, 0, 0);
                p.mesh.GetNode().Rotation = new Quaternion(0, 90, 0);
                //p.mesh.LoadAnimation("Move.ani");
                //p.mesh.LoadAnimation("Eat.ani");
                //p.mesh.Play("Move.ani");
                wormi.Add(p);
            }

            for (int q = 0; q < 20; q++)
            {
                SpawnFood();
            }

            particleNode = scene.CreateChild("Particles");
            emitter      = particleNode.CreateComponent <ParticleEmitter>();
        }