Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <glm/gtc/random.hpp>
- #include "playerHp.h"
- #include <shaders/diffuse_vert_glsl.h>
- #include <shaders/diffuse_frag_glsl.h>
- #include <shaders/color_vert_glsl.h>
- #include <shaders/color_frag_glsl.h>
- #include <glm/gtx/euler_angles.hpp>
- // Static resources
- std::unique_ptr<ppgso::Mesh> playerHp::mesh;
- std::unique_ptr<ppgso::Texture> playerHp::texture;
- std::unique_ptr<ppgso::Shader> playerHp::shader;
- playerHp::playerHp(Object *parent): parent(parent) {
- scale = {0.2f,0.2f,0.2f};
- rotation = glm::ballRand(ppgso::PI);
- rotMomentum = glm::ballRand(ppgso::PI);
- position = {0,1.5,0};
- if (!shader) shader = std::make_unique<ppgso::Shader>(color_vert_glsl, color_frag_glsl);
- if (!texture) texture = std::make_unique<ppgso::Texture>(ppgso::image::loadBMP("asteroid.bmp"));
- if (!mesh) mesh = std::make_unique<ppgso::Mesh>("hp.obj");
- }
- bool playerHp::update(Scene &scene, float dt,int offset) {
- // Count time alive
- position = {-8+(scale.x*offset),-8,0};
- rotation += rotMomentum * dt;
- generateModelMatrix();
- return true;
- }
- void playerHp::render(Scene &scene) {
- shader->use();
- // Set up light
- shader->setUniform("LightDirection", scene.lightDirection);
- // use camera
- shader->setUniform("ProjectionMatrix", scene.camera->projectionMatrix);
- shader->setUniform("ViewMatrix", scene.camera->viewMatrix);
- shader->setUniform("OverallColor", {1,0,0});
- // render mesh
- shader->setUniform("ModelMatrix", modelMatrix);
- shader->setUniform("Texture", *texture);
- mesh->render();
- }
- //void ::generateModelMatrix() {
- // modelMatrix =
- // glm::translate(glm::mat4(1.0f), position + parent->position)
- // * glm::orientate4(rotation)
- // * glm::scale(glm::mat4(1.0f), scale * parent->scale);
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement