intersection line & surface, drawing terrain
Members - Reputation: 148
Posted 08 August 2001 - 02:29 PM
Posted 09 August 2001 - 02:43 AM
Members - Reputation: 122
Posted 13 August 2001 - 09:13 AM
to find and intersection point of a ray (line) and a plane you have to do this :
lets consider a ray : X=A+t*V
where X is any point on the ray , t is a scalar and V is the direction vector of the ray.
now , lets consider a plane : X dot N + D=0
where X is any point on the plane, N is the normal to the plane and D is a scalar unique to the plane
all we have to do is find a point Xi that fits both eqations :
Xi dot N+D=0 , but Xi=A+t*V , so :
(A+t*V) dot N +D=0
A dot N + t*V dot N +D =0
t=-(D+A dot N)/(V dot N )
back to the first equation , replace t and there you go , the intersection point !!!
Members - Reputation: 148
Posted 13 August 2001 - 06:58 PM
I looked around for stuff about raytracing and most of it is about intersections of lines with geometric shapes, which gives you a mathematical solution. But looking at a height map is one which probably requires some iterative method to zoom in on the right point. Any ideas?
Moderators - Reputation: 1534
Posted 13 August 2001 - 07:25 PM
You need a tree structure which you use to perform culling, so that you don''t have to test the ray against every polygon in the world - I think you can use a quadtree or bsp tree for terrain.
I wouldn''t know how to explain the math, it''s a little involved, not too hard but lots of vectors and a few matrices, which are hard to show in ascii...
Magmai Kai Holmlor
- Not For Rent
Posted 14 August 2001 - 03:40 AM
When you ''picking'' for every pixel on the screen, you are ray tracing or at least ray casting.
You could do that, but it''ll be faster to draw all the triangles with frustrum culling and maybe LOD. Even in a pure software renderer.
It sounds to me that AndyMan is trying to find an intersection between a ray and the surface that is defined by function h(x,y).
You can do this - for some types of h(x,y)
Unfortunately, while the surface may be continuous, it''s derivative is probably not. This is because your function h(x,y) is really selecting from a whole bunch of different plane equations depending on which x and y you''ve got. I think if you want to solve this mathematically in any sane manner, you would need to generate a more complicated surface from your height map that uses one equation and not switching between several distinct equations. Some type of spline function, perhaps.
Posted 14 August 2001 - 02:21 PM
But, in pure 3d space with no restrictions, what you want to do is raytracing, pure and simple.
There is no heightmap-screen pixel equivalency that can be worked backwards from the screen pixel to the heightmap cell short of raytracing. Why? Well, for one thing, on the screen, some mountains are behind other mountains. You know that rule in math, that in a graph, if a vertical line can intersect more than 1 part of it at any location, it''s not a function? Well, you''re trying to essentially find a function that can be intersected by a vertical line. It can''t be done. Algorithmically, the only equivalency can be found through ray-tracing, and that''s rather brute-force. But, like I said, if you limit some freedom on the part of the player, you can start doing all kinds of cool things, and that''s called voxel rendering.
On a side note, I am positive that the key to efficient terrain rendering lies in the old voxel techniques - specifically wavesurfing. And if adapted, you can get more freedom.