 |
|
| Computers Forum Index » Computer - Games Programming (Algorithms) » halfline to heightmap intersection...... |
|
Page 1 of 1 |
|
| Author |
Message |
| Miss Elaine Eos... |
Posted: Thu Oct 16, 2008 3:27 am |
|
|
|
Guest
|
In article <48f62159$0$31384$426a34cc at (no spam) news.free.fr>,
cathy <comptedenews at (no spam) free.fr> wrote:
Quote: Bresenham's algorithm would be a good way to quickly generate each
square. My DADS entry has links to implementations and explanations
that might help.
http://www.nist.gov/dads/HTML/bresenham.html
The problem is that Bresenham's algorithm is NOT a good way as far as it
would not generate all the squares crossed. If you have a look at the
picture there:
http://en.wikipedia.org/wiki/Image:Bresenham.svg
you see that there are some squares where the line pass, but they are
not grayed. And as this is for collision detection purpose, I can not
miss any square!
Thanks anyway.
Are you using Open-GL? It has built-ins for this. gluUnProject()
sounds like exactly what you're doing, here.
--
Please take off your pants or I won't read your e-mail.
I will not, no matter how "good" the deal, patronise any business which sends
unsolicited commercial e-mail or that advertises in discussion newsgroups. |
|
|
| Back to top |
|
|
|
| cathy... |
Posted: Thu Oct 16, 2008 7:10 pm |
|
|
|
Guest
|
Quote: Are you using Open-GL? It has built-ins for this. gluUnProject()
sounds like exactly what you're doing, here.
Hi
I am using OpenGL, but I believe using gluUnproject means solving
equations and I would have liked something more efficient. Anyway if
that is the only solution, could you help me giving me some hints with
this way to solve it?
Thanks
Cathy |
|
|
| Back to top |
|
|
|
| Tom Plunket... |
Posted: Sun Oct 19, 2008 6:16 am |
|
|
|
Guest
|
cathy wrote:
Quote: I have a 2D grid of n*n squares of the same size s. The first one starts
at (x0,y0). So the square nx,ny spans from (x0+nx*s,y0+ny*s) to
(x0+(nx+1)*s,y0+(ny+1)*s).
Then I have a half-line whose equation is ax+by+c=0 starting at (x1,y1).
What would be a quick way to know the squares crossed from (x1,y1)
further?
When I did this in the past, I just inverted the matrix that I was using
to draw the grid and multiplied it into the mouse position. This gave
me the square index in floating point, where the whole portion was the
square being clicked on and the fraction was how far across the square I
was clicking.
Granted, this was for a flat plane, but it worked well for any
projection matrix. If you're trying to click on squares that have been
manipulated in a heightfield, you might need to do something trickier.
bonne chance,
-tom!
-- |
|
|
| Back to top |
|
|
|
| cathy... |
Posted: Sun Oct 19, 2008 11:59 am |
|
|
|
Guest
|
Tom Plunket a écrit :
Quote: When I did this in the past, I just inverted the matrix that I was using
to draw the grid and multiplied it into the mouse position. This gave
me the square index in floating point, where the whole portion was the
square being clicked on and the fraction was how far across the square I
was clicking.
Hum sorry I do not understand that. What is this "matrix used to draw
the grid" you are talking about?
Quote: Granted, this was for a flat plane, but it worked well for any
projection matrix. If you're trying to click on squares that have been
manipulated in a heightfield, you might need to do something trickier.
This is in 3D space, but for a flat plane, the horizontal one: I just
want to know what are the squares "overflown" by the ray (and if
possible from near to far) so that I will perform a "ray to square
collision detection" with my heightmap only on those squares and stop as
soon as I have found the first one hit (if any).
I have found a solution that may work well using a modified version of
the algorithm of Bresenham that draw ALL the pixels (=my squares)
"overflown" by a line (Bresenham's original one does not draw all of
them). The algorithm is explained there:
http://lifc.univ-fcomte.fr/~dedu/projects/bresenham/index.html
As it is based on the algorithm of Bresenham it is efficient and it can
be used from near to far and stop whenever I want.
What do you think of this?
Thanks
Cathy |
|
|
| Back to top |
|
|
|
|
|
All times are GMT
The time now is Wed Dec 09, 2009 5:52 pm
|
|