Ejemplo n.º 1
0
        protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            CurrentProject.GraphicsDevice = GraphicsDevice;
            CurrentProject.SkyboxShader.LoadShader(Content, GraphicsDevice);
            CurrentProject.TexturedMeshShader.LoadShader(Content, GraphicsDevice);
            CurrentProject.BasicColorShader.LoadShader(Content, GraphicsDevice);
            CurrentProject.Resolution = new Vector2(800, 600);

            CurrentProject.BasicColorShader.LoadShader(Content, GraphicsDevice);
            Skybox.Load(Content);

            Space = new BEPUphysics.Space();
            Space.ForceUpdater.Gravity = new BEPUutilities.Vector3(0, -9f, 0);
            Space.ForceUpdater.Enabled = true;

            Map.Load(Content);
            MapVisible.Load(Content);
            SetDefaultSkinmeshLightning(MapVisible.Model);
            Map.PhysicsInitialize(Space);

            StairsVisible.Load(Content);
            SetDefaultSkinmeshLightning(StairsVisible.Model);
            Stairs.Load(Content);
            Stairs.PhysicsInitialize(Space);

            Teapot.Load(Content);
            Cup.Load(Content);

            Camera.PhysicsInitialize(Space);
            Skybox.LinkCamera(Camera);

            DefaultFont = Content.Load <SpriteFont>("Font");

            RenderTargetMap = new RenderTarget2D(GraphicsDevice, 800, 480, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.DiscardContents);

            NonEuclideanRenders = new RenderTarget2D[10];
            for (int i = 0; i < 10; i++)
            {
                NonEuclideanRenders[i] = new RenderTarget2D(GraphicsDevice, 800, 480, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.DiscardContents);
            }

            StairsCol2.Load(Content);

            illusion2plane = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 6, BufferUsage.None);
            illusion2plane.SetData(new VertexPositionColor[]
            {
                new VertexPositionColor(new Vector3(-8.60f, 1.4f, -13.46f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 1.4f, -15.73f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 0f, -13.46f), Color.Red),

                new VertexPositionColor(new Vector3(-8.60f, 1.4f, -15.73f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 0f, -15.73f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 0f, -13.46f), Color.Red),
            });

            illusion3plane = new VertexBuffer(GraphicsDevice, typeof(VertexPositionColor), 6, BufferUsage.None);
            illusion3plane.SetData(new VertexPositionColor[]
            {
                new VertexPositionColor(new Vector3(-8.60f, 1.4f, -18.73f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 1.4f, -21.00f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 0f, -18.73f), Color.Red),

                new VertexPositionColor(new Vector3(-8.60f, 1.4f, -21.00f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 0f, -21.00f), Color.Red),
                new VertexPositionColor(new Vector3(-8.60f, 0f, -18.73f), Color.Red),
            });

            RoomIllusion1.Load(Content);
            SetDefaultSkinmeshLightning(RoomIllusion1.Model);

            NonEuclideanRenderFunctions.LoadSepShader(Content);

            pblack = new Texture2D(GraphicsDevice, 1, 1);
            pblack.SetData(new Color[] { Color.Black });
        }
Ejemplo n.º 2
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            Camera.Draw(gameTime, null, ref view, ref proj);

            GraphicsDevice.BlendFactor       = new Color(255, 255, 255, 255);
            GraphicsDevice.BlendState        = BlendState.Opaque;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            GraphicsDevice.RasterizerState   = RasterizerState.CullCounterClockwise;
            GraphicsDevice.SamplerStates[0]  = SamplerState.PointWrap;

            GraphicsDevice.SetRenderTarget(RenderTargetMap);
            GraphicsDevice.Clear(Color.Transparent);

            MapVisible.DrawMeshWithoutPart(0, 3, Camera.CameraFrustum, ref view, ref proj);
            NonEuclideanRenderFunctions.DrawPlane(GraphicsDevice, illusion2plane, ref view, ref proj);
            NonEuclideanRenderFunctions.DrawPlane(GraphicsDevice, illusion3plane, ref view, ref proj);

            Teapot.Position = new Vector3(4.32f, 0.76f, -6.73f);
            Teapot.Draw(ref view, ref proj);
            Teapot.Position = new Vector3(-10.764509f, 0f, -19.796597f);
            Teapot.Draw(ref view, ref proj);
            Cup.Position = new Vector3(-6.42751f, 0f, -20.183052f);
            Cup.Draw(ref view, ref proj);

            for (int i = 0; i < 30; i++)
            {
                StairsVisible.Draw(ref view, ref proj);
                StairsVisible.Position.Y += 5.36f;
            }
            StairsVisible.Position.Y = 5.36f;

            GraphicsDevice.SetRenderTarget(NonEuclideanRenders[0]);
            GraphicsDevice.Clear(Color.Transparent);
            Teapot.Position = new Vector3(4.32f, 0.17f, -6.73f);
            Teapot.Draw(ref view, ref proj);

            GraphicsDevice.SetRenderTarget(NonEuclideanRenders[1]);
            GraphicsDevice.Clear(Color.Transparent);
            RoomIllusion1.DrawMeshWithoutPart(0, 3, Camera.CameraFrustum, ref view, ref proj);

            GraphicsDevice.SetRenderTarget(null);

            Skybox.Draw(gameTime, Camera.CameraFrustum, ref view, ref proj);

            _spriteBatch.Begin();
            _spriteBatch.Draw(NonEuclideanRenders[1], new Rectangle(0, 0, 800, 480), Color.White);
            _spriteBatch.Draw(RenderTargetMap, new Rectangle(0, 0, 800, 480), Color.White);
            if (_illusion_visible)
            {
                /*
                 * Vector3 p = Vector3.Transform(new Vector3(3.96f, 0.71f, -6.12f), view *proj);
                 * Vector3 p2 = Vector3.Transform(new Vector3(4.67f, 0.17f, -6.12f), view * proj);
                 *
                 * p += Vector3.One;
                 * p *= 0.5f;
                 * p2 += Vector3.One;
                 * p2 *= 0.5f;
                 * p.X *= 800;
                 * p2.X *= 800;
                 *
                 * p.Y *= 480;
                 * p2.Y *= 480;
                 *
                 * _spriteBatch.Draw(NonEuclideanRenders[0],
                 * new Rectangle((int)p.X, 0,(int) p2.X, 480),
                 * new Rectangle((int)p.X, 0,(int) p2.X, 480), Color.White); ;
                 * if(allowdebugging) Debugger.Break();
                 * _spriteBatch.DrawString(DefaultFont, "Second demonstration visible", new Vector2(10, 460), Color.White);
                 */
            }
            _spriteBatch.DrawString(DefaultFont, "DEBUG: Position = " + Camera.Position, Vector2.One, Color.Black);
            _spriteBatch.End();
            base.Draw(gameTime);
        }