Skip to main content
1 of 3
zacharmarz
  • 3.9k
  • 2
  • 18
  • 17

I know two ways how to do this:

  1. Use frame buffer, where you render all objects, each with different color (no lighing, no texturing, ...). Then render normal scene.

When you click with your mouse, you read 2D coordinates, look in frame buffer and find color of pixel, where you have clicked. Then you will find object according to this color.

This method is called pixel picking.

  1. Render your scene, read clicked coordinates. Now you have to transfer 2D point back to 3D - create ray from camera to clicked point. Then do ray tracing and find first object in path (ray object collision).
zacharmarz
  • 3.9k
  • 2
  • 18
  • 17