Example #1
0
        /// <summary>
        /// Constructs a new primitive manager.
        /// </summary>
        /// <param name="engine">The current game engine.</param>
        /// <param name="effect">The effect file to load into MyEffect.</param>
        public PrimManager(Engine engine, Effect effect)
        {
            // Gets the graphic device.
            this.device = engine.GraphicsDevice;

            // Sets the 3D matrix transformations.
            worldMatrix      = Matrix.Identity;
            projectionMatrix = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 3, device.Viewport.AspectRatio, 5.0f, 800.0f);
            viewMatrix       = Matrix.CreateLookAt(new Vector3(-8, -8, 8), Vector3.Zero, new Vector3(0, 0, 1));

            // Sets the orthographic matrix transformations.
            worldMatrixOrtho      = Matrix.Identity;
            projectionMatrixOrtho = Matrix.CreateOrthographicOffCenter(0, engine.windowSize.X, -engine.windowSize.Y, 0, -512f, 512f);
            viewMatrixOrtho       = new Matrix(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);

            // Sets the sampler states.
            // NOTE: that these settings are overrided in the effects file.
            samplerState            = new SamplerState();
            samplerState.AddressU   = TextureAddressMode.Clamp;
            samplerState.AddressV   = TextureAddressMode.Clamp;
            samplerState.AddressW   = TextureAddressMode.Clamp;
            samplerState.Filter     = TextureFilter.Point;
            device.SamplerStates[0] = samplerState;

            // Sets the rasterizer states, used to set culling.
            rasterizerState          = new RasterizerState();
            rasterizerState.CullMode = CullMode.CullCounterClockwiseFace;
            device.RasterizerState   = rasterizerState;

            // Creates a depth buffer set off.
            depthOffState = new DepthStencilState();
            depthOffState.DepthBufferEnable = false;
            device.DepthStencilState        = DepthStencilState.Default;

            // Creates and sets the effect settings.
            myEffect            = new MyEffect(engine, effect);
            myEffect.World      = worldMatrix;
            myEffect.Projection = projectionMatrix;
            myEffect.View       = viewMatrix;
        }
Example #2
0
        /// <summary>
        /// Constructs a new primitive manager.
        /// </summary>
        /// <param name="engine">The current game engine.</param>
        /// <param name="effect">The effect file to load into MyEffect.</param>
        public PrimManager(Engine engine, Effect effect)
        {
            // Gets the graphic device.
            this.device = engine.GraphicsDevice;

            // Sets the 3D matrix transformations.
            worldMatrix = Matrix.Identity;
            projectionMatrix = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 3, device.Viewport.AspectRatio, 5.0f, 800.0f);
            viewMatrix = Matrix.CreateLookAt(new Vector3(-8, -8, 8), Vector3.Zero, new Vector3(0, 0, 1));

            // Sets the orthographic matrix transformations.
            worldMatrixOrtho = Matrix.Identity;
            projectionMatrixOrtho = Matrix.CreateOrthographicOffCenter(0, engine.windowSize.X, -engine.windowSize.Y, 0, -512f, 512f);
            viewMatrixOrtho = new Matrix(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f);

            // Sets the sampler states.
            // NOTE: that these settings are overrided in the effects file.
            samplerState = new SamplerState();
            samplerState.AddressU = TextureAddressMode.Clamp;
            samplerState.AddressV = TextureAddressMode.Clamp;
            samplerState.AddressW = TextureAddressMode.Clamp;
            samplerState.Filter = TextureFilter.Point;
            device.SamplerStates[0] = samplerState;

            // Sets the rasterizer states, used to set culling.
            rasterizerState = new RasterizerState();
            rasterizerState.CullMode = CullMode.CullCounterClockwiseFace;
            device.RasterizerState = rasterizerState;

            // Creates a depth buffer set off.
            depthOffState = new DepthStencilState();
            depthOffState.DepthBufferEnable = false;
            device.DepthStencilState = DepthStencilState.Default;

            // Creates and sets the effect settings.
            myEffect = new MyEffect(engine, effect);
            myEffect.World = worldMatrix;
            myEffect.Projection = projectionMatrix;
            myEffect.View = viewMatrix;
        }