🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

INFO: Clipping Help

Started by
0 comments, last by Matthew Allen 24 years, 5 months ago
Having trouble with clipping? If you''re having trouble because you are passing the blitter coordinates that are off the screen (example: (-5,-6) or (805,606) on an 800x600 screen), use code like the stuff below. I was doing this the hard way for a long time before I realized how easy it was: if ( xTo < 0 ) { rcFrom.left -= xTo; xTo = 0; } if ( yTo < 0 ) { rcFrom.top -= yTo; yTo = 0; } if ( xTo + rcFrom.right - rcFrom.left >= SCREEN_W ) { rcFrom.right -= xTo + rcFrom.right - rcFrom.left - SCREEN_W; } if ( yTo + rcFrom.bottom - rcFrom.top >= SCREEN_H ) { rcFrom.bottom -= yTo + rcFrom.bottom - rcFrom.top - SCREEN_H; } if ( rcFrom.right - rcFrom.left <= 0 // rcFrom.bottom - rcFrom.top <= 0 ) return TRUE; rcFrom is the source rectangle and xTo and yTo are the destination coordinates. This could, of course, be used for any rectangle; it doesn''t need to be the screen. Hope this helps someone... - mallen22@concentric.net
- http://mxf_entertainment.tripod.com/
Advertisement
This is what I do when using the IDirectDrawSurface3->Blt() function, to fill out the Src RECT and Destination RECT structures:

ddctrl_Scr* is the height and width of the screen
x and y are the desired screen coordinates. Width and Height are the sprite''s (src surface''s) dimensions...

For some reason, specifying the real right and bottom coordinate for a 10x10 image (meaning bottom = 9 and right = 9) makes it become 9x9 on screen. So, I pass a 11x11 rectangle for a 10x10 surface, etc. ...

if ((y >= ddctrl_ScrHeight) // (x >= ddctrl_ScrWidth) // (y+height) < 0 // (x+width) < 0)
{
return FALSE;
}

if (y < 0)
{
SpriteRect.top = -y;
ScreenRect.top = 0;
}
else
{
SpriteRect.top = 0;
ScreenRect.top = y;
}

if (y+height > ddctrl_ScrHeight)
{
SpriteRect.bottom = ddctrl_ScrHeight - y;
ScreenRect.bottom = ddctrl_ScrHeight;
}
else
{
SpriteRect.bottom = height;
ScreenRect.bottom = y+height;
}

if (x < 0)
{
SpriteRect.left = -x;
ScreenRect.left = 0;
}
else
{
SpriteRect.left = 0;
ScreenRect.left = x;
}

if (x+width > ddctrl_ScrWidth)
{
SpriteRect.right = ddctrl_ScrWidth - x;
ScreenRect.right = ddctrl_ScrWidth;
}
else
{
SpriteRect.right = width;
ScreenRect.right = x+width;
}

Åke Wallebom

This topic is closed to new replies.

Advertisement