0
\$\begingroup\$

New to XNA (3D) -- familiar with OpenGL (but it has been a few years).

I've been working on an engine that should be a 3D Isometric View, but I'm having issues with things rendering. I wouldn't be shocked if I'm doing it the "wrong" way.

To start -- I'm assembling a bunch of terrain, which is procedurally generated into a Vertex. I'm using X/Y as my ground (N/S/E/W) coordinates and Z as my vertical (Up/Down). I assemble a map into the VertexBuffer based on its absolute world coordinates, i.e. Map is 256x256 tiles; a Map is a Tile on the world, also 256x256, so 0,0 Position of the Map on the World would be 0,0 -> 255,255; world position 1,0 would contain 256,0 -> 511,255 (top left -> bottom right).

I've followed a few tutorials and thankfully gotten some help on setting things up, but I feel as though something is still "wrong." My scene is not drawing correctly. It looks as though only ONE face of my scene is being drawn -- perhaps I haven't setup the Depth buffer correctly? When I rotate (I just change Rotation on the object pCamera), once I turn ~90-180 degrees, I start missing pieces of the Mesh. To me, it seems like the Depth isn't configured properly. I know in GL, we had to manually set the DEPTH_BIT / flag to on. I haven't set a World matrix to this BasicEffect, since the VertexBuffer is already built in the World coordinates.

I've confirmed the VertexBuffer is properly written/assembled. The values are all correct. The VertexBuffer is full of triangles only -- so I'm just using a TriangleList.

The VertexBuffer (TileMeshVertexBuffer) is being attached to a BasicEffect (TileMeshEffect), and this is the extent of my code:

            TileMeshEffect = new BasicEffect( GraphicsDevice );

            if ( _priorResolution != pCamera.Resolution )
            {
                Single Width = pCamera.Resolution.Width / MapTile.DIMENSION;
                Single Height = pCamera.Resolution.Height / MapTile.DIMENSION;

                TileMeshEffect.Projection = Matrix.CreateOrthographic( Width, Height, 1, 2000 );

                _priorResolution = pCamera.Resolution;
            }

            if ( _priorCenter != pCamera.Center || _priorRelativePosition != pCamera.RelativePosition || _priorRotation != pCamera.Rotation )
            {
                Single AngularUnit = pCamera.Resolution.Height / MapTile.DIMENSION;
                //pCamera.RelativePosition is 0, 0, 20
                //pCamera.Center is 128,128,60 (center of the mesh -- current elevation for the tile is at 50, so the middle tile it is focused above is 128,128,50; or composed of 127,127,50 -> 128,127,50 -> 128,128,50 and 127,127,50 -> 128,128,50 -> 127,128,50 (two triangles).
                //I've confirmed the other faces are correct for this tile as well, since it is actually rendering a cube.

                //The goal is to rotate around the Z axis -- perhaps this is the part that is wrong, but I feel as though I'd still see cubes, just rendered unusually.

                Vector3D CameraLocation = new Vector3D( pCamera.Center.X + pCamera.RelativePosition.X + AngularUnit * Math.Cos( pCamera.Rotation ),
                    pCamera.Center.Y + pCamera.RelativePosition.Y + AngularUnit * Math.Sin( pCamera.Rotation ), pCamera.Center.Z + pCamera.RelativePosition.Z );

                TileMeshEffect.View = Matrix.CreateLookAt( CameraLocation.ToVector3(), pCamera.Center.ToVector3(), Vector3.UnitZ );

                _priorCenter = pCamera.Center;
                _priorRelativePosition = pCamera.RelativePosition;
                _priorRotation = pCamera.Rotation;
            }

            //Texture is good -- all tiles are only mapping to one tile, statically on the texture, nothing else.
            TileMeshEffect.Texture = TileMeshTexture;
            TileMeshEffect.TextureEnabled = true;


                TileMeshEffect.CurrentTechnique.Passes[0].Apply();
                GraphicsDevice.SetVertexBuffer( TileMeshVertexBuffer );
                GraphicsDevice.DrawPrimitives( PrimitiveType.TriangleList, 0, TileMeshVertexBuffer.VertexCount / 3 );

I've cut and pasted things -- but this is essentially all I have. Aside from that, the GraphicsDeviceManager has the following set:

        Graphics = new GraphicsDeviceManager( this )
        {
            PreferredBackBufferHeight = 720,
            PreferredBackBufferWidth = 1280,
        };

I'm setting normals on each of the Triangles in my VertexBuffer -- so they're VertexPositionNormalTexture's -- and again, I've confirmed that these values are all correct.

This is what I see: http://imgur.com/a/irgoD

EDIT:

I've added the following code (Culling!) before I render the scene, and I get MUCH closer. However, I still have some issues with rotation, wherein pieces do not render.

                GraphicsDevice.RasterizerState = new RasterizerState()
                {
                    CullMode = CullMode.None
                };

http://imgur.com/a/oea9r

There are now "holes" in the terrain as it rotates.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

...as we should always do -- check your code over and over -- for some reason, my code wasn't drawing the "bottom" set of triangles (user-error). Oy.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .