Jump to content
  • Advertisement


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


simple raytracing

This topic is 5411 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!