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(
|
||||
#version 120
|
||||
varying vec2 vertex;
|
||||
varying vec2 velocity;
|
||||
uniform float maxAge;
|
||||
uniform float time;
|
||||
void main()
|
||||
|
@ -10,6 +11,8 @@ void main()
|
|||
discard;
|
||||
}
|
||||
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);
|
||||
}
|
||||
)raw_string"
|
|
@ -3,15 +3,18 @@ R"raw_string(
|
|||
attribute vec2 in_vertex;
|
||||
attribute vec2 in_position;
|
||||
attribute vec2 in_velocity;
|
||||
varying vec2 velocity;
|
||||
varying vec2 vertex;
|
||||
uniform float time;
|
||||
uniform float size;
|
||||
void main()
|
||||
{
|
||||
vec2 p = size*in_vertex;
|
||||
p += time * in_velocity;
|
||||
p += log(1.0+time) * in_velocity;
|
||||
p += in_position;
|
||||
gl_Position = vec4(p, 0.0, 1.0);
|
||||
|
||||
vertex = in_vertex;
|
||||
velocity = in_velocity;
|
||||
}
|
||||
)raw_string"
|
|
@ -23,7 +23,7 @@ namespace endofthejedi {
|
|||
-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_velocity.resize(m_numParticles);
|
||||
|
@ -88,7 +88,7 @@ namespace endofthejedi {
|
|||
|
||||
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
|
||||
|
||||
|
|
|
@ -69,13 +69,13 @@ namespace endofthejedi {
|
|||
|
||||
m_shader.bind();
|
||||
|
||||
// TODO :Z?
|
||||
|
||||
renderPlanets();
|
||||
renderShips();
|
||||
renderMissiles();
|
||||
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
renderParticles();
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
|
||||
//glColor3f(1.0, 0.0, 0.0);
|
||||
//glBegin(GL_QUADS);
|
||||
|
@ -102,11 +102,12 @@ namespace endofthejedi {
|
|||
|
||||
for (size_t i=0; i<n; i++) {
|
||||
// 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();
|
||||
|
||||
// with random velocities
|
||||
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);
|
||||
}
|
||||
|
@ -118,14 +119,24 @@ namespace endofthejedi {
|
|||
|
||||
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) {
|
||||
batch->tick(dt);
|
||||
if (batch->done()) {
|
||||
rm.push_back(batch);
|
||||
}
|
||||
}
|
||||
|
||||
for (ParticleBatch *batch : rm) {
|
||||
m_particles.remove(batch);
|
||||
delete(batch);
|
||||
|
||||
std::cout<<"particle batch done!" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,15 +214,15 @@ namespace endofthejedi {
|
|||
|
||||
// TODO: which visual size has the rocket? in game its just a point with
|
||||
// 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)
|
||||
{
|
||||
// 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
|
||||
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));
|
||||
return mat;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue