View Full Version : Ray Intersecting with bounding box?
08-08-2003, 12:04 AM
Can anyone either give me a small example on how to do this, or give me a link to a turtorial? I have checked out nehe, gametutorials, and a few other sites and haven't found anything...
What I want to do is find get a bounding box around some objects on screen and a ray coming out of the cursor all the way into the clipping plane (or infinity) and test to see what object the mouse is on.
I have no idea where to even start with this.
I could---in theory---give you my code to do this, but you wouldn't exactly learn much about how to design algorithms. So, what I propose instead is a guided way of showing you how to figure out the answer for yourself. Everyone should know how to divide and conquer algorithms.
What I propose you do is work out some pseudo code to implement what you're after. A simple first step is
1. find the line parameters
2. find the intersection of the line  with the scene
Now, can you elaborate on that framework? Give it a go, and post your attempt. If you include assumptions about steps you think might be possible, but not sure, then that's ok too.
give it a shot
08-08-2003, 01:43 PM
okay, I now have a line being drawn from my cursor to 0,0,FarClipping Plane, except that the Y is reversed...
cm.iPosX = LOWORD(lParam);
cm.iPosY = HIWORD(lParam);
//Make assignments to fRayX and fRayY here...
//Change the window settings
sprintf(MouseString,"DarkLib Line Intersection Test - %d-%d",cm.iPosX,cm.iPosY);
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.