Ejemplo n.º 1
0
        protected override void Initialize()
        {
            // Setup resource manager
            ResourceManager.FileSystems.Add(new DiskFileSystem("Content"));

            // Setup debug blender
            //Renderer.Blender = new DebugBlender(0, Services);

            // Add view
            camera = new Camera(new Vector3(0, 5, 5), new Vector2(-(float)Math.PI / 4f, 0), 3.1415f / 3f, 4f / 3f, 0.1f, 100f);
            view = Renderer.CreateDefaultView(camera);
            Renderer.Views.Add(view);

            // Add sector
            sector = new ListSector(new BoundingBox(new Vector3(-10), new Vector3(10)));
            WorldManager.RegisterSector(sector);

            // Fill world
            boxObject1 = SimpleObject.CreateCube("Shaders/Test.fx", "Textures/Crate.jpg", "Box1", Services);
            boxObject1.Position = new Vector3(0.4f, 1, 1.2f);
            sector.RegisterObject(boxObject1);
            boxObject2 = SimpleObject.CreateCube("Shaders/Test.fx", "Textures/Crate.jpg", "Box2", Services);
            boxObject2.Position = new Vector3(-0.4f, 1, -1);
            sector.RegisterObject(boxObject2);
            boxObject3 = SimpleObject.CreateCube("Shaders/Test.fx", "Textures/Crate.jpg", "Box3", Services);
            boxObject3.Position = new Vector3(0, 3.001f, 0);
            boxObject3.Rotation = Quaternion.RotationAxis(Vector3.UnitY, (float)Math.PI / 3f);
            sector.RegisterObject(boxObject3);
            floorObject = SimpleObject.CreatePlane("Shaders/Test.fx", "Textures/Floor.jpg", "Floor", Services, 20, 20);
            floorObject.Position = new Vector3(0, -0.001f, 0);
            sector.RegisterObject(floorObject);

            // Add lighting
            ambientLighting = new AmbientLightingEffect(Services);
            //Renderer.VisualEffects.Add(ambientLighting);
            sunLighting = new DirectionalLightingEffect(Services);
            Renderer.VisualEffects.Add(sunLighting);

            // Register input handler
            InputManager.KeyDown += InputManager_KeyDown;
        }
Ejemplo n.º 2
0
        public Portal(Sector sourceSector, Sector destinationSector, Vector3 position, Quaternion rotation,
            IEnumerable<Triangle> triangles)
        {
            if (sourceSector == null)
                throw new ArgumentNullException("sourceSector");
            if (destinationSector == null)
                throw new ArgumentNullException("destinationSector");
            if (triangles == null)
                throw new ArgumentNullException("triangles");
            if (sourceSector == destinationSector)
                throw new ArgumentException("sourceSector and destinationSector must differ.");

            this.sourceSector = sourceSector;
            this.destinationSector = destinationSector;
            this.worldMatrix = Matrix.Transformation(Vector3.Zero, Quaternion.Identity, new Vector3(1f), Vector3.Zero, rotation,
                                                     position);

            this.triangles.AddRange(triangles);
            this.trianglesRO = new TriangleReadOnlyCollection(this.triangles);
            CalculateBounary();
        }
Ejemplo n.º 3
0
        private void PrepareBatches(Sector startSector)
        {
            // Retrieve visible objects
            startSector.Manager.GetObjectsInVolume(startSector, new BoundingFrustumVolumeAdapter(viewerForBatches.Frustum), visibleObjects,
                                              startSector.Manager.RegisteredSectors.Count);

            // Get list of batches
            foreach (WorldObject visibleObject in visibleObjects)
            {
                var batches = visibleObject.GetBatches(viewerForBatches);
                batchesToRender.AddRange(batches);
            }

            // Sort by effect
            batchesToRender.Sort(delegate(Batch batch1, Batch batch2)
            {
                int code1 = batch1.Effect.GetHashCode();
                int code2 = batch2.Effect.GetHashCode();
                return code1 < code2 ? -1 : code1 == code2 ? 0 : 1;
            });

            // Apply global effect parameters
            foreach (Batch batch in batchesToRender)
                batch.SetupGlobalParameters(viewerForBatches, (Timer) services.GetService(typeof (Timer)));
        }