#### Archived

This topic is now archived and is closed to further replies.

# Co-ordinate Problem (I think)

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

## Recommended Posts

Hi, Ive just been setting up my first Direct3D application, basically showing a square on screen with the usual rotations and so forth. I can get the rotations working (with alittle help from the sdk docs) however the co-ordinates I give that should make a square make a rectangle, even when I modify the tutorial code it is a rectangle, Ill post my init code to see if anything is wrong with that or am I missing something or is my idea of co-ordinates for vertices in Direct3D just plain wrong? Thanks for any help. co-ordinate init code


struct StandardVertex
{
float X,Y,Z;
DWORD Colour;
};

#define STANDARDVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE)

StandardVertex Vert[] =
{
{-2.5f, -2.5f, 0.0f, 0xffff0000,},
{ -2.5f,  2.5f, 0.0f, 0xffff0000,},
{  2.5f, -2.5f, 0.0f, 0xffff0000,},

{ -2.5f,  2.5f, 0.0f, 0xffff0000,},
{  2.5f,  2.5f, 0.0f, 0xffff0000,},
{  2.5f, -2.5f, 0.0f, 0xffff0000
{ 0.0f, 0.0f, 0.0f, 0xffff0000,},
{ 0.0f, 1.0f, 0.0f, 0xffff0000,},
{ 1.0f, 0.0f, 0.0f, 0xffff0000,},

{ 0.0f,  1.0f, 0.0f, 0xffff0000,},
{ 1.0f,  1.0f, 0.0f, 0xffff0000,},
{ 1.0f, 0.0f, 0.0f, 0xffff0000,},
};

Direct3DDevice->CreateVertexBuffer(6*sizeof(StandardVertex),0,STANDARDVERTEX,D3DPOOL_DEFAULT,&Buffer,NULL);
VOID* pVertices;
Buffer->Lock(0,sizeof(Vert),(void**)&pVertices,0);
memcpy( pVertices,Vert,sizeof(Vert));
Buffer->Unlock();



bool CDirect3D::CreateFullScreenVersion(HWND WindowHandle, int Width, int Height)
{
Direct3DInterface = Direct3DCreate9(D3D_SDK_VERSION);

if(Direct3DInterface == NULL)
return(false);

D3DPRESENT_PARAMETERS  Parameters;
ZeroMemory(&Parameters,sizeof(D3DPRESENT_PARAMETERS));

Parameters.BackBufferWidth = Width;
Parameters.BackBufferHeight = Height;
Parameters.BackBufferFormat = D3DFMT_R5G6B5;
Parameters.MultiSampleType = D3DMULTISAMPLE_NONE;
Parameters.BackBufferCount = 1;
Parameters.hDeviceWindow = WindowHandle;
Parameters.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
Parameters.Windowed = false;
Parameters.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;

D3DCREATE_HARDWARE_VERTEXPROCESSING,
&Parameters, &Direct3DDevice)))
return(false);

ViewPort.X = 0;
ViewPort.Y = 0;
ViewPort.Width = Width;
ViewPort.Height = Height;
ViewPort.MinZ = 0.0f;
ViewPort.MaxZ = 1.0f;

if(FAILED(Direct3DDevice->SetViewport(&ViewPort)))
return(false);

Direct3DDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
Direct3DDevice->SetRenderState( D3DRS_LIGHTING, FALSE );



bool CDirect3D::DrawFrame()
{
if(FAILED(Direct3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0)))
return(false);

if(FAILED(Direct3DDevice->BeginScene()))
return(false);

D3DXMATRIXA16 matWorld;

UINT  iTime  = timeGetTime() % 1000;
FLOAT fAngle = iTime * (2.0f * D3DX_PI) / 1000.0f;
D3DXMatrixRotationY( &matWorld, fAngle );
Direct3DDevice->SetTransform( D3DTS_WORLD, &matWorld );

D3DXVECTOR3 vEyePt( 0.0f, 0.0f,-25.0f );
D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
D3DXMATRIXA16 matView;

D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
Direct3DDevice->SetTransform( D3DTS_VIEW, &matView );

D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
Direct3DDevice->SetTransform( D3DTS_PROJECTION, &matProj );

Direct3DDevice->SetStreamSource( 0, Buffer, 0, sizeof(StandardVertex) );
Direct3DDevice->SetFVF(STANDARDVERTEX);
Direct3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2 );

if(FAILED(Direct3DDevice->EndScene()))
return(false);

if(FAILED(Direct3DDevice->Present( NULL, NULL, NULL, NULL )))
return(false);

return(true);
}

Ballistic Programs

##### Share on other sites
you have the 3rd parm of your call to D3DXMatrixPerspectiveFovLH set to 1.0. this is the aspect ratio and is normally set to 4.0f/3.0f, or more technically correct, the width of your rendering buffer(window), in pixels, divided by the height of your rendering buffer(window).

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 15
• 9
• 10
• 12
• ### Forum Statistics

• Total Topics
633004
• Total Posts
3009835
• ### Who's Online (See full list)

There are no registered users currently online

×