图形:如何围绕太阳旋转地球 [英] Graphics: how to revolve earth around sun
本文介绍了图形:如何围绕太阳旋转地球的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
建议如何围绕太阳旋转地球?我试图使用openGL用c语言围绕太阳旋转地球。
Suggest, how to revolve earth around sun? I am trying to revolve earth around the sun in c language using openGL.
#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();
}
推荐答案
你可能知道地球围绕太阳转圈。因此,你必须将GL-earth移动到类似的物体中并与地球自转重叠。
我发现这很好示例代码或此片段可以帮助您理解它。
提示:OpenGL非常便携,所以你应该找到有趣的部分
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
这篇关于图形:如何围绕太阳旋转地球的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文