I am creating a 3d asteroid game where you navigate a spaceship through some asteroids.When i click the asteroid i destroy it, and i want before the asteroid is being destroyed to add a hud like you see in sci-fi movies with target locked and stuff like that.So select asteroid, animate the hud, destroy asteroid.What is the best approach in achieving this ? Should i simply create some planes and render them visible only when i need to, or is there another approach like when you create text and you set up a new projection to render the text over the main window.
1 Answers
Woah, woah, you're tackling several problems at once here.
First you must determine the on-screen position (and maybe the bounds) of the asteroid. You do this by mimicking the vertex transformation pipeline on the barycenter position of the asteroid. The usual way is
p_clip = Projection · (Modelview · p)
p_ndc = p_ndc / p_ndc.w
Drawing the HUD overlay requires to get a newbe-misconception out of the way. If you followed one of the usual, bad tutorials, then you'll find the projection matrix setup in the window reshape function. That's not where it belongs.
If you put the whole viewport and projection setup into the drawing function, things become obvious. You can set and reset the viewport and projection as often as required. So first draw the scene using your usual projection and viewport settings. Then you clear the depth buffer and switch to a projection suitable for rendering the overlay.