dsk
dsk

Reputation: 33

Draw order of 3D-Models in XNA

i'm having trouble with drawing 3D-Models in the right order in XNA.

Here are two images that describe the problem:

Pic1: http://imgur.com/wGPIk&L5AY1l Pic2: http://imgur.com/wGPIkl&L5AY1

The ball is moving downwards and as soon as it intersects the terrain, the perspective is changing so that it looks like as if the ball is behind the terrain.

If i change the order of drawing, it will look like the ball is on top of the terrain all the time..

Can someone please explain how to solve this problem?

Thanks in advance

Upvotes: 3

Views: 2256

Answers (2)

dowhilefor
dowhilefor

Reputation: 11051

This looks like a ZBuffer problem. Have you checked that your Zbuffer is enabled and working? Try what David Lively said. if that works, check that you don't draw your 3D models Inside the Begin and End calls of the SpriteBatch class. Begin readies the device for drawing 2D objects, if you try now to call 3D drawing this can't work. End makes sure that everything, set for 2D, is unset and reverted to the states before the Begin call.

Upvotes: 1

3Dave
3Dave

Reputation: 29051

The problem is the SpriteBatch call that draws your FPS counter in the corner.

SpriteBatch changes the state of the graphics device. Whenever you're done drawing your 2D objects (in this case, your frame rate counter in the upper-left corner), you need to restore the device state.

After calling SpriteBatch.End(), add this code:

device.DepthStencilState = DepthStencilState.Default;

where device is a reference to the current GraphicsDevice that you're drawing with.

Upvotes: 10

Related Questions