Jump to content
  • Advertisement
Sign in to follow this  
tim-the-inventor

OpenGL small drawing problem

This topic is 4059 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 new opengl coder looking for some help. Basically ive drawn a rotatable box (gonna be a tank some day :p) and a circle around it to show its sort of collision detection. When I move it from the centre of the screen the circle becomes offset from the box as in the following screenies: piccy1 piccy2 piccy3 code:
                Gl.glPushMatrix();

                Gl.glTranslatef(x, y, -1.01f);
                Gl.glScalef(0.02f, 0.02f, 0.02f);
                Gl.glRotatef(facing, 0, 0, 1);

                Gl.glBegin(Gl.GL_QUADS);
                Gl.glColor3f(1, 1, 1);
                Gl.glVertex3f(-1.0f, 1.0f, 0.0f);
                Gl.glVertex3f(1.0f, 1.0f, 0.0f);
                Gl.glVertex3f(1.0f, -1.0f, 0.0f);
                Gl.glVertex3f(-1.0f, -1.0f, 0.0f);
                Gl.glEnd();

                Gl.glPopMatrix();
                
                Gl.glPushMatrix();
                
                Gl.glTranslatef(x, y, -1.0f);
                Gl.glScalef(0.02f, 0.02f, 0.02f);
               
                float vectorX; float vectorY;
                
                Gl.glBegin(Gl.GL_LINES);
                Gl.glColor3f(1, 1, 1);
                for (float angle = 0.0f; angle <= (2.0f * Math.PI); angle += 0.01f)
                {
                    vectorX = (radius * (float)Math.Sin((double)angle));
                    vectorY = (radius * (float)Math.Cos((double)angle));
                    Gl.glVertex3f(vectorX, vectorY, 0.0f);
                    
                }
                Gl.glEnd();

               
                Gl.glPopMatrix();



I really cant see the cause. Seems like one object is behind the other? Any help is most welcome. :) [Edited by - tim-the-inventor on June 8, 2007 4:34:53 PM]

Share this post


Link to post
Share on other sites
Advertisement
I think that the problem may be that you seem to be generating your circle vertices around an offset origin when you have already had OpenGL offset the geometry. Perhaps try removing the "origin(X/Y) + " from your vectorX and -Y calculations.

Share this post


Link to post
Share on other sites
My pleasure - I'm glad that I helped. ^_^

As to your remaining offset, it occurs to me to ask: are you using a perspective or an orthographic projection? If the former, it could simply be that perspective projection is causing an apparent offset as a result of one element being placed slightly closer to the camera than the other (Gl.glTranslatef(x, y, -1.01f) as opposed to Gl.glTranslatef(x, y, -1.0f) (emphasis mine)).

If you are using a perspective projection, perhaps try placing both at the same distance from the camera.

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!