Jump to content
  • Advertisement
Sign in to follow this  
Node

Static 2D region on top of 3D scene

This topic is 4252 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am trying to place a semi-transparent 2d region on top of my 3D scene which will contain text giving some information, however I am having trouble finding a way to have this 2D area such that it does not rotate and move as the rest of the scene does. Anybody know how I can go about achieving this? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
While I am only familiar with Direct3D syntax, what you're probably looking for is an orthographic projection. You'll want to render your 3D scene normally, using the standard perspective projection. When you're done with that, you switch to an orthographic projection, with an appropriate view matrix, and then render all your 2D stuff. (Either clearing the z-buffer before doing this, or rendering 2D stuff without a depth test is probably a good idea.) Then the frame is done. Next frame you do the same thing: setup the perspective projection for your camera, render 3D, setup the orthographic projection, render 2D.

Your look-at vector for the orthographic projection will probably be directly parallel to the z-axis, and the up-vector will probably be parallel with the y-axis. Within those two constraints, you should be able to set things up for a variety of conditions. Perhaps you want the (x,y) coordinates to match up exactly with pixel values. Perhaps you want (0,0) to correspond to the top-left, and (1,1) to the bottom-right. Perhaps you want (0,0) to be the center of the screen. Perhaps you want to render your 2D stuff as though you're always in 1024x768 mode, regardless of what the resolution actually is. You can do all that by merely translating and scaling the view, while maintaining those two parallel constraints above.

Share this post


Link to post
Share on other sites
Like Agony said, an orthographic projection matrix is your way to go. This enables you to define the orientation of your y and x-axes as wll as the "resolution" of your screen. (With "resoultion" I mean the number of units your screen is wide and high, i.e. if you want say the width is 100 then translating a point (0,0) by x = 50 it will end up on the vertical line crossing the center of the screen.)

Then after your 3D scene is drawn, make sure you only have the view matrix as your MODELVIEW (no model transformation) and switched PROJECTION to the orthographic matrix. Then you can translate/rotate/scale everthing on screen, without z having any effect except affecting depth test.

From your post, however, I see that there are some problems with having the 2D overlay staying in the same place relative to the camera. As I said above you have to take care that only the view transformation is present as your modelview matrix.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!