coloring face

Hi, I believe I had asked something similar before, but did not really get the answer,
so decided to repharse my question and post again… so sorry about that.

Heres the problem.
I load a ball object from an object file.
For the display() method, I use an animator to call it, meaning that it will be called repeatedly.
For this ball object, I can do transformation like,rotation,translation and scaling to it.

Now, I would like to apply some changes to it. when a user selects a face, I want to shade it to the color say blue.
How do I do the shading part?

Thanks for the help…

Use vertex colors. After calculating which triangle the user clicked on, modify the vertex colors so that only the color for that face are blue and all other vertices use the other color. This part isn’t the hard part, the tricky part is figuring out what triangle someone clicked on:

  1. Get mouse coordinates
  2. Convert mouse coordinates into 3D coordinates on the near camera plane
  3. Create a ray starting at the camera’s position and going through the point from #2
  4. Check every object drawn in your scene for intersection:
    4a. For each shape, check if the ray intersects any of it’s triangle’s planes and that the points of intersection are within the bounds of the triangle.
  5. Choose the intersection that is closest to the camera
  6. Now go color the faces correctly