nicer explosion effects
This commit is contained in:
parent
1123be9860
commit
70b7233043
4 changed files with 30 additions and 13 deletions
|
@ -1,6 +1,7 @@
|
||||||
R"raw_string(
|
R"raw_string(
|
||||||
#version 120
|
#version 120
|
||||||
varying vec2 vertex;
|
varying vec2 vertex;
|
||||||
|
varying vec2 velocity;
|
||||||
uniform float maxAge;
|
uniform float maxAge;
|
||||||
uniform float time;
|
uniform float time;
|
||||||
void main()
|
void main()
|
||||||
|
@ -10,6 +11,8 @@ void main()
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
float decay = time / maxAge;
|
float decay = time / maxAge;
|
||||||
|
decay = 5.0*decay*decay;
|
||||||
|
// (length(10.0*velocity));
|
||||||
gl_FragColor = vec4(1.0/max(1.0, decay), 1.0/max(1.0, 6.0*decay), 0.0, 1.0);
|
gl_FragColor = vec4(1.0/max(1.0, decay), 1.0/max(1.0, 6.0*decay), 0.0, 1.0);
|
||||||
}
|
}
|
||||||
)raw_string"
|
)raw_string"
|
|
@ -3,15 +3,18 @@ R"raw_string(
|
||||||
attribute vec2 in_vertex;
|
attribute vec2 in_vertex;
|
||||||
attribute vec2 in_position;
|
attribute vec2 in_position;
|
||||||
attribute vec2 in_velocity;
|
attribute vec2 in_velocity;
|
||||||
|
varying vec2 velocity;
|
||||||
varying vec2 vertex;
|
varying vec2 vertex;
|
||||||
uniform float time;
|
uniform float time;
|
||||||
uniform float size;
|
uniform float size;
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 p = size*in_vertex;
|
vec2 p = size*in_vertex;
|
||||||
p += time * in_velocity;
|
p += log(1.0+time) * in_velocity;
|
||||||
p += in_position;
|
p += in_position;
|
||||||
gl_Position = vec4(p, 0.0, 1.0);
|
gl_Position = vec4(p, 0.0, 1.0);
|
||||||
|
|
||||||
vertex = in_vertex;
|
vertex = in_vertex;
|
||||||
|
velocity = in_velocity;
|
||||||
}
|
}
|
||||||
)raw_string"
|
)raw_string"
|
|
@ -23,7 +23,7 @@ namespace endofthejedi {
|
||||||
-1.0f, 1.0f,
|
-1.0f, 1.0f,
|
||||||
-1.0f, -1.0f})
|
-1.0f, -1.0f})
|
||||||
{
|
{
|
||||||
std::cout<<"[ParticleBatch] create for " << numParticles << " num particles" << std::endl;
|
//std::cout<<"[ParticleBatch] create for " << numParticles << " num particles" << std::endl;
|
||||||
|
|
||||||
m_data_position.resize(m_numParticles);
|
m_data_position.resize(m_numParticles);
|
||||||
m_data_velocity.resize(m_numParticles);
|
m_data_velocity.resize(m_numParticles);
|
||||||
|
@ -88,7 +88,7 @@ namespace endofthejedi {
|
||||||
|
|
||||||
void ParticleBatch::upload()
|
void ParticleBatch::upload()
|
||||||
{
|
{
|
||||||
std::cout<<"[ParticleBatch] upload to vbo's " << std::endl;
|
//std::cout<<"[ParticleBatch] upload to vbo's " << std::endl;
|
||||||
|
|
||||||
glGenBuffers(4, m_data_vbos); // Generate buffer
|
glGenBuffers(4, m_data_vbos); // Generate buffer
|
||||||
|
|
||||||
|
|
|
@ -69,13 +69,13 @@ namespace endofthejedi {
|
||||||
|
|
||||||
m_shader.bind();
|
m_shader.bind();
|
||||||
|
|
||||||
// TODO :Z?
|
|
||||||
|
|
||||||
renderPlanets();
|
renderPlanets();
|
||||||
renderShips();
|
renderShips();
|
||||||
renderMissiles();
|
renderMissiles();
|
||||||
|
|
||||||
|
//glDisable(GL_DEPTH_TEST);
|
||||||
renderParticles();
|
renderParticles();
|
||||||
|
//glEnable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
//glColor3f(1.0, 0.0, 0.0);
|
//glColor3f(1.0, 0.0, 0.0);
|
||||||
//glBegin(GL_QUADS);
|
//glBegin(GL_QUADS);
|
||||||
|
@ -102,11 +102,12 @@ namespace endofthejedi {
|
||||||
|
|
||||||
for (size_t i=0; i<n; i++) {
|
for (size_t i=0; i<n; i++) {
|
||||||
// distribute in a circle
|
// distribute in a circle
|
||||||
float t = 2.0 * M_PI * i / (float) n;
|
float t = 4.0 * M_PI * i / (float) n;
|
||||||
t += 0.2*util::randf_m1_1();
|
t += 0.2*util::randf_m1_1();
|
||||||
|
|
||||||
// with random velocities
|
// with random velocities
|
||||||
glm::vec2 v = 0.2f*glm::vec2(sin(t), cos(t));
|
glm::vec2 v = 0.2f*glm::vec2(sin(t), cos(t));
|
||||||
|
v *= 0.2+0.8*util::randf_0_1();
|
||||||
|
|
||||||
batch->setParticle(i, pos, v);
|
batch->setParticle(i, pos, v);
|
||||||
}
|
}
|
||||||
|
@ -118,15 +119,25 @@ namespace endofthejedi {
|
||||||
|
|
||||||
void RendererPolygon3d::advanceGraphicObjects(float dt)
|
void RendererPolygon3d::advanceGraphicObjects(float dt)
|
||||||
{
|
{
|
||||||
|
for (const game::Explosion *expl : m_state->explosions) {
|
||||||
|
if (expl->age == 0.0) {
|
||||||
|
addExplosionEffect(expl->position, 200, 3.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ParticleBatch*> rm;
|
||||||
|
|
||||||
for (ParticleBatch *batch : m_particles) {
|
for (ParticleBatch *batch : m_particles) {
|
||||||
batch->tick(dt);
|
batch->tick(dt);
|
||||||
if (batch->done()) {
|
if (batch->done()) {
|
||||||
m_particles.remove(batch);
|
rm.push_back(batch);
|
||||||
delete(batch);
|
|
||||||
|
|
||||||
std::cout<<"particle batch done!" << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ParticleBatch *batch : rm) {
|
||||||
|
m_particles.remove(batch);
|
||||||
|
delete(batch);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RendererPolygon3d::renderPlanets()
|
void RendererPolygon3d::renderPlanets()
|
||||||
|
@ -203,15 +214,15 @@ namespace endofthejedi {
|
||||||
|
|
||||||
// TODO: which visual size has the rocket? in game its just a point with
|
// TODO: which visual size has the rocket? in game its just a point with
|
||||||
// no size because all others have size.
|
// no size because all others have size.
|
||||||
return computeModelMatrix(missile->position, 0.05f, a);
|
return computeModelMatrix(missile->position, 0.03f, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 RendererPolygon3d::computeModelMatrix(const game::Ship *ship)
|
glm::mat4 RendererPolygon3d::computeModelMatrix(const game::Ship *ship)
|
||||||
{
|
{
|
||||||
// TODO: rotate them before shooting, that looks better
|
// TODO: rotate them before shooting, that looks better
|
||||||
//return computeModelMatrix(ship->position, m_state->shipRadius());
|
glm::mat4 mat = computeModelMatrix(ship->position, m_state->shipRadius());
|
||||||
// XXX model is flipped
|
// XXX model is flipped
|
||||||
glm::mat4 mat = computeModelMatrix(ship->position, 0.3);
|
//glm::mat4 mat = computeModelMatrix(ship->position, 0.3);
|
||||||
mat = glm::rotate(mat, (float) M_PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
mat = glm::rotate(mat, (float) M_PI, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue