void drawRadar(){ //Set up orthographic projection for radar mat4 projection1 = perspective(45.0f, window.window_aspect, 0.01f, 10.0f); glm::mat4 Projection2 = glm::ortho( -10.0f, 10.0f, -10.0f, 00.0f,1.0f, 10.0f); glm::mat4 View = glm::lookAt( glm::vec3(0,0,5), // Camera is at (0,0,5), in World Space glm::vec3(0,0,0), // and looks at the origin glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down) ); mat4 another = View; mat4 healthBarMatrix = View; another = translate(another, vec3(8.5,-8.5,0)); another = rotate(another, 90.0f, vec3(0,1,0)); another = rotate(another, 90.0f, vec3(0,0,1)); healthBarMatrix = translate(healthBarMatrix, vec3(-9.5,-0.5,0)); //healthBarMatrix = rotate(healthBarMatrix, 90.0f, vec3(0,1,0)); healthBarMatrix = rotate(healthBarMatrix, -90.0f, vec3(0,0,1)); healthBarMatrix = scale(healthBarMatrix, vec3(0.05f, userTeam.soldiers[0].health/10.f, 0.05f)); if(userTeam.soldiers[0].health < 50){ healthBar.color = vec3(1.f, userTeam.soldiers[0].health/50.f, 0.f); } else{ healthBar.color = vec3(1.f - (userTeam.soldiers[0].health-50.f)/50.f, 1.f, 0.f); } healthBar.Draw(Projection2, healthBarMatrix, tod, 0); mat4 radar = another; //Radar display int radarBlipTime = current_timeDisplay * 1000; float radarBlip = 0.0015 * (radarBlipTime%1000); radar = scale(radar, vec3(radarBlip, radarBlip, radarBlip)); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); disc.color = vec3(0,1,0); disc.Draw(Projection2, radar, tod, 0); another = scale(another, vec3(1.5, 1.5, 1.5)); disc.Draw(Projection2, another, tod, 0); glPolygonMode(GL_FRONT_AND_BACK, window.wireframe ? GL_LINE : GL_FILL); disc.color = vec3(0,0.25,0); disc.Draw(Projection2, another, tod, 0); another = translate(View, vec3(8.5 - ((3/104.6)*transX),-8.6 + ((3/104.6)*transZ),0)); usr.Draw(Projection2, another, tod, 0); stringstream ammo (stringstream::in | stringstream::out); ammo << userTeam.soldiers[0].ammo; activeTextDisplay(("Ammo: " + ammo.str()).c_str(), -0.95f, -0.85f, 16); }
void DisplayDisc() { Window * window = Window::FindCurrentWindow(windows); if (window->handle == BAD_GL_VALUE) return; glViewport(0, 0, window->size.x, window->size.y); vec4 crimson(0.6f , 0.0f , 0.0f , 1.0f); vec3 ambient = vec3(0.0f , 0.0f , 0.0f); vec3 specular = vec3(0.0f , 0.0f , 0.3f); vec3 diffuse = vec3(0.0f , 0.0f , 0.9f); glClearColor(crimson.r , crimson.g , crimson.b , crimson.a); glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glEnable(GL_DEPTH_TEST); mat4 model_matrix = rotate(mat4() , radians(window->LocalTime() * 30.0f) , vec3(0.0f , 1.0f , 0.0f)); model_matrix = scale(model_matrix , vec3(3.0f , 3.0f , 3.0f)); mat4 view_matrix = lookAt(vec3(0.0f , 0.0f , 8.0f) , vec3(0.0f , 0.0f , 0.0f) , vec3(0.0f , 1.0f , 0.0f)); mat4 projection_matrix = perspective(radians(window->fovy) , window->aspect , window->near_distance , window->far_distance); phong_shader.Use(model_matrix , view_matrix , projection_matrix); phong_shader.SetMaterial(diffuse , specular , 128.0f , ambient); phong_shader.SetLightPosition(vec3(0.0f , 0.0f , 1000.0f)); phong_shader.SelectSubroutine(PhongShader::PHONG_WITH_TEXTURE); phong_shader.EnableTexture(textures[2] , 0); disc3.Draw(false); phong_shader.UnUse(); if (window->draw_normals) { constant_shader.Use(model_matrix , view_matrix , projection_matrix); constant_shader.SetMaterial(diffuse , specular , 32.0f , vec3(1.0f , 1.0f , 1.0f)); disc3.Draw(true); constant_shader.UnUse(); } glutSwapBuffers(); disc3.UpdateValues(TestUpdateDisc , window->LocalTime(), nullptr); }
void DrawScene(Window * window) { phong_shader.GLReturnedError("DrawScene() - entering"); #ifdef MOVE mat4 m = rotate(mat4() , radians(window->LocalTime() * 30.0f) , vec3(0.0f , 1.0f , 0.2f)); m = translate(m, vec3(0.0f, 11.5f * cos(window->LocalTime() * 0.5f) + 2.0f, 11.5f * sin(window->LocalTime() * 0.5f) + 2.0f)); #else mat4 m; #endif // MOVE mat4 view_matrix = lookAt(vec3(m * vec4(eye, 1.0f)), cop, up); mat4 model_matrix; mat4 projection_matrix = perspective(radians(window->fovy), window->aspect, window->near_distance, window->far_distance); vec3 z_axis = vec3(0.0f, 0.0f, 1.0f); vec3 y_axis = vec3(0.0f, 1.0f, 0.0f); vec3 ambient = vec3(0.1f, 0.1f, 0.1f); vec3 specular = vec3(1.0f, 1.0f, 1.0f); float c_offset = radians(45.0f); glViewport(0, 0, window->size.x, window->size.y); const int count_of_shapes = 4; for (unsigned int i = 0; i < instances.size(); i++) { model_matrix = translate(mat4(), instances[i].position); model_matrix = rotate(model_matrix, radians(window->LocalTime() * instances[i].rate) + instances[i].offset, y_axis); if (i % count_of_shapes == 3) model_matrix = scale(model_matrix, vec3(0.25f, 0.25f, 0.25f)); phong_shader.Use(model_matrix, view_matrix, projection_matrix); phong_shader.SetMaterial(instances[i].diffuse, specular, 32.0f, ambient); phong_shader.SetLightPosition(vec3(0.0f, 0.0f, 1000.0f)); switch (i % count_of_shapes) { case 0: disc1.Draw(false); break; case 1: disc3.Draw(false); break; case 2: plane2.Draw(false); break; case 3: cube.Draw(false); break; } phong_shader.UnUse(); #ifdef SHOW_NORMALS if (i == 0) { constant_shader.Use(model_matrix, view_matrix, projection_matrix); constant_shader.SetMaterial(vec3(0.0f, 0.0f, 0.8f), specular, 128.0f, vec3(1.0f, 0.0f, 0.0f)); disc1.Draw(true); constant_shader.UnUse(); } #endif } model_matrix = mat4(); mat4 mz = model_matrix; model_matrix = scale(model_matrix, vec3(0.5f, 0.5f, 16.0f)); phong_shader.Use(model_matrix, view_matrix, projection_matrix); phong_shader.SetMaterial(vec3(0.0f, 0.0f, 0.8f), specular, 128.0f, ambient); phong_shader.SetLightPosition(vec3(0.0f, 1000.0f, 0.0f)); cylinder1.Draw(false); phong_shader.UnUse(); #ifdef SHOW_NORMALS constant_shader.Use(model_matrix, view_matrix, projection_matrix); constant_shader.SetMaterial(vec3(0.0f, 0.0f, 0.8f), specular, 128.0f, vec3(1.0f, 1.0f, 1.0f)); cylinder.Draw(true); constant_shader.UnUse(); #endif model_matrix = rotate(mz, radians(90.0f), y_axis); model_matrix = scale(model_matrix, vec3(0.5f, 0.5f, 16.0f)); phong_shader.Use(model_matrix, view_matrix, projection_matrix); phong_shader.SetMaterial(vec3(1.0f, 0.0f, 0.0f), specular, 128.0f, ambient); phong_shader.SetLightPosition(vec3(0.0f, 1000.0f, 0.0f)); cylinder1.Draw(false); phong_shader.UnUse(); model_matrix = rotate(mz, radians(-90.0f), vec3(1.0f, 0.0f, 0.0f)); model_matrix = scale(model_matrix, vec3(0.5f, 0.5f, 16.0f)); phong_shader.Use(model_matrix, view_matrix, projection_matrix); phong_shader.SetMaterial(vec3(0.0f, 1.0f, 0.0f), specular, 128.0f, ambient); phong_shader.SetLightPosition(vec3(0.0f, 1000.0f, 0.0f)); cylinder1.Draw(false); phong_shader.UnUse(); cylinder1.UpdateValues(TestUpdate, window->LocalTime(), nullptr); }