Object disappears after setting Projection

Started by
4 comments, last by The Pentium Guy 19 years, 8 months ago
Hey, I'm trying to create a skybox. In my game, my meshes render just fine. But when I create a skybox (6 textured quads) nothing appears. So I tried messing around with quads(loading textures onto vertex buffers and rendering). When I render my quad at 0,0,1 it appers fine. But when I render my quat at 0,0,1.000001, it dissappears (a little exxaguration, but you know what I mean, any Z > 1, it disappears) Yes, I'm clearing my ZBuffer, and Yes, i'm setting a ZDepth of 1 D3Ddev.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.FromArgb(0, 0, 225), 1.0, 0) (1.0 is the max it can go). So I thought it had to do with the Projection matrix. When i set up the projection matrix: D3Ddev.Transform.Projection = Matrix.PerspectiveFovLH(System.Convert.ToSingle(Math.PI) / 4, mDisplaymode.Width / mDisplaymode.Height, 1.0F, 1000.0F) the object disappears altogether! even when the Z is set to 1. Does anyone know how to fix these problems? All i want to do is use that same projection matrix, and a matrix LookAtLH to render my meshes as well as quads. For some reason any quad with a Z > 1 disappears. Thanks pent
Advertisement
what is your world and view matrix set to?
paste the code that you use to position your quad. Are you rendering using the ID3DXSprite interface? That requires a worldview transform to be set..
Also check the normals of the skybox, if you turn off culling and can see it then your problem is inverted normals.
________________
"I'm starting to think that maybe it's wrong to put someone who thinks they're a Vietnamese prostitute on a bull"       -- Stan from South Park
Lab74 Entertainment | Project Razor Online: the Future of Racing (flashsite preview)
My object is centered (by default) at 0,0,0.
Its height,depth,and width are 512. so the backleft coordinate is (-256,-256,-256), its far right coordinate is (256,256,256)

My World is set to Identity.

My View is set to:
D3Ddev.Transform.View = Matrix.LookAtLH(new Vector3(0,0,0), New Vector3(0, 0, 1), New Vector3(0, 1, 0))

My Projectoin is set to:
D3Ddev.Transform.Projection = Microsoft.DirectX.Matrix.PerspectiveFovLH(CSng(Math.PI) / 4, 800.0F / 600.0F, 0.0F, 300.0F)

Nah, I'm not using a d3dxsprite, i created my own class (using CustomVertex.PositionTextured)

I turned Culling and I can't see it :).;

Never set your nearZ to 0. It's recommended to make it as large as possible. Also, it's recommended to keep the ratio of farZ to nearZ less than 1000.

Setting nearZ to 0 totally messes up the z-buffer (if you look into how perspective projection matrices are formed, you'll find that there are divisions by nearZ in more than one place).

Thanks,
But unfortunately, it didn't work

D3Ddev.Transform.Projection = Microsoft.DirectX.Matrix.PerspectiveFovLH(CSng(Math.PI) / 4, 800.0F / 600.0F, -300.0F, 300.0F)

didn't work

D3Ddev.Transform.Projection = Microsoft.DirectX.Matrix.PerspectiveFovLH(CSng(Math.PI) / 4, 800.0F / 600.0F, 1.0F, 300.0F)

also didn't work

edit:
D3Ddev.Transform.Projection = Microsoft.DirectX.Matrix.PerspectiveFovLH(CSng(Math.PI) / 4, 800.0F / 600.0F, 1000, 8000.0F)

didn't work either.

pent
Someone told me it was becuase the winding order of my vertices was ccw, so he told me to do scale by (-1,-1,-1)

I tried:
D3Ddev.Transform.World = Matrix.Multiply(D3Ddev.Transform.World, Matrix.Scaling(New Vector3(-1, -1, -1)))

and

D3Ddev.Transform.World = Matrix.scaling(New Vector3(-1, -1, -1)))

This topic is closed to new replies.

Advertisement