#include <math.h>
#include <gl/glut.h>
float day=0;//地球自转角度
float month=0;//月球自转角度
float year=0;//地球公转角度
float sun=0;//太阳自转角度
void Keyboard(unsigned char key,int x,int y)
{
if(key==27)
exit(0);//按下ESC退出
}
//定时器回调函数
void Timer(int millis)
{
float dday=6,speed=4;
float dmonth=speed*dday/29.5;//月亮自转和公转角度增量,fmod函数取余数
float dyear=speed*dday/365.2475;//地球公转角度增量
float dsun=speed*dday/27.5;//太阳自转角度增量
day=fmod(day+dday,360);//计算地球自转角度
month=fmod(month+dmonth,360);//计算月球公转,自转角度
year=fmod(year+dyear,360);//计算地球公转角度
sun=fmod(sun+dsun,360);//计算太阳公转角度
glutPostRedisplay();
glutTimerFunc(millis,Timer,millis);
}
//窗口回调函数
void Reshape(int w,int h)
{
glViewport(0,0,w,h);
本内容试读结束,登录后可阅读更多
下载后可阅读完整内容,剩余4页未读,立即下载