53 lines
1.6 KiB
C++
53 lines
1.6 KiB
C++
#include "glm.hpp"
|
|
#include "src/Shader_Loader.h"
|
|
|
|
#pragma once
|
|
class Bullet
|
|
{
|
|
private:
|
|
float speed;
|
|
float lifetime;
|
|
glm::vec3 directionNormalized;
|
|
glm::vec3 startPosition;
|
|
float birthTime;
|
|
float scale;
|
|
//GLuint program;
|
|
Core::RenderContext renderContext;
|
|
|
|
float getAge(float time) {
|
|
return time - birthTime;
|
|
}
|
|
|
|
Bullet(float speed, float lifetime, glm::vec3 directionNormalized, glm::vec3 startPosition, float birthTime, Core::RenderContext renderContext, float scale){
|
|
this->speed = speed;
|
|
this->lifetime = lifetime;
|
|
this->directionNormalized = directionNormalized;
|
|
this->startPosition = startPosition;
|
|
this->birthTime = birthTime;
|
|
this->renderContext = renderContext;
|
|
this->scale = scale;
|
|
}
|
|
|
|
public:
|
|
static Bullet* createSimpleBullet(glm::vec3 directionNormalized, glm::vec3 startPosition, float birthTime) {
|
|
static bool simpleRenderContextLoaded;
|
|
static Core::RenderContext simpleRenderContext;
|
|
if (!simpleRenderContextLoaded) {
|
|
simpleRenderContextLoaded = true;
|
|
Core::loadModelToContext("./models/sphere.obj", simpleRenderContext);
|
|
}
|
|
return new Bullet(10, 10, directionNormalized, startPosition, birthTime, simpleRenderContext, 0.01f);
|
|
}
|
|
|
|
bool shouldBeDestroyed(float time, GLuint program) {
|
|
float age = getAge(time);
|
|
if (age > lifetime) {
|
|
return true;
|
|
}
|
|
glm::mat4 modelMatrix = glm::translate(glm::mat4(1.0f), startPosition) * glm::translate(directionNormalized * speed * age) * glm::scale(glm::vec3(scale));
|
|
Core::drawObjectPBR(renderContext, modelMatrix, glm::vec3(1.f, 0.f, 0.f), 0.3, 0, program);
|
|
return false;
|
|
}
|
|
};
|
|
|