#include #include "UI.h" #include "Lines.h" #include "Axis.h" #include "Box.h" #include "Object.h" #include "OffObject.h" #include "Errors.h" #include using namespace std; #include "vgl.h" #include "mat.h" #include "vec.h" #include "LoadShaders.h" // globals OffObject starburst_G; Axis axis_G; Box box_G; OffObject object_G("offs/lizard.off"); GLuint program_G; float theta_G =0; void init(void); void display(void); void CheckForErrors(void); struct item{ vec3 loc; vec3 dir; float size; float speed; }; vector wheels; float NewRand(){ return 1.-2.0*rand()/float(RAND_MAX); } void MakeWheel() { item wheel; wheel.loc = vec3(NewRand(), NewRand(), NewRand()); wheel.dir = normalize(vec3(NewRand(), NewRand(), NewRand())*.01); wheel.size = .25+ NewRand()/4.0; wheel.speed = 2*NewRand(); wheels.push_back(wheel); return; } int main(int argc, char * argv[]){ srand(time(NULL)); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA); glutInitWindowSize(512, 512); glutInitContextVersion(3,0); glutInitContextProfile(GLUT_CORE_PROFILE | GLUT_DEBUG); //glutInitContextProfile(GLUT_FORWARD_COMPATIBLE | GLUT_DEBUG); glutCreateWindow(argv[0]); if (glewInit()) { cerr<< "Unable to initialize GLEW " << endl; return -1; } init(); glutDisplayFunc(display); glutKeyboardFunc(Keypress); glutSpecialFunc(SpecialKeypress); glutKeyboardUpFunc(KeyUp); glutSpecialUpFunc(SpecialUp); KeyHelp(); glutMainLoop(); return 0; } void init(void) { MakeWheel(); InitErrors(); glClearColor(1,1,1,1); ShaderInfo shaders [] = { { GL_VERTEX_SHADER, "vertex.glsl"}, { GL_FRAGMENT_SHADER, "fragment.glsl"}, { GL_NONE, NULL} }; program_G = LoadShaders(shaders); glUseProgram(program_G); starburst_G.Bind(program_G); axis_G.Bind(program_G); box_G.Bind(program_G); object_G.Bind(program_G); return; } // stolen from http://gamedev.stackexchange.com/questions/23672/determine-resulting-angle-of-wall-collision void MoveWheel(item & wheel){ wheel.loc += wheel.dir*.01; if (abs(wheel.loc.x) > 1 or abs(wheel.loc.y) > 1 or abs(wheel.loc.z) >1) { if (wheel.loc.x > 1) { wheel.dir.x *= -1; wheel.loc.x = 1; } else if (wheel.loc.x < -1) { wheel.dir.x *= -1; wheel.loc.x = -1; } if (wheel.loc.y < -1) { wheel.dir.y *= -1; wheel.loc.y = -1; } else if (wheel.loc.y > 1) { wheel.dir.y *= -1; wheel.loc.y =1; } if (wheel.loc.z < -1) { wheel.dir.z *= -1; wheel.loc.z = -1; } else if (wheel.loc.z > 1) { wheel.dir.z *= -1; wheel.loc.z =1; } wheel.loc += wheel.dir*.01; //return vector - 2 * dot(vector, normal) * normal; } } void display(void){ mat4 model; mat4 T,S,R; mat4 world; mat4 I = mat4(1.0); int i; static int mLoc = glGetUniformLocation(program_G, "model"); static int wLoc = glGetUniformLocation(program_G, "world"); glClear(GL_COLOR_BUFFER_BIT); // reset all matricies to be identity glUniformMatrix4fv(wLoc, 1, true, I); glUniformMatrix4fv(mLoc, 1, true, I); // box does not move at all. box_G.Display(); // object_G just lives in space rotating away. R = RotateX(theta_G) * RotateY(theta_G*0.5) * RotateZ(theta_G*0.25); glUniformMatrix4fv(mLoc, 1, true, R); object_G.Display(); // rotate the world a little each time. R = RotateZ(-theta_G/10); world = R; glUniformMatrix4fv(wLoc, 1, true, world); // reset the model matrix to the identity for the axis glUniformMatrix4fv(mLoc, 1, true, I); axis_G.Display(); for(i=0;i