[SDL] Want to help with SDL 1.3?
MrPeach
gmane-jack at threeindians.com
Fri Jan 2 10:18:04 PST 2009
Donny Viszneki <donny.viszneki <at> gmail.com> writes:
>
> On Thu, Jan 1, 2009 at 2:08 PM, Sam Lantinga <slouken <at> devolution.com>
wrote:
> > For example, here's a good quick project for someone from the TODO list:
> > * Add diagonal line clipping to SDL_IntersectRectAndLine()
>
> On it.
>
> There are just two things I think need clearing up, though.
>
> 1) Does the line segment (*X1,*Y1)(*X2,*Y2) have direction? If it does
> not, that would mean SDL_IntersectRectAndLine() can swap those two
> points.
>
> 2) Should this function return integer values? As I just noted in the
> source code...
>
> /* The task of clipping a line with finite dx/dy ratios in a fixed-
> * precision coordinate space is not as immediately simple as it is
> * with coordinates of arbitrary precision. If the ratio of ratios
> * (dx1/dy1) / (dx2/dy2) is not integral, you must in fact *move* the
> * line a bit in order to clip it.
> */
>
Donny,
If one is concerned about the clipped line segment matching exactly the
unclipped line segment, one cannot simply reduce the clipped line segment to a
pair of coordinates.
To retain consistency with the original line, you must also retain the
Bresenham parameters (slope ratio and the current error value) at the start
pixel. With these values in hand, your clipped segment will exactly match the
unclipped segment.
This was one of the first graphics related code bits I worked on about 15 years
ago. The need was a software algo that would match the hardware accelerator
algo in use (this was for a "generic" windows display driver). My code could be
easily configured to match whatever rounding or directional rules the hardware
used. It was a fun bit of coding. Obviously overkill for this project, unless
you need that same sort of functionality.
I haven't looked at the 1.3 stuff, so I don't know if it allows more than just
the endpoints to be specified. If it doesn't then this whole post is pointless.
^_^
If there is a need, I can see if I have this in my archives somewhere. It is
encumbered though (the project is long dead and probably written off by it's
current owner Labtec) so if I do it's just for examples sake - you can't use
it.
MrPeach
More information about the SDL
mailing list