GitHub项目地址OpenGL(glut)模拟太阳系:太阳,地球,月球,火星
核心代码如下:
// orgin.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include "pch.h"
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
using namespace std;
bool bPersp = false;
int year = 0, day = 0, marsYear = 0;
int speed = 12;
float light_angle = 0;
bool bWire = false;
float light_radius = 8.0;
float eye[] = {
5.5, 1.7, 1.7};
float center[] = {
0, 0, 0 };
int wHeight = 0;
int wWidth = 0;
int state = 1;
float star[1000][3];
GLUquadricObj *g_text;
void lPosition()
{
float y, z;
y = light_radius * cos(light_angle);
z = light_radius * sin(light_angle);
float light_position[] = {
3.0, y, z, 0.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
}
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
lPosition();
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
g_text = gluNewQuadric();
}
void init_stars()
{
for (int i = 0; i < 1000; i++)
for (int j = 0; j < 3; j++)
star[i][j] = rand()