Directx 3D the farther object covers the nearer object -
i'm new directx in c#, , there question confused me lot, want render 2 cubes on screen, 1 near camera , other far camera, expected nearer 1 in front of further one, in fact, depends on rendering sequence, last rendered 1 in front of other, i've tried clear z-buffer not work @ all, i'm wondering if there i'm doing wrong?
here code snippet
private void form1_load(object sender, eventargs e) { presentparameters presentparams = new presentparameters(); presentparams.windowed = true; presentparams.swapeffect = swapeffect.discard; presentparams.enableautodepthstencil = true; presentparams.autodepthstencilformat = depthformat.d16; device = new device(0, devicetype.hardware, this, createflags.mixedvertexprocessing, presentparams); device.vertexformat = customvertex.positioncolored.format; device.renderstate.cullmode = cull.counterclockwise; device.renderstate.lighting = false; matrix projection = matrix.perspectivefovlh((float)math.pi / 4, this.width / this.height, 0f, 10000.0f); device.transform.projection = projection; } protected override void onpaint(painteventargs e) { cube = new cube(new vector3(0, 0, 0), 5); cube b = new cube(new vector3(0, 0, 15), 5); device.clear(clearflags.target | clearflags.zbuffer, color.darkgray, 1, 0); device.beginscene(); matrix viewmatrix = matrix.lookatlh(cameraposition, targetposition, up); device.transform.view = viewmatrix; device.drawindexeduserprimitives(primitivetype.trianglelist, 0, 8, 12, a.indexdata, false, a.getvertices()); device.drawindexeduserprimitives(primitivetype.trianglelist, 0, 8, 12, b.indexdata, false, b.getvertices()); device.endscene(); device.present(); }
alright, fixed problem, changing
matrix projection = matrix.perspectivefovlh((float)math.pi / 4, this.width / this.height, 0f, 10000.0f);
to
matrix projection = matrix.perspectivefovlh((float)math.pi / 4, this.width / this.height, 1f, 10000.0f);
but don't know reason, , why happens, know that?
Comments
Post a Comment