Quantcast
Channel: Active questions tagged xna-4.0 - Game Development Stack Exchange
Viewing all articles
Browse latest Browse all 33

Why distant objects are being drawn in front of close objects?

$
0
0

I am rendering two cubes in the space using XNA 4.0 and the layering of objects only works from certain angles.

Here is what I see from the front angle (everything ok)

Capture from certain angle

Here is what I see from behind

Opposite angle

This is my draw method. Cubes are drawn by serverManager and serverManager1

        protected override void Draw(GameTime gameTime)    {        GraphicsDevice.Clear(Color.CornflowerBlue);        switch (_gameStateFSM.State)        {            case GameFSMState.GameStateFSM.INTROSCREEN:                spriteBatch.Begin();                introscreen.Draw(spriteBatch);                spriteBatch.End();                break;            case GameFSMState.GameStateFSM.GAME:                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);                // Text                screenMessagesManager.Draw(spriteBatch, firstPersonCamera.cameraPosition, fpsHelper.framesPerSecond);                // Camera                firstPersonCamera.Draw();                // Servers                serverManager.Draw(GraphicsDevice, firstPersonCamera.viewMatrix, firstPersonCamera.projMatrix);                serverManager1.Draw(GraphicsDevice, firstPersonCamera.viewMatrix, firstPersonCamera.projMatrix);                // Room                //roomManager.Draw(GraphicsDevice, firstPersonCamera.viewMatrix);                spriteBatch.End();                break;            case GameFSMState.GameStateFSM.EXITGAME:                break;            default:                break;        }        base.Draw(gameTime);        fpsHelper.IncrementFrameCounter();    }

serverManager and serverManager1 are instances of the same class ServerManager that draws a cube. The draw method for ServerManager is:

        public void Draw(GraphicsDevice graphicsDevice, Matrix viewMatrix, Matrix projectionMatrix)    {        cubeEffect.World = Matrix.CreateTranslation(modelPosition); // Set the World matrix which defines the position of the cube        cubeEffect.View = viewMatrix; // Set the View matrix which defines the camera and what it's looking at        cubeEffect.Projection = projectionMatrix;        // Enable textures on the Cube Effect. this is necessary to texture the model        cubeEffect.TextureEnabled = true;        cubeEffect.Texture = cubeTexture;        // Enable some pretty lights        cubeEffect.EnableDefaultLighting();        // apply the effect and render the cube        foreach (EffectPass pass in cubeEffect.CurrentTechnique.Passes)        {            pass.Apply();            cubeToDraw.RenderToDevice(graphicsDevice);        }    }

Obviously there is something I am doing wrong. Any hint of where to look? (Maybe z-buffer or occlusion tests?)


Viewing all articles
Browse latest Browse all 33

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>