openGPMP
Open Source Mathematics Package
Macros | Functions | Variables
openGL_astronomy_animated.c File Reference
#include <GL/glut.h>
#include <math.h>
#include <stdio.h>

Go to the source code of this file.

Macros

#define pi   3.142857
 

Functions

void myWireSphere (GLfloat radius, int slices, int stacks)
 
void display ()
 
void timer (int v)
 
void reshape (GLint w, GLint h)
 
int main (int argc, char **argv)
 

Variables

static bool spinning = true
 
static const int FPS = 20
 
static GLfloat current_rot = 0.0
 
static int year = 0
 
static int day = 0
 
static GLfloat u = 0.0
 
static GLfloat du = 0.1
 

Macro Definition Documentation

◆ pi

#define pi   3.142857

Definition at line 8 of file openGL_astronomy_animated.c.

Function Documentation

◆ display()

void display ( void  )

Definition at line 40 of file openGL_astronomy_animated.c.

40  {
41  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
42  glPushMatrix();
43 
44  // Draw sun: a yellow sphere of radius 1 centered at the origin.
45  glColor3f(1.0, 1.0, 0.0);
46  myWireSphere(1.0, 15, 15);
47 
48  // Draw planet: a blue sphere of radius 0.2, 2 units away from
49  // sun, with a white "pole" for its axis.
50  glRotatef((GLfloat)year, 0.0, 1.0, 0.0);
51  glTranslatef(2.0, 0.0, 0.0);
52  glRotatef((GLfloat)day, 0.0, 1.0, 0.0);
53  glColor3f(0.0, 0.0, 1.0);
54  myWireSphere(0.2, 15, 15);
55  glColor3f(1, 1, 1);
56  glBegin(GL_LINES);
57  glVertex3f(0, -0.3, 0);
58  glVertex3f(0, 0.3, 0);
59  glEnd();
60 
61  glPopMatrix();
62  glFlush();
63  glutSwapBuffers();
64 }
static int day
static int year
void myWireSphere(GLfloat radius, int slices, int stacks)

References day, myWireSphere(), and year.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 112 of file openGL_astronomy_animated.c.

112  {
113  glutInit(&argc, argv);
114  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
115  glutInitWindowSize(800, 600);
116  glutCreateWindow("Comet, Planet Simulation");
117  glutDisplayFunc(display);
118  glutReshapeFunc(reshape);
119  glutTimerFunc(100, timer, 0);
120  glEnable(GL_DEPTH_TEST);
121  glutMainLoop();
122 }
void display()
void reshape(GLint w, GLint h)
void timer(int v)

References display(), reshape(), and timer().

◆ myWireSphere()

void myWireSphere ( GLfloat  radius,
int  slices,
int  stacks 
)

Definition at line 20 of file openGL_astronomy_animated.c.

20  {
21  glPushMatrix();
22  glRotatef(-90.0, 1.0, 0.0, 0.0);
23  glutWireSphere(radius, slices, stacks);
24  glPopMatrix();
25 }

Referenced by display().

◆ reshape()

void reshape ( GLint  w,
GLint  h 
)

Definition at line 103 of file openGL_astronomy_animated.c.

103  {
104  glViewport(0, 0, w, h);
105  glMatrixMode(GL_PROJECTION);
106  glLoadIdentity();
107  gluPerspective(60.0, (GLfloat)w / (GLfloat)h, 1.0, 40.0);
108  glMatrixMode(GL_MODELVIEW);
109 }

Referenced by main().

◆ timer()

void timer ( int  v)

Definition at line 75 of file openGL_astronomy_animated.c.

75  {
76  u += du;
77  day = (day + 1) % 360;
78  year = (year + 2) % 360;
79  glLoadIdentity();
80  gluLookAt(20 * cos(u / 8.0) + 12,
81  5 * sin(u / 8.0) + 1,
82  10 * cos(u / 8.0) + 2,
83  0,
84  0,
85  0,
86  0,
87  1,
88  0);
89  glutPostRedisplay();
90  glutTimerFunc(1000 / 60, timer, v);
91 }
static GLfloat du
static GLfloat u

References day, du, u, and year.

Referenced by main().

Variable Documentation

◆ current_rot

GLfloat current_rot = 0.0
static

Definition at line 14 of file openGL_astronomy_animated.c.

◆ day

int day = 0
static

Definition at line 32 of file openGL_astronomy_animated.c.

Referenced by display(), and timer().

◆ du

GLfloat du = 0.1
static

Definition at line 73 of file openGL_astronomy_animated.c.

Referenced by timer().

◆ FPS

const int FPS = 20
static

Definition at line 11 of file openGL_astronomy_animated.c.

◆ spinning

bool spinning = true
static

Definition at line 10 of file openGL_astronomy_animated.c.

◆ u

GLfloat u = 0.0
static

◆ year

int year = 0
static

Definition at line 32 of file openGL_astronomy_animated.c.

Referenced by gpmp::core::DataTable::datetime(), display(), and timer().