Advertisement

world to screen coords

Started by February 27, 2000 04:55 PM
1 comment, last by ViPeR007 24 years, 6 months ago
Im trying to find a way of converting my sprite''s world coordinates to screen coordinates so that I can use my drawing function to draw them (of course the function takes screen coordinates, not world coordinates). I''ve got a RECT that goes around my sprite and a RECT that is around my actual viewport. Then I test if the two intersect and if they do I start drawing the sprite. Is there an equation that can convert (from the information gotten by the RECTs) the world coordinates to the screen coordinates so that it draws it in the right place? Thanx, ViPeR
Pretty simple:

SpriteRect.left -= ViewportRect.left;
SpriteRect.right -= ViewportRect.left;
SpriteRect.top -= ViewportRect.top;
SpriteRect.bottom -= ViewportRect.bottom;

If you didn''t have ViewportRect in world coordinates you need to convert that first by checking the camera''s worldcoordinates.
Advertisement
Hm, here is what I have right now. Its giving the wrong effect because it looks like the picture is moving along with the screen (its drawing it at world coordinates but the conversion must be messing up somewhere).

RECT ViewPort;
ViewPort.left = Map->MapGetXPosition();
ViewPort.top = Map->MapGetYPosition();
ViewPort.right = Map->MapGetXPosition() + 1024;
ViewPort.bottom = Map->MapGetYPosition() + 768;



RECT Sprite;
Sprite.left = Test->m_PosX;
Sprite.top = Test->m_PosY;
Sprite.right = Test->m_PosX + TestTile->m_BlockWidth;
Sprite.bottom = Test->m_PosY + TestTile->m_BlockHeight;



RECT Result;

Test->m_PosX = 1300;
Test->m_PosY = 1300;

if (IntersectRect(&Result, &ViewPort, &Sprite))
{
int X = Sprite.left - ViewPort.left;
int Y = Sprite.top - ViewPort.top;

test++;


Test->Draw(Screen->GetBack() , X, Y, CDXBLT_TRANS );


}

m_PosX/Y are the positions of the sprite in the world. Everything else should be pretty easy to understand. Anyone see what is wrong here?

Thanx,
ViPeR

Edited by - ViPeR007 on 2/28/00 4:28:51 PM

This topic is closed to new replies.

Advertisement