Jump to content
  • Advertisement
Sign in to follow this  

2D sprites in 3D world...

This topic is 4284 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

Hi guys. I'm having a slight problem. I want to create a sprite in my 3d environment that would always face the camera. I want to use this sprite for things like smoke and fire. What I do is I draw a quad thats on the y-z plane, then rotate it to face teh camera position using polar coordinates. But for some reason it never works.. all the angles seem to be messed up. Here's the code:

     float dx = camera->_xCam - _x;
     float dy = camera->_yCam - _y;
     float dz = camera->_zCam - _z;               
     float r = sqrt(dx*dx + dy*dy + dz*dz );     

//Calculate the rotation around the y and z axis
     _yrot = 90-acos(dz/r)*180/PI;
     _zrot = atan2(dy, dx)*180/PI;

        glRotatef(_xrot, 1.0,0.0,0.0);         
        glRotatef(_yrot, 0.0,1.0,0.0);        
        glRotatef(_zrot, 0.0, 0.0,1.0);             
        glScalef( _xscale, _yscale, _zscale);                        
        if( hasTexture ){
        } else {

            glTexCoord2f( 0.0,0.0);

            glTexCoord2f( 0.0,1.0);            

            glTexCoord2f( 1.0,1.0);                        

            glTexCoord2f( 1.0,0.0);                        

If anyone knows whats wrong or has a better way to draw these sprites. Please let me know. Thank you. Gavin

Share this post

Link to post
Share on other sites
I didn't look further than this line, but here:
You're mixing radians and degrees, which renders the results meaningless. So I'd fix that first and see if it improves things at all (it may not, since there may be other errors as well).

Share this post

Link to post
Share on other sites
I just spent a good 5 minutes running through the Open GL forum looking for a previous reply I made not too long ago, only to realise that it was in the Graphics Programming and Theory section...

Anyway, here's the stuff you're looking for.

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!