2016-09-28 19:26:11 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <glm/vec2.hpp>
|
2016-09-30 19:24:06 +00:00
|
|
|
#include <glm/vec3.hpp>
|
2016-09-28 19:26:11 +00:00
|
|
|
|
|
|
|
#include "glclasses.hpp"
|
|
|
|
|
|
|
|
namespace endofthejedi {
|
2016-10-03 20:58:52 +00:00
|
|
|
#if 0
|
|
|
|
class VertexAttribute {
|
|
|
|
public:
|
|
|
|
class Data {
|
|
|
|
public:
|
|
|
|
enum class Type {
|
|
|
|
Integer, Float, Float2, Float3, Float4, Matrix3, Matrix4
|
|
|
|
};
|
|
|
|
|
|
|
|
void setDataInteger(int index, int v)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Data(Type type, int size) : m_type(type), m_size(size)
|
|
|
|
{
|
|
|
|
if (type ==
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_size;
|
|
|
|
Type m_type;
|
|
|
|
std::vector<int> m_sourceInteger;
|
|
|
|
std::vector<float> m_sourceFloat;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
Data data;
|
|
|
|
std::string variableName;
|
|
|
|
int divisor;
|
|
|
|
GLint index;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2016-09-28 19:26:11 +00:00
|
|
|
class ParticleBatch {
|
|
|
|
public:
|
2016-09-30 19:48:15 +00:00
|
|
|
ParticleBatch(size_t id, size_t numParticles, float particleRadius, float halfAge);
|
2016-09-28 19:26:11 +00:00
|
|
|
|
|
|
|
// deallocate opengl stuff on destroy
|
|
|
|
~ParticleBatch();
|
|
|
|
|
2016-10-03 20:58:52 +00:00
|
|
|
// set particle data
|
2016-10-02 15:22:47 +00:00
|
|
|
void setParticle(size_t index, const glm::vec3 &p, const glm::vec3 &v, float maxDistance);
|
2016-09-30 19:24:06 +00:00
|
|
|
|
2016-10-03 20:58:52 +00:00
|
|
|
// stuff for setup/rendering usage
|
2016-10-02 09:00:03 +00:00
|
|
|
void setup(Shader *shader);
|
2016-09-28 19:26:11 +00:00
|
|
|
void bind();
|
|
|
|
void upload();
|
2016-10-02 09:00:03 +00:00
|
|
|
void render(Shader *shader);
|
2016-09-28 19:26:11 +00:00
|
|
|
|
2016-10-03 20:58:52 +00:00
|
|
|
// advance internal state (mostly age)
|
2016-09-29 06:28:56 +00:00
|
|
|
void tick(float dt);
|
2016-09-30 18:19:10 +00:00
|
|
|
|
2016-10-03 20:58:52 +00:00
|
|
|
// check if the lifetime is over and whether it can be deleted.
|
|
|
|
bool done() const;
|
2016-10-03 08:47:02 +00:00
|
|
|
|
2016-10-03 20:58:52 +00:00
|
|
|
// access attributes
|
|
|
|
size_t numParticles() const { return m_numParticles; }
|
|
|
|
float ageNormalized() const { return m_age / (m_maxNumHalfAges*m_halfAge); }
|
|
|
|
float age() const { return m_age; }
|
|
|
|
size_t id() const { return m_id; }
|
2016-10-03 08:47:02 +00:00
|
|
|
const glm::vec3 &explosionCenter() const { return m_center; }
|
|
|
|
|
2016-10-03 20:58:52 +00:00
|
|
|
// set attributes
|
|
|
|
void setCenter(const glm::vec3 ¢er);
|
|
|
|
void setMaxVelocity(float maxVelocity);
|
|
|
|
|
2016-09-28 19:26:11 +00:00
|
|
|
private:
|
2016-10-02 15:22:47 +00:00
|
|
|
size_t dataSizeForIndex(size_t index);
|
|
|
|
void *dataSourceForIndex(size_t index);
|
2016-09-28 19:26:11 +00:00
|
|
|
|
|
|
|
private:
|
2016-10-02 15:22:47 +00:00
|
|
|
// id of explosion
|
2016-09-30 18:19:10 +00:00
|
|
|
size_t m_id;
|
2016-10-02 15:22:47 +00:00
|
|
|
|
|
|
|
// uniforms for the shader
|
2016-09-28 19:26:11 +00:00
|
|
|
size_t m_numParticles;
|
2016-09-28 22:50:14 +00:00
|
|
|
float m_particleRadius;
|
2016-09-29 06:28:56 +00:00
|
|
|
float m_age;
|
2016-10-03 08:47:02 +00:00
|
|
|
const float m_halfAge;
|
|
|
|
const float m_maxNumHalfAges;
|
2016-09-30 19:24:06 +00:00
|
|
|
float m_maxVelocity;
|
|
|
|
glm::vec3 m_center;
|
2016-09-28 22:50:14 +00:00
|
|
|
|
2016-10-02 15:22:47 +00:00
|
|
|
// meta data
|
|
|
|
size_t m_num_vertex_buffers;
|
|
|
|
std::vector<GLuint> m_data_vbos;
|
|
|
|
std::vector<GLuint> m_attr_locations;
|
2016-09-28 19:26:11 +00:00
|
|
|
|
2016-10-02 15:22:47 +00:00
|
|
|
// vertex attributes
|
|
|
|
std::vector<float> m_data_geometry;
|
2016-09-30 19:24:06 +00:00
|
|
|
std::vector<glm::vec3> m_data_position;
|
|
|
|
std::vector<glm::vec3> m_data_velocity;
|
2016-10-02 15:22:47 +00:00
|
|
|
std::vector<float> m_data_max_distance;
|
2016-09-28 19:26:11 +00:00
|
|
|
};
|
|
|
|
}
|