Archived

This topic is now archived and is closed to further replies.

CProgrammer

simple raytracing

Recommended Posts

CProgrammer    303
I want to make simple shadow casting. Basically I need a function, that checks if the line from a given point to a given tile intersects the terrain. So something like bool intersects(float x, float y, int xtile, int ytile); Is there a standard algorithm for this? Possibly some line algorithm that checks for each tile if the height exeeds? -CProgrammer

Share this post


Link to post
Share on other sites
Basiror    241
there s a equation for line plane intersection

get the intersection with a plane

and then check whether the x,y coordinates are between the min and max x,y of your terrain tile otherwise move to the next tile and do it all over again until you find the right tile


P.S.: this works only for heightmap like terrains
for other geometry you need to do a line-plane test as descriped above and check if the point is inside the polygon


to check if it is inside the polygon you can project the polygon into a 2d plane by finding the biggest coordinate of the polygon normal and use the plane of the 2 smallest components of the normal


now get the planes of the 2d projection and check if the 2d projection of the intersection point is inside the polygon


a) why project it into 2d?
because of polygons with lots of vertices you have to do a lot of operations in 3d so 2d is usually faster

b) why can t i simply project it into the x,y plane?

well because the polygon might stand perpendicular to the surface and you get a precision decrease so always project into the plane of the smallest components of the polygon normal

Share this post


Link to post
Share on other sites