Jump to content
  • Advertisement
Sign in to follow this  
Jerry.Mouse

Triangles visibility

This topic is 1490 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 )  
                                             );
Edited by Jerry.Mouse

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Great. How can I set depth buffer ? 

If I set 

 

_presentParameters->EnableAutoDepthStencil = true;

 

I see nothing ... black screen sad.png

Share this post


Link to post
Share on other sites

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.

Edited by Buckeye

Share this post


Link to post
Share on other sites

_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 ); 

Share this post


Link to post
Share on other sites

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 

Share this post


Link to post
Share on other sites

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 

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!