Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Scaling rotation and translation order of operations problem.

This topic is 3814 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 make solar system simulator in opengl and in my function drawplanets() that just draws all the planets in their correct position based on where they are in their orbit. Each planet is a struct with many attributes such as its starting x and z, its size its period of orbit and rotation, and its size. My problem is that the planets that are bigger show up closer then the planets that are smaller relative to where they should be based on their starting x/z (I.E earth is closer to the sun then mars but it is also bigger, in my simulation mars appears closer then the Earth and if I adjust the size of mars to be equal or bigger then the size of the Earth it appears in the right spot relative to the Earth). I believe this is caused by the order I am doing my rotation/translation and scaling but when I try and move the scaling to the end everything just ends up in the sun. I posted the function below its kind of sloppy atm. Thanks for your help. static void draw_planets() { double size; int k; double xrot,zrot; for(k=0;k<n;k++) { glPushMatrix(); //glRotated(-90,1,0,0); size = planet[k].size; glColor3f(1,1,1); glEnable(GL_TEXTURE_2D); glScaled(size,size,size); if((k!=0)&&(k!=4)) //Draw all planets except sun and moon in the arch of their orbit. { xrot = Cos(planet[k].orbTheta) * planet[k].x; zrot = Sin(planet[k].orbTheta) * planet[k].x; glTranslated(xrot,0,zrot); } else { glTranslated(planet[k].x,0,planet[k].z); //Draw sun and moon in set locations. } // Surface texture glBindTexture(GL_TEXTURE_2D,planet[k].balltex); // Rotation around spin axis // glRotated(-90,1,0,0); glRotated(planet[k].theta,0,1,0); // glScaled(size,size,size);// Solid gluQuadricDrawstyle(Pball,GLU_FILL); // Calculate normals gluQuadricNormals(Pball,GLU_SMOOTH); // Apply Textures gluQuadricTexture(Pball,1); // Draw the ball gluSphere(Pball,1.0,36,36); /* * Draw rings for planets that have them * We naively assume the ring width equals the radius */ if (planet[k].ring) { int i; // Make rings transparent grey glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_COLOR); glColor3f(1.0,1.0,1.0); // Set ring texture glBindTexture(GL_TEXTURE_2D,planet[k].ringtex); // Draw ring plane glBegin(GL_QUAD_STRIP); for (i=0;i<=360;i+=2) { glTexCoord2f(1,0);glVertex2d(1.0*Cos(i),1.0*Sin(i)); glTexCoord2f(0,0);glVertex2d(2.2*Cos(i),2.2*Sin(i)); } glEnd(); glDisable(GL_BLEND); } glPopMatrix(); } } [Edited by - Ender2012 on July 3, 2008 4:10:45 PM]

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!