Please help me with clipping algoritm

Started by
2 comments, last by ZomeonE 24 years, 3 months ago
I've been thinking and thinking what could be wrong, but I'm too tired to figure that out so maybe you can help me. It looks like this:
quote: int Blt_Clipped(int x, int y, int width, int height, LPDIRECTDRAWSURFACE7 surface) { RECT src; if((x >= SCREEN_WIDTH) // (y >= SCREEN_HEIGHT) // ((x + width) <= 0) // ((y + height) <= 0)) //Check if surface is totally off the screen return 0; int x1 = x; // Compute bounding box of surface int y1 = y; int x2 = x1 + width; int y2 = y1 + height; if (x1 < 0) // Check if surface is off the left edge x1 = 0; if (y1 < 0) // Check if surface is off the top y1 = 0; if (x2 >= SCREEN_WIDTH) //Check if the surface has gone off the screen to the right x2 = SCREEN_WIDTH; if (y2 >= SCREEN_HEIGHT) // Check if the surface har gone off the bottom of the screen y2 = SCREEN_HEIGHT; src.top = y1 - y; // Calculate which part of src.left = x1 - x; // the surface to use src.bottom = y2 - y1; // when blitting src.right = x2 - x1; backsurf->BltFast(x1, y1, surface, &src, DDBLTFAST_WAIT); // Blit surface to backbuffer return 0; // Return function }
The problem is that the bitmap is clipped on all sides when partially outside the screen on the left or top side. This doesn't happen on the right or bottom side of the screen. What could i do to make it work? Edited by - ZomeonE on 1/11/00 11:32:39 AM Edited by - ZomeonE on 1/11/00 11:47:03 AM
Advertisement
I really need some help, isn''t there anyone who can help me?
ZomeonE, a good practice, if you want to understand your code or if you want anyone else to understand it (which is a mild pre-requisite for them helping you) is to comment it.

It might look obvious to you what it does but it adds a factor of ten to the difficulty of anyone else trying to understand it. Yes, even for the simplest code.

Besides, if you make this effort for others, they may be more inclined to return the gesture and help you.

Mike
There''s no need to answer, I figured it out by my self.

Thankz anyway!

Correction:

src.bottom = y2 - y;
src.right = x2 - x;

This topic is closed to new replies.

Advertisement