1
\$\begingroup\$

Alright, so before you down vote saying that OpenGL doesn't support rays for rendering, please read:

So I want to detect a quad in opengl 1.1( I don't want to use opengl 3.0). I wanted to detect it using OpenGL, but that doesn't seem possible.

But basically I have one choice, which is kind of "hacky". I create custom matrices and store the transformed vertices somewhere, then do a simple collision test.

What is the common way of doing ray-tracing in legacy OpenGL?

\$\endgroup\$
1
\$\begingroup\$

I create custom matrices and store the transformed vertices somewhere, then do a simple collision test.

Thats one way, very expensive though, since you have to transform all the vertices of all the objects in question. Doing it the other way around is much cheaper. Transform the ray with the inverse object's matrix into the local object space and make the ray test in that space. Usually transforming the ray is way easier than transforming all your vertices.

Its even cheaper, if you use Bounding Objects (Aabb Axis-Aligned-Bounding-Boxes, Obb - Oriented Bounding Boxes, Bounding Sphere etc) for a first Hit Test. If that succeeds, do the actual Object Hit Test.

\$\endgroup\$
0
\$\begingroup\$

Picking in OpenGL can be done, by rendering the primitives you want to check for, assigning each one a unique color, based upon which you can look it up.

Then you can check what color is rendered for example on the center of the screen, this way getting the object pointed at.

This was done in older games, but is frowned upon, because it can be a huge performance hog.


Picking in an OpenGL based app, is usually done using external libraries to do the ray-casting. Usually a game has a Physics engine, which must be able to do a ray-cast, so most of the time the actual physics engine is used to do ray-casting.

One of such libraries is bullet.

Now if I understand you correctly, what you propose is simply the method used by a physics engine, it uses matrices to translate the object into world-space, then doing a ray-cast in world-space.

\$\endgroup\$
  • \$\begingroup\$ Well i use LWJGL - Java. I was thinking of making an infinitely long line checking for intersections, i did consider using a physics library, but i dont really emulate any physics, i even went as far as creating my own graphics library today, but it just gave me more knowledge. Thanks for the answer ! C: \$\endgroup\$ – EEVV Aug 17 '15 at 15:18
  • \$\begingroup\$ @EEVV Physics and ray-casting is something you really don't want to reinvent or recreate, especially if you asked this question. Otherwise great learning experience. \$\endgroup\$ – akaltar Aug 17 '15 at 15:22
  • \$\begingroup\$ Woops something is wrong with my stack exchange. \$\endgroup\$ – EEVV Aug 17 '15 at 15:24
  • 1
    \$\begingroup\$ @EEVV Doing Ray-casts in 3D is much much much more complicated as far as I know. look it up. \$\endgroup\$ – akaltar Aug 17 '15 at 21:29
  • 1
    \$\begingroup\$ @EEVV If you found this answer useful then please vote it up, and if it answered your question, please accept it. \$\endgroup\$ – akaltar Aug 20 '15 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.