1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <Windows.h>
#include <cmath>
#include "ball_funcs.h"
#include <string>
#include <glut.h>
#include <GL\GLU.h>
using namespace std;
void checkColision(int ID){}
void wall_collision(float R, float G, float B, int wall){}
void eraseAllBalls(){}
void drawBalls(int i) {
glTranslated(posX[i], posY[i], posZ[i]);
glColor3d(myR[i], myG[i], myB[i]);
glutSolidCube(ballSize[i]);
}
void Reshape (int height, int width) {
glViewport(0, 0, width, height);
glClearColor(0, 0, 0, 1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (float)height/(float)width, 1, 100);
glMatrixMode(GL_MODELVIEW);
}
void Display(void) {
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
for (int i = 0;i < 10; i++) {
if (filled[i] == true) {
drawBalls(i);
}
}
glPopMatrix();
system("cls");
for (int i = 0; i < 10; i++) {
cout << i << ". X: " << posX[i]
<< "; Y: " << posY[i]
<< "; Z: " << posZ[i]
<< "; Size: " << ballSize[i]
<< "; R: " << myR[i]
<< "; G: " << myG[i]
<< "; B: " << myB[i] << endl;
}
glPushMatrix();
glTranslated(0+boxX, 0+boxY, -10+boxZ);
glColor3d(0, 1, 0);
glutWireCube(boundaries);
glPopMatrix();
glutSwapBuffers();
}
void Keyboard(unsigned char key, int x, int y) {
switch(key){
case'r': //r for random
if (keypressed == false) {
importInfo_Random(currBallImport);
filled[currBallImport] = true;
currBallImport++;
keypressed = true;
glutPostRedisplay();
}
keypressed = false;
break;
case'e':// e for entry (user input/entry)
if (keypressed == false) {
importInfo_userInput(currBallImport);
filled[currBallImport] = true;
currBallImport++;
keypressed = true;
}
keypressed = false;
break;
}
}
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 5.0f, 5.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
int main(int argc, char **argv) {
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInit(&argc, argv);
glutInitWindowSize(500, 500);
glutInitWindowPosition(100, 100);
glutCreateWindow("Ball cage!");
glutReshapeFunc(Reshape);
glutDisplayFunc(Display);
glutKeyboardFunc(Keyboard);
/*
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
*/
glutMainLoop();
}
|