Triangles visibility

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

ERROR was repaired.

My biggest problem is why BLUE triangle is in front of GREEN triangle ...

source code is here

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

Yes I am frustrated .... very much ...

Advertisement

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

This topic is closed to new replies.

Advertisement