http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gameprogrammer] Re: Constraining a line to a rectangle



On Tue, 2004-04-13 at 02:36, David Olofson wrote:
> On Tuesday 13 April 2004 06.35, Kevin Jenkins wrote:
> > In my game I have a series of lines.  For each line, it is possible
> > that one or both of the endpoints is outside the viewport, which is
> > smaller than the screen.  Given the endpoints of the line, I want
> > to modify these endpoints so I when I render a line between the two
> > endpoints, all rendering is done inside the viewport.
> [...]
> 
> It's usually called clipping, and it should be easy to find tons of 
> papers and code examples on various techniques. Try searching for 
> "computer graphics clipping lines" (without the quotes) or something 
> on your search engine of choice.
> 
> Or just try Cohen-Sutherland:
> 	
> http://www.cc.gatech.edu/grads/h/Hao-wei.Hsieh/Haowei.Hsieh/mm.html#sec2_3

Or Sutherland-Hodgman clipping
http://pages.infinit.net/jstlouis/3dbhole/sutherland_hodgman_clipping.html

Visit http://www.wumpus.com.au/eric/ and pick up a copy of of VOGLE. It
contains a complete Sutherland-Hodgman line and polygon clipper and the
code is public domain. I've been mining that code for years.

		Bob Pendleton

> 
> 
> //David Olofson - Programmer, Composer, Open Source Advocate
> 
> .- Audiality -----------------------------------------------.
> |  Free/Open Source audio engine for games and multimedia.  |
> | MIDI, modular synthesis, real time effects, scripting,... |
> `-----------------------------------> http://audiality.org -'
>    --- http://olofson.net --- http://www.reologica.se ---
> 
-- 
+---------------------------------------+
+ Bob Pendleton: writer and programmer. +
+ email: Bob@Pendleton.com              +
+ web:   www.GameProgrammer.com         +
+---------------------------------------+