源代码下载:https://download.csdn.net/download/u012737193/10307716
点击上下左右调整观看视角
源代码下载:https://download.csdn.net/download/u012737193/10307716
Main.cpp文件:
#include <GL/glut.h>//只要包含了这个头文件,
可以通过以下三个文件,设置点击键盘事件,屏幕刷新事件和静止的时候执行的函数
glutDisplayFunc(onDisplay);
glutIdleFunc(onUpdate);
glutKeyboardFunc(onKeyboard);
#include <GL/glut.h>
#include "solarsystem.hpp"
#define WINDOW_X_POS 50
#define WINDOW_Y_POS 50
#define WIDTH 700
#define HEIGHT 700
SolarSystem solarsystem;
void onDisplay(void) {
solarsystem.onDisplay();
}
void onUpdate(void) {
solarsystem.onUpdate();
}
void onKeyboard(unsignedchar key,int x, int y) {
solarsystem.onKeyboard(key, x, y);
}
int main(int argc,char * argv[]){
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA| GLUT_DOUBLE);
glutInitWindowPosition(WINDOW_X_POS,WINDOW_Y_POS);
glutCreateWindow("SolarSytem at Shityanlou");
glutDisplayFunc(onDisplay);
glutIdleFunc(onUpdate);
glutKeyboardFunc(onKeyboard);
glutMainLoop();
return 0;
}
来源: 实验楼
链接: https://www.shiyanlou.com/courses/558
Stars.hpp文件:
#ifndef star_hpp//这个头文件的功能就是当star_hpp存在的时候不执行#ifndef#endif之间的内容
#define star_hpp
#include <GL/glut.h>
class Star {
public :
GLfloat radius;
GLfloat speed,selfSpeed;
GLfloat distance;
GLfloat rgbaColor[4];
Star * parentStar;
Star(GLfloat radius,GLfloatdistance,GLfloatspeed,GLfloatselfSpeed,Star*parent);
void drawStar();
virtual void draw() {drawStar();}
virtual void update(longtimeSpan);
protected:
GLfloat alphaSelf,alpha;
};