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

Go to the source code of this file.

Classes

class  Camera
 
class  Ball
 
class  Checkerboard
 

Macros

#define pi   3.142857
 

Functions

Checkerboard checkerboard (8, 8)
 
void init ()
 
void display ()
 
void reshape (GLint w, GLint h)
 
void timer (int v)
 
void special (int key, int, int)
 
int main (int argc, char **argv)
 

Variables

GLfloat WHITE [] = {1, 1, 1}
 
GLfloat RED [] = {1, 0, 0}
 
GLfloat GREEN [] = {0, 1, 0}
 
GLfloat MAGENTA [] = {1, 0, 1}
 
Camera camera
 
Ball balls []
 

Macro Definition Documentation

◆ pi

#define pi   3.142857

Definition at line 9 of file openGL_bounce.c.

Function Documentation

◆ checkerboard()

Checkerboard checkerboard ( ,
 
)

Referenced by display(), and init().

◆ display()

void display ( void  )

Definition at line 171 of file openGL_bounce.c.

171  {
172  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
173  glLoadIdentity();
174  gluLookAt(camera.getX(),
175  camera.getY(),
176  camera.getZ(),
178  0.0,
180  0.0,
181  1.0,
182  0.0);
183  checkerboard.draw();
184  for (int i = 0; i < sizeof balls / sizeof(Ball); i++) {
185  balls[i].update();
186  }
187  glFlush();
188  glutSwapBuffers();
189 }
void update()
Definition: openGL_bounce.c:78
double getY()
Definition: openGL_bounce.c:33
double getX()
Definition: openGL_bounce.c:29
double getZ()
Definition: openGL_bounce.c:37
double centerz()
double centerx()
Camera camera
Ball balls[]
Checkerboard checkerboard(8, 8)

References balls, camera, Checkerboard::centerx(), Checkerboard::centerz(), checkerboard(), Checkerboard::draw(), Camera::getX(), Camera::getY(), Camera::getZ(), and Ball::update().

Referenced by main().

◆ init()

void init ( )

Definition at line 158 of file openGL_bounce.c.

158  {
159  glEnable(GL_DEPTH_TEST);
160  glLightfv(GL_LIGHT0, GL_DIFFUSE, WHITE);
161  glLightfv(GL_LIGHT0, GL_SPECULAR, WHITE);
162  glMaterialfv(GL_FRONT, GL_SPECULAR, WHITE);
163  glMaterialf(GL_FRONT, GL_SHININESS, 30);
164  glEnable(GL_LIGHTING);
165  glEnable(GL_LIGHT0);
167 }
GLfloat WHITE[]
Definition: openGL_bounce.c:12

References checkerboard(), Checkerboard::create(), and WHITE.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 227 of file openGL_bounce.c.

227  {
228  glutInit(&argc, argv);
229  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
230  glutInitWindowPosition(80, 80);
231  glutInitWindowSize(800, 600);
232  glutCreateWindow("Bouncing Balls");
233  glutDisplayFunc(display);
234  glutReshapeFunc(reshape);
235  glutSpecialFunc(special);
236  glutTimerFunc(100, timer, 0);
237  init();
238  glutMainLoop();
239 }
void init()
void display()
void reshape(GLint w, GLint h)
void special(int key, int, int)
void timer(int v)

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

◆ reshape()

void reshape ( GLint  w,
GLint  h 
)

Definition at line 192 of file openGL_bounce.c.

192  {
193  glViewport(0, 0, w, h);
194  glMatrixMode(GL_PROJECTION);
195  glLoadIdentity();
196  gluPerspective(40.0, GLfloat(w) / GLfloat(h), 1.0, 150.0);
197  glMatrixMode(GL_MODELVIEW);
198 }

Referenced by main().

◆ special()

void special ( int  key,
int  ,
int   
)

Definition at line 208 of file openGL_bounce.c.

208  {
209  switch (key) {
210  case GLUT_KEY_LEFT:
211  camera.moveLeft();
212  break;
213  case GLUT_KEY_RIGHT:
214  camera.moveRight();
215  break;
216  case GLUT_KEY_UP:
217  camera.moveUp();
218  break;
219  case GLUT_KEY_DOWN:
220  camera.moveDown();
221  break;
222  }
223  glutPostRedisplay();
224 }
void moveUp()
Definition: openGL_bounce.c:49
void moveDown()
Definition: openGL_bounce.c:53
void moveLeft()
Definition: openGL_bounce.c:45
void moveRight()
Definition: openGL_bounce.c:41

References camera, Camera::moveDown(), Camera::moveLeft(), Camera::moveRight(), and Camera::moveUp().

Referenced by main().

◆ timer()

void timer ( int  v)

Definition at line 201 of file openGL_bounce.c.

201  {
202  glutPostRedisplay();
203  glutTimerFunc(1000 / 60, timer, v);
204 }

Referenced by main().

Variable Documentation

◆ balls

Ball balls[]
Initial value:
= {Ball(1, GREEN, 7, 6, 1),
Ball(1.5, MAGENTA, 6, 3, 4),
Ball(0.4, WHITE, 5, 1, 7)}
GLfloat MAGENTA[]
Definition: openGL_bounce.c:15
GLfloat GREEN[]
Definition: openGL_bounce.c:14

Definition at line 152 of file openGL_bounce.c.

Referenced by display().

◆ camera

Camera camera

Definition at line 151 of file openGL_bounce.c.

Referenced by display(), and special().

◆ GREEN

GLfloat GREEN[] = {0, 1, 0}

Definition at line 14 of file openGL_bounce.c.

◆ MAGENTA

GLfloat MAGENTA[] = {1, 0, 1}

Definition at line 15 of file openGL_bounce.c.

◆ RED

GLfloat RED[] = {1, 0, 0}

Definition at line 13 of file openGL_bounce.c.

Referenced by Checkerboard::create().

◆ WHITE

GLfloat WHITE[] = {1, 1, 1}

Definition at line 12 of file openGL_bounce.c.

Referenced by Checkerboard::create(), and init().