Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <glm/gtc/random.hpp>
  2.  
  3. #include "playerHp.h"
  4.  
  5.  
  6. #include <shaders/diffuse_vert_glsl.h>
  7. #include <shaders/diffuse_frag_glsl.h>
  8. #include <shaders/color_vert_glsl.h>
  9. #include <shaders/color_frag_glsl.h>
  10. #include <glm/gtx/euler_angles.hpp>
  11.  
  12.  
  13. // Static resources
  14. std::unique_ptr<ppgso::Mesh> playerHp::mesh;
  15. std::unique_ptr<ppgso::Texture> playerHp::texture;
  16. std::unique_ptr<ppgso::Shader> playerHp::shader;
  17.  
  18.  
  19. playerHp::playerHp(Object *parent): parent(parent) {
  20. scale = {0.2f,0.2f,0.2f};
  21. rotation = glm::ballRand(ppgso::PI);
  22. rotMomentum = glm::ballRand(ppgso::PI);
  23. position = {0,1.5,0};
  24.  
  25. if (!shader) shader = std::make_unique<ppgso::Shader>(color_vert_glsl, color_frag_glsl);
  26. if (!texture) texture = std::make_unique<ppgso::Texture>(ppgso::image::loadBMP("asteroid.bmp"));
  27. if (!mesh) mesh = std::make_unique<ppgso::Mesh>("hp.obj");
  28. }
  29.  
  30.  
  31. bool playerHp::update(Scene &scene, float dt,int offset) {
  32. // Count time alive
  33. position = {-8+(scale.x*offset),-8,0};
  34. rotation += rotMomentum * dt;
  35. generateModelMatrix();
  36. return true;
  37. }
  38.  
  39. void playerHp::render(Scene &scene) {
  40. shader->use();
  41.  
  42. // Set up light
  43. shader->setUniform("LightDirection", scene.lightDirection);
  44.  
  45. // use camera
  46. shader->setUniform("ProjectionMatrix", scene.camera->projectionMatrix);
  47. shader->setUniform("ViewMatrix", scene.camera->viewMatrix);
  48. shader->setUniform("OverallColor", {1,0,0});
  49. // render mesh
  50. shader->setUniform("ModelMatrix", modelMatrix);
  51. shader->setUniform("Texture", *texture);
  52. mesh->render();
  53. }
  54.  
  55. //void ::generateModelMatrix() {
  56. // modelMatrix =
  57. // glm::translate(glm::mat4(1.0f), position + parent->position)
  58. // * glm::orientate4(rotation)
  59. // * glm::scale(glm::mat4(1.0f), scale * parent->scale);
  60. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement