Click here to Skip to main content
15,881,695 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Suggest, how to revolve earth around sun? I am trying to revolve earth around the sun in c language using openGL.

C++
#include 
 void init(void){
     glClearColor(0.0,0.0,0.0,0.0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 }
 void display(void){
     glClearColor(0.05,0.05,0.5,0.0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glColor3f(0.03,0.05,0.09);
     glutSolidSphere(0.5,30,30);//Earth
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
     glTranslatef(.7,.7,.7);
     glColor3f(1.0,1.0,1.0);
     glutSolidSphere(0.2,50,50);//Sun
     glLoadIdentity();
     glFlush();

 }
int main(int argc, char **argv){
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE);
    glutInitWindowPosition(10,10);
    glutInitWindowSize(400,400);
    init();
    glutCreateWindow("Planets");
    glutDisplayFunc(display);
    
    glFlush();
    glutMainLoop();
}
Posted
Updated 25-Feb-16 5:48am
v3
Comments
dan!sh 25-Feb-16 5:39am    
That's a funny subject line. LOL
OriginalGriff 25-Feb-16 6:21am    
Especially as we all know the Sun goes round the flat Earth! :laugh:

1 solution

As you may know the earth moves around the sun in circle. So you must move your GL-earth in a similar matter and overlap with some earth rotation.

I found this nice example code or this snippets which may help you to understand it.

Hint: the OpenGL is highly portable, so you should find the interesting parts
 
Share this answer
 
Comments
Kenneth Haugland 25-Feb-16 11:45am    
Actually, it's not a circle (however it's not very far from it), it's an ellipse.
https://en.wikipedia.org/wiki/Earth%27s_orbit

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900