• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Jerry.Mouse

Triangles visibility

11 posts in this topic

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
0

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

0

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
0

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

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 

0

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 

0

Share this post


Link to post
Share on other sites


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

 

Apologies. You are correct.

0

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.
0

Share this post


Link to post
Share on other sites

WOU, it is really working. I feel so free wub.png  .. ecstatic-ally

So, here is working source code, maybe, it will help to someone....

 

 

#pragma once
 
namespace CLRW58 {
 
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Threading; 
 
using namespace SlimDX;
using namespace SlimDX::Direct3D9;
using namespace SlimDX::DirectInput;
 
 
 
/// <summary>
/// Summary for Form1
///          resources associated with this form.
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
  
SlimDX::Direct3D9::PresentParameters^ sl_pp;
SlimDX::Direct3D9::Device^ sl_device;  
  SlimDX::Direct3D9::Direct3D^ sl_direct3D;
SlimDX::Direct3D9::VertexBuffer^ sl_vb; 
SlimDX::Direct3D9::VertexBuffer^ sl_vb2; 
SlimDX::Direct3D9::VertexBuffer^ sl_vb3; 
SlimDX::Direct3D9::IndexBuffer^ sl_ib;  
 
  value struct CustomVertex {
 SlimDX::Vector3 pose;
 Int32 color; 
}; 
 
 
 
public:
Form1(void)
{
InitializeComponent();
 
this->Show(); 
 
   sl_pp = gcnew SlimDX::Direct3D9::PresentParameters();
 
   sl_pp->Windowed = true;
  sl_pp->SwapEffect = SlimDX::Direct3D9::SwapEffect::Discard;
sl_pp->EnableAutoDepthStencil = true;  //  Z Buffer
sl_pp->BackBufferCount = 1;
sl_pp->BackBufferWidth = this->panel1->Width;
sl_pp->BackBufferHeight = this->panel1->Height;
   sl_pp->AutoDepthStencilFormat = SlimDX::Direct3D9::Format::D16;  // Z buffer format
 
sl_direct3D = gcnew SlimDX::Direct3D9::Direct3D();
sl_device = gcnew SlimDX::Direct3D9::Device( sl_direct3D,
                                            0,
SlimDX::Direct3D9::DeviceType::Hardware,
      this->panel1->Handle,
SlimDX::Direct3D9::CreateFlags::SoftwareVertexProcessing, // ::HardwareVertexProcessing,
     sl_pp  );
 
 
 
 
  sl_device->SetRenderState( SlimDX::Direct3D9::RenderState::Lighting, false );
 
 
    // TWO TRIANGLES, BLUE and GREEN
//***************************************************************
  sl_vb = gcnew SlimDX::Direct3D9::VertexBuffer( sl_device,
                                               6 * 16,
SlimDX::Direct3D9::Usage::None,
SlimDX::Direct3D9::VertexFormat::Position | SlimDX::Direct3D9::VertexFormat::Diffuse, //SlimDX::Direct3D9::VertexFormat::Diffuse,
  SlimDX::Direct3D9::Pool::Managed );
 
 
array<CustomVertex>^ v = gcnew array<CustomVertex>(6);
 
 
// GREEN
  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; // 
 
// BLUE
  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; // 
    
  SlimDX::DataStream^ sl_ds;
sl_ds = sl_vb->Lock( 0,0,SlimDX::Direct3D9::LockFlags::None );    
sl_ds->WriteRange( v ); //Write( v );
sl_vb->Unlock(); 
 
//***************************************************************
 
    sl_vb3 = gcnew SlimDX::Direct3D9::VertexBuffer( sl_device,
                                               18 * 16,
SlimDX::Direct3D9::Usage::None,
SlimDX::Direct3D9::VertexFormat::Position | SlimDX::Direct3D9::VertexFormat::Diffuse, //SlimDX::Direct3D9::VertexFormat::Diffuse,
  SlimDX::Direct3D9::Pool::Managed );
 
 
 
 
array<CustomVertex>^ v3 = gcnew array<CustomVertex>(18);
 
// cross
  v3[0].pose  = SlimDX::Vector3( -10.0f, 0.0f, 0.0f );
v3[0].color = 0xffff0000; //    
  v3[1].pose  = SlimDX::Vector3( +10.0f, 0.0f, 0.0f );
    v3[1].color = 0xffff0000; //   
  v3[2].pose  = SlimDX::Vector3( 0.0f, -10.0f, 0.0f );
    v3[2].color = 0xffff0000; //    
  v3[3].pose  = SlimDX::Vector3( 0.0f, +10.0f, 0.0f );
    v3[3].color = 0xffff0000; //   
  v3[4].pose  = SlimDX::Vector3( 0.0f, 0.0f, -10.0f );
    v3[4].color = 0xffff0000; //   
  v3[5].pose  = SlimDX::Vector3( 0.0f, 0.0f, +20.0f );
    v3[5].color = 0xffff0000; //   
 
// markers
// +X
  v3[6].pose  = SlimDX::Vector3( +10.0f, 1.0f, 0.0f );
    v3[6].color = 0xffff0000; //   
  v3[7].pose  = SlimDX::Vector3( +10.0f, -1.0f, 0.0f );
    v3[7].color = 0xffff0000; //   
  v3[8].pose  = SlimDX::Vector3( +10.0f, 0.0f, -1.0f );
    v3[8].color = 0xffff0000; //    
  v3[9].pose  = SlimDX::Vector3( +10.0f, 0.0f, +1.0f );
    v3[9].color = 0xffff0000; //   
 
// +Y
  v3[10].pose  = SlimDX::Vector3( -1.0f, +10.0f, 0.0f );
    v3[10].color = 0xff00ff00; //    
  v3[11].pose  = SlimDX::Vector3( +1.0f, +10.0f, 0.0f );
    v3[11].color = 0xff00ff00; // 
  v3[12].pose  = SlimDX::Vector3( 0.0f, +10.0f, +1.0f );
    v3[12].color = 0xff00ff00; //    
  v3[13].pose  = SlimDX::Vector3( 0.0f, +10.0f, -1.0f );
    v3[13].color = 0xff00ff00; // 
 
// +Z
  v3[14].pose  = SlimDX::Vector3( 0.0f, -1.0f, +10.0f );
    v3[14].color = 0xff0000ff; //    
  v3[15].pose  = SlimDX::Vector3( 0.0f, +1.0f, +10.0f );
    v3[15].color = 0xff0000ff; // 
  v3[16].pose  = SlimDX::Vector3( -1.0f, 0.0f, +10.0f );
    v3[16].color = 0xff0000ff; //    
  v3[17].pose  = SlimDX::Vector3( +1.0f, 0.0f, +10.0f );
    v3[17].color = 0xff0000ff; // 
 
SlimDX::DataStream^ sl_ds3;
sl_ds3 = sl_vb3->Lock( 0,0,SlimDX::Direct3D9::LockFlags::None );    
  sl_ds3->WriteRange( v3, 0 , v3->Length ); //
sl_vb3->Unlock(); 
 
//***************************************************************
 
 
 
System::Drawing::Font^ _sysfont = gcnew System::Drawing::Font( "Arial", 20 );
SlimDX::Direct3D9::Font^ _font = gcnew SlimDX::Direct3D9::Font( sl_device, _sysfont );
 
    sl_device->SetRenderState( SlimDX::Direct3D9::RenderState::CullMode, SlimDX::Direct3D9::Cull::None ); //::Counterclockwise );// :Clockwise ); // ::None ); 
  sl_device->SetRenderState( SlimDX::Direct3D9::RenderState::Lighting, false ); 
    sl_device->SetRenderState( SlimDX::Direct3D9::RenderState::ZEnable, true ); 
 
SlimDX::Direct3D9::Sprite^ _sprite = gcnew SlimDX::Direct3D9::Sprite( sl_device );  
 
Int32 counter = 0;
 
float angle = 0; //
 
    SlimDX::DirectInput::DirectInput^ _directinput = gcnew SlimDX::DirectInput::DirectInput(); 
    SlimDX::DirectInput::Mouse^ mouse = gcnew SlimDX::DirectInput::Mouse( _directinput );
 
    mouse->Properties->AxisMode = SlimDX::DirectInput::DeviceAxisMode::Relative;   
 
    mouse->Acquire(); 
                   
    float pointM = -15.0f;
    Int32 value = 0;
 
while ( this->IsDisposed == false ) {
 
      value = mouse->GetCurrentState()->Z;
 
      if ( value > 0 ) {
         pointM = pointM + 1;
      }// 
      if ( value < 0 ) {
         pointM = pointM - 1;
      }// 
 
 
    // camera / frustum 
sl_device->SetTransform( SlimDX::Direct3D9::TransformState::View, 
                       SlimDX::Matrix::LookAtLH( SlimDX::Vector3( 0.0f,  0.0f, pointM ), // 
                      SlimDX::Vector3( 0.0f,  0.0f, 0.0f ), 
SlimDX::Vector3( 0.0f, +1.0f,  0.0f ) ) );
 
    
 
     // perspective projection
     /*
     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 )  
                            );  */
 
 
        sl_device->SetTransform( SlimDX::Direct3D9::TransformState::Projection, 
                        SlimDX::Matrix::PerspectiveFovLH( (float)Math::PI / 2, 1.76795f, 0.1f, 100.0f) );
 
     SlimDX::Color4 bkcolor( 255.0f, 0.0f, 0.0f, 0.0f );    
        sl_device->Clear( SlimDX::Direct3D9::ClearFlags::Target , SlimDX::Color4( SlimDX::Color3( 0.0f, 0.0f, 0.0f )) , 1.0f, 0 ); 
        sl_device->Clear( SlimDX::Direct3D9::ClearFlags::ZBuffer, SlimDX::Color4( SlimDX::Color3( 0.0f, 0.0f, 0.0f )) , 1.0f, 0 ); 
 
 
    sl_device->BeginScene(); 
 
// triangle
      sl_device->SetStreamSource( 0, sl_vb, 0 , sizeof(CustomVertex) );
  sl_device->VertexFormat = SlimDX::Direct3D9::VertexFormat::Position | SlimDX::Direct3D9::VertexFormat::Diffuse; 
sl_device->DrawPrimitives( SlimDX::Direct3D9::PrimitiveType::TriangleList, 0, 2 );
 
// reticle
      sl_device->SetStreamSource( 0, sl_vb3, 0 , sizeof(CustomVertex) ); 
  sl_device->VertexFormat = SlimDX::Direct3D9::VertexFormat::Position | SlimDX::Direct3D9::VertexFormat::Diffuse; 
  sl_device->DrawPrimitives( SlimDX::Direct3D9::PrimitiveType::LineList, 0, 9 ); 
 
 
// text 
_sprite->Begin( SlimDX::Direct3D9::SpriteFlags::AlphaBlend ); 
_font->DrawString( _sprite, "H e l l o : " + counter.ToString(), 20, 20, SlimDX::Color4( SlimDX::Color3( 1.0f, 1.0f, 1.0f ) ) );
_sprite->End(); 
 
 
  sl_device->EndScene(); 
 
  sl_device->Present(); 
 
     Application::DoEvents(); 
 
angle =  angle + (float)0.017;
if ( angle > ( Math::PI * 2 ) ) angle = 0; 
 
//Thread::Sleep(50); 
 
counter++;
 
}// while
 
 
   return;
 
//
//TODO: Add the constructor code here
//
}
 
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
 
delete sl_device;
delete sl_vb;
delete sl_vb2;
delete sl_vb3;
 
   
 
}
private: System::Windows::Forms::Panel^  panel1;
 
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
 
#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->panel1 = (gcnew System::Windows::Forms::Panel());
this->SuspendLayout();
// 
// panel1
// 
this->panel1->Location = System::Drawing::Point(0, 0);
this->panel1->Name = L"panel1";
this->panel1->Size = System::Drawing::Size(960, 543);
this->panel1->TabIndex = 0;
// 
// Form1
// 
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(996, 568);
this->Controls->Add(this->panel1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
 
}
#pragma endregion
 
 
};// public ref class Form1 : public System::Windows::Forms::Form
 
}// namespace CLRW58 
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0