Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  

Ray / Polygon Collision from DigiBen

This topic is 2833 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 have a DidgiBen programming Lessons source of simple line -> polygon collision code:


The source contains lines like this:

  1. // This is our line that we will be checking against the polygon's plane for collision.

  2. // We position the line going directly through the polygon at first.

  3. CVector3 vLine[2] = { {0, 0.5f, -0.5f}, {0, 0.5f, 0.5f} };

vLine is used like ray, to shoot through polygon / triangle / quad.
It works fine.

Now, my question is: is it possible and how to make this code to use ray from gluUnproject?
Instead of hardcoded vLine?

Will this be very hard? What modifications i must make?

Share this post

Link to post
Share on other sites
you have to call glGetDouble to grab the current projection matrix, gluUnproject asks for a few other things. Take a point such as mousex, mousey, far plane (the parameter for far in gluPerspective), and that gives you the 3D point really far away from your 3D camera. Subtract that point, from your camera position and you have a 3d ray.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!