void move(mat4 & e, vec3 & pos) { //e_position -= vec3(getPosition().v[0],0,getPosition().v[2]) * getDelta() * e_speed; if(e_isAlive) { e = scale(e, vec3(1.5,1.5,1.5)); e_direction = vec3(getPosition() - e_cs.center); e_direction = normalise(e_direction); e_rotation.v[1] = std::acos(e_direction.v[2]); if(e_direction.v[0] > 0) e_rotation.v[1] =-e_rotation.v[1]; e = rotate_x_deg(e, e_rotation.v[0]); e = rotate_y_deg(e, (-e_rotation.v[1] * (180/M_PI))); e = rotate_z_deg(e, e_rotation.v[2]); } if(e_isAlive) { vec3 newpos(e_cs.center); newpos += e_direction * e_speed; // newpos.v[1] -= 0.3; setE_Position(newpos); e = translate(e,getE_Position()); } // e_position = getPosition() - e_position; // temp -= getPosition() * getDelta() * e_speed;//vec3(getPosition().v[0],0,getPosition().v[2]);// * getDelta() * e_speed; }
// Maintain translations and rotations. inline void updateView() { mat4 T = translate (identity_mat4 (), vec3 (-cam_pos[0], -cam_pos[1], -cam_pos[2])); // cam translation mat4 R = rotate_z_deg(identity_mat4(), -cam_zaw) * rotate_y_deg(identity_mat4(), -cam_yaw) * rotate_x_deg(identity_mat4(), -cam_xaw); mat4 view_mat = T * R; glUniformMatrix4fv (view_mat_location, 1, GL_FALSE, view_mat.m); }
void display(){ computeMatricesFromInputs(); glEnable (GL_DEPTH_TEST); // enable depth-testing glDepthFunc (GL_LESS); // depth-testing interprets a smaller value as "closer" glClearColor (0.5f, 0.5f, 0.5f, 1.0f); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram (shaderProgramID); //glBindTexture(GL_TEXTURE_2D, texs[1]); glActiveTexture(GL_TEXTURE0); glBindVertexArray(vaos[1]); // int matrix_location2 = glGetUniformLocation (shaderProgramID, "model"); int view_mat_location2 = glGetUniformLocation (shaderProgramID, "view"); int proj_mat_location2 = glGetUniformLocation (shaderProgramID, "proj"); int tex_loc2 = glGetUniformLocation (shaderProgramID,"basic_texture"); mat4 viewMatrix2 = getViewMatrix(); mat4 persp_proj2 = getProjectionMatrix(); mat4 model3 = identity_mat4 (); model3 = rotate_x_deg(model3,90); model3 = scale(model3, vec3(20,20,20)); glUniformMatrix4fv (proj_mat_location2, 1, GL_FALSE, persp_proj2.m); glUniformMatrix4fv (view_mat_location2, 1, GL_FALSE, viewMatrix2.m); glUniformMatrix4fv (matrix_location2, 1, GL_FALSE, model3.m); // glBindTexture(GL_TEXTURE_2D, texs[1]); glDrawArrays(GL_TRIANGLES,0,g_point_count2); glBindVertexArray(vaos[2]); int matrix_location3 = glGetUniformLocation (shaderProgramID, "model"); int view_mat_location3 = glGetUniformLocation (shaderProgramID, "view"); int proj_mat_location3 = glGetUniformLocation (shaderProgramID, "proj"); zombie = identity_mat4(); move(zombie, getPosition()); // zombie = translate(zombie, getE_Position()); //zombie = translate(zombie, vec3(0.0,-20.0, 0)); glUniformMatrix4fv (proj_mat_location3, 1, GL_FALSE, persp_proj2.m); glUniformMatrix4fv (view_mat_location3, 1, GL_FALSE, viewMatrix2.m); glUniformMatrix4fv(matrix_location3,1,GL_FALSE, zombie.m); glDrawArrays(GL_TRIANGLES, 0, g_point_count3); // ---------------------------SKYBOX---------------------------------------------------------------- glDepthMask (GL_FALSE); glActiveTexture(GL_TEXTURE0);glBindTexture(GL_TEXTURE_CUBE_MAP, texs[0]); glBindVertexArray(vaos[0]); int matrix_location = glGetUniformLocation (shaderProgramID, "model"); int view_mat_location = glGetUniformLocation (shaderProgramID, "view"); int proj_mat_location = glGetUniformLocation (shaderProgramID, "proj"); int tex_loc = glGetUniformLocation (shaderProgramID,"basic_texture"); mat4 viewMatrix = getViewMatrix(); mat4 persp_proj = getProjectionMatrix(); model = identity_mat4(); model = rotate_x_deg(model, 90); model = translate(model, getPosition()); // mat4 global = model3 * model; glUniformMatrix4fv (proj_mat_location, 1, GL_FALSE, persp_proj.m); glUniformMatrix4fv (view_mat_location, 1, GL_FALSE, viewMatrix.m); glUniformMatrix4fv (matrix_location, 1, GL_FALSE, model.m); glDrawArrays(GL_TRIANGLES,0,36); // tell GL to only draw onto a pixel if the shape is closer to the viewer glDepthMask (GL_TRUE); //glUseProgram (shaderProgramID); /* glBindVertexArray(vaos[1]); //Declare your uniform variables that will be used in your shader int matrix_location2 = glGetUniformLocation (shaderProgramID, "model"); // int tex_loc = glGetUniformLocation (shaderProgramID,"basic_texture"); glUniform1i(tex_loc,0); mat4 model2 = identity_mat4(); model2 = scale(model2, vec3(100,100,100)); model2 = rotate_x_deg(model2, 90); mat4 global2 = global2 * model2; glUniformMatrix4fv(matrix_location2, 1, GL_FALSE, model2.m); glDrawArrays(GL_TRIANGLES,0, g_point_count2); */ /* // BOTTOM-LEFT mat4 viewMatrix2 = getViewMatrix(); mat4 persp_proj2 = getProjectionMatrix(); mat4 model2 = identity_mat4 (); model2 = rotate_z_deg (model, 180) * rotate_y_deg(model, 180); model2 = scale (model2, vec3(.1,.1,.1)); mat4 global1 = model2; // view = translate (view, vec3 (-cam_pos[0], -cam_pos[1], -cam_pos[2])); // glViewport (200, 150, width / 2, height / 2); glUniformMatrix4fv (proj_mat_location2, 1, GL_FALSE, persp_proj2.m); glUniformMatrix4fv (view_mat_location2, 1, GL_FALSE, viewMatrix2.m); glUniformMatrix4fv (matrix_location2, 1, GL_FALSE, model2.m); glDrawArrays (GL_TRIANGLES, 36, g_point_count3); */ // int matrix_location2 = glGetUniformLocation(shaderProgramID, "model"); // glDrawElements(GL_TRIANGLES, g_point_count2, GL_UNSIGNED_SHORT, &vaos[0]); /* glBindVertexArray(vaos[1]); int matrix_location2 = glGetUniformLocation (shaderProgramID, "model"); int view_mat_location2 = glGetUniformLocation (shaderProgramID, "view"); int proj_mat_location2 = glGetUniformLocation (shaderProgramID, "proj"); mat4 model2 = identity_mat4 (); model2 = rotate_x_deg (model, 180) * rotate_y_deg(model, 180); // model2 = scale (model, vec3(5,5,5)); // view = translate (view, vec3 (-cam_pos[0], -cam_pos[1], -cam_pos[2])); // glViewport (200, 150, width / 2, height / 2); glUniformMatrix4fv (matrix_location2, 1, GL_FALSE, model2.m); // mat4 spiral = identity_mat4(); // mat4 global = model * spiral; // glUniformMatrix4fv(matrix_location,1,GL_FALSE, global.m); glDrawArrays(GL_TRIANGLES,g_point_count2 + 1,g_point_count3); // glDrawElements(GL_TRIANGLES, g_point_count3, GL_UNSIGNED_SHORT, &vaos[1]); */ glutSwapBuffers(); }