Triangles visibility

Started by
10 comments, last by Jerry.Mouse 9 years, 11 months ago

Hello, I have a petty problem. I have two triangles - see "triangles perspective.bmp"

Axis +X is marked RED cross, +Y is marked GREEN cross, axis +Z is marked BLUE cross.

Both are ClockWise and CULL mode is off.

// TRIANGLE A, GREEN color, is close to me
v[0].pose = SlimDX::Vector3( -0.5f, +0.0f, -10.5f );
v[0].color = 0xff00ff00; //
v[1].pose = SlimDX::Vector3( +0.0f, +1.5f, -10.5f );
v[1].color = 0xff00ff00; //
v[2].pose = SlimDX::Vector3( +5.5f, +0.0f, -10.5f );
v[2].color = 0xff00ff00; //
// TRIANGE B, BLUE color, ias FAR / further
v[3].pose = SlimDX::Vector3( -3.5f, +0.0f, 10.5f );
v[3].color = 0xff0000f0; //
v[4].pose = SlimDX::Vector3( +0.0f, +2.5f, 10.5f );
v[4].color = 0xff0000f0; //
v[5].pose = SlimDX::Vector3( +3.5f, +0.0f, 10.5f );
v[5].color = 0xff0000f0; //
sl_device->SetTransform( SlimDX::Direct3D9::TransformState::View,
SlimDX::Matrix::LookAtLH( SlimDX::Vector3( 0.0f, 0.0f, -15.0f ), //
SlimDX::Vector3( 0.0f, 0.0f, +15.0f ),
SlimDX::Vector3( 0.0f, +1.0f, 0.0f ) ) );
If camera is set to Z: -15 to +15, I see this: "triangle camera.bmp". The Blue triangle is depicted in front ot the green.
It is not normal. Please, where is error ?
Thanks.
"triangle camera.bmp" - no World rotation
sl_device->SetTransform( SlimDX::Direct3D9::TransformState::World,
SlimDX::Matrix::Translation( 0.0f, 0.0f, 0.0f ) *
SlimDX::Matrix::RotationY( 0.0f ) *
SlimDX::Matrix::RotationX( 0.0f ) *
SlimDX::Matrix::RotationZ( 0.0f )
);
"triangles perspective.bmp", small rotation
sl_device->SetTransform( SlimDX::Direct3D9::TransformState::World,
SlimDX::Matrix::Translation( 0.0f, 0.0f, 0.0f ) *
SlimDX::Matrix::RotationY( +0.3f ) *
SlimDX::Matrix::RotationX( -0.2f ) *
SlimDX::Matrix::RotationZ( 0.0f )
);
Advertisement

It sounds like you don't have depth testing enabled. You'll need a depth buffer and the proper depth-stencil state set in order to get the correct sorting of those triangles.

Great. How can I set depth buffer ?

If I set

_presentParameters->EnableAutoDepthStencil = true;

I see nothing ... black screen sad.png


The Blue triangle is depicted in front ot the green.

That's correct. Your camera is at -15, the Blue triangle is at -10.5, the Green triangle is at +10.5.

EDIT: I was incorrect. I had the colors reversed. See response below.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

_device->SetRenderState( SlimDX::Direct3D9::RenderState::ZEnable, true );

leads to D3DERR_INVALIDCALL: Invalid call (-2005530516)

at

_device->Clear( SlimDX::Direct3D9::ClearFlags::Target | ClearFlags::ZBuffer, SlimDX::Color4( SlimDX::Color3( 0.0f, 0.0f, 0.0f )) , 1.0f, 0 );

no no BLUE triangle is at +10.5f, GREEN at -10.5f,

it means, that GREEN is before BLUE, I should have seen GREEN first, that BLUE

terrible

COLOR 0xff00ff00;

means:

FF is alpha, 00 is RED, FF is GREEN, 00 is BLUE = GREEN

FF is aplha, 00 is RED, FF is GREEN, F0 is BLUE = BLUE

BLUE triangle is far


no no BLUE triangle is at +10.5f, GREEN at -10.5f,

Apologies. You are correct.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

nice,

please, can someone take a look at this simple severaal-lines code.

https://onedrive.live.com/redir?resid=6C2D62DDB1948596%21287

I really do not know why blue triangle is before green. It is not normal....maybe I am dumbass

No, you're experiencing the frustrating first steps with a low level API. There are dozens of things that can go wrong. As you can see, that error isn't very informative, you wanna help yourself with Direct3D Programming Tip #5: Use The Debug Runtime. Post the error here when you got it working.

As Samith points out, you need a depth buffer and must set the related renderstates before drawing, This explains it quite well.

Also, get familiar with a graphics debugger, e.g. the tool PIX coming with the SDK (PIXWin.exe in the utilities directory).

PS: In the future you can post such things in the DirectX subforum here.

This topic is closed to new replies.

Advertisement