#### Archived

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

# Help with square

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

## Recommended Posts

I have 2 triangles rendering to the screen. The screen resolution is 640x480 and I am trying to make a perfect square 100x100 in size. However, what I am getting is a rectangle like so ............... . . . . . . ............... and not an actual square. The values I am storing into my VB and IBs are here
ptrVertexBuffer[StartVertex + 0].x = iX;
ptrVertexBuffer[StartVertex + 0].y = iY;
ptrVertexBuffer[StartVertex + 0].z = 0.5f;
ptrVertexBuffer[StartVertex + 0].rhw = 1.0f;
ptrVertexBuffer[StartVertex + 0].color = D3DCOLOR_ARGB(0,255,0,0);

ptrVertexBuffer[StartVertex + 1].x = iWidth;
ptrVertexBuffer[StartVertex + 1].y = iY;
ptrVertexBuffer[StartVertex + 1].z = 0.5f;
ptrVertexBuffer[StartVertex + 1].rhw = 1.0f;
ptrVertexBuffer[StartVertex + 1].color = D3DCOLOR_ARGB(0,255,0,0);

ptrVertexBuffer[StartVertex + 2].x = iX;
ptrVertexBuffer[StartVertex + 2].y = iHeight;
ptrVertexBuffer[StartVertex + 2].z = 0.5f;
ptrVertexBuffer[StartVertex + 2].rhw = 1.0f;
ptrVertexBuffer[StartVertex + 2].color = D3DCOLOR_ARGB(0,255,0,0);

ptrVertexBuffer[StartVertex + 3].x = iWidth;
ptrVertexBuffer[StartVertex + 3].y = iHeight;
ptrVertexBuffer[StartVertex + 3].z = 0.5f;
ptrVertexBuffer[StartVertex + 3].rhw = 1.0f;
ptrVertexBuffer[StartVertex + 3].color = D3DCOLOR_ARGB(0,255,0,0);

ptrIndexBuffer[StartIndex + 0] = StartVertex + 0;
ptrIndexBuffer[StartIndex + 1] = StartVertex + 1;
ptrIndexBuffer[StartIndex + 2] = StartVertex + 2;
ptrIndexBuffer[StartIndex + 3] = StartVertex + 2;
ptrIndexBuffer[StartIndex + 4] = StartVertex + 1;
ptrIndexBuffer[StartIndex + 5] = StartVertex + 3;

iY and iX are both 50. iWidth and iHeight are both 100. I tried offsetting by a factor of the aspect ratio but that didn''t generate a square either, though it was closer. I''m working with the tutorials on here for a GUI and the functions VertxToPixel and VertyToPixel given below don''t help either. I''ve checked to make sure that all of my surfaces were indeed 640x480.
int cBaseGUIWindow::VirtxToPixels(int virtx)
{
int iWidth = (m_pParent) ?
(m_pParent->GetGUIWindowPos().right -
m_pParent->GetGUIWindowPos().left) :
GetGameWidth();
return((int)((double)virtx*(double)iWidth/GUI_SCALEX));
}

int cBaseGUIWindow::VirtyToPixels(int virty)
{
int iHeight = (m_pParent) ?
(m_pParent->GetGUIWindowPos().bottom -
m_pParent->GetGUIWindowPos().top) :
GetGameHeight();
return((int)((double)virty*(double)iHeight/GUI_SCALEY));
}

I''m guessing there is some sort of offset that I need to apply in order to work directly with screen pixels to get the shapes/sizes I want. Apparently pixels are somewhat rectangular in nature. Thanks for any help, Webby

##### Share on other sites
Maybe thats because your perspective''s aspect ratio isn''t 1:1.

(Correct me if I''m wrong)

--
You''re Welcome,
Rick Wong

- sitting in his chair doing the most time-consuming thing..

##### Share on other sites
Aspect ratio is indeed .75 (480/640).
I''ve tried adjusting the height by this amount but the
square is still a bit rectangular. That''s why i was asking here if there wasn''t maybe some other value I had to adjust by.

Webby

##### Share on other sites
Hmmm. It appears that multiplying width by .75 and
height by 1.25 fixed the issue.
I guess it''s to take into account the discrepency from both directions.

Multiplying by 2*the discrepency on a single side will likely achieve the same goal. None of the tutorials mention having to do this....

Webby