added test script to lauch rockets, nicer explosions.
This commit is contained in:
parent
4712926be2
commit
9ce106c179
11 changed files with 127 additions and 35 deletions
|
|
@ -94,7 +94,10 @@ namespace endofthejedi {
|
|||
}
|
||||
}
|
||||
|
||||
void RendererPolygon3d::addExplosionEffect(size_t id, const glm::vec2 &explCenter, size_t n, float duration)
|
||||
void RendererPolygon3d::addExplosionEffect(
|
||||
size_t id, const glm::vec2 &explCenter, const glm::vec2 &missileVelocity,
|
||||
bool isPlanetHit,
|
||||
size_t n, float duration)
|
||||
{
|
||||
//float particleRadius = 0.005;
|
||||
//float particleRadius = 0.003;
|
||||
|
|
@ -124,7 +127,13 @@ namespace endofthejedi {
|
|||
glm::vec3 pos = glm::vec3(explCenter, 0.0) + glm::ballRand(explCoreSize);
|
||||
|
||||
glm::vec3 v = glm::ballRand(maxVelocity);
|
||||
v *= util::randf_0_1() * util::randf_0_1() * util::randf_0_1();
|
||||
|
||||
// TODO: is that good?
|
||||
if (isPlanetHit) {
|
||||
v *= util::randf_0_1() * util::randf_0_1() * util::randf_0_1();
|
||||
} else {
|
||||
v *= util::randf_0_1();
|
||||
}
|
||||
|
||||
// find collisions with planetns and limit max distance so particles
|
||||
// won't fly through planets
|
||||
|
|
@ -136,7 +145,8 @@ namespace endofthejedi {
|
|||
const game::Planet *nearestPlanet = nullptr;
|
||||
for (const game::Planet *planet : m_state->planets) {
|
||||
const glm::vec3 ppos3 = glm::vec3(planet->position, 0.0f);
|
||||
// TODO: check if inside planet!
|
||||
|
||||
// TODO: that's slightly wrong. use intersection for this.
|
||||
float dist = glm::distance(ppos3, pos);
|
||||
if (dist <= planet->radius) {
|
||||
isInsidePlanet = true;
|
||||
|
|
@ -158,18 +168,40 @@ namespace endofthejedi {
|
|||
}
|
||||
}
|
||||
|
||||
if (isInsidePlanet) {
|
||||
bool makeStationary = false;
|
||||
|
||||
if (isInsidePlanet && isPlanetHit) {
|
||||
util::IntersectionTest intersect;
|
||||
if (!intersect.raySphere(
|
||||
pos, v,
|
||||
glm::vec3(nearestPlanet->position, 0.0f), nearestPlanet->radius))
|
||||
glm::vec3(explCenter, 0.0f), v,
|
||||
glm::vec3(nearestPlanet->position, 0.0f), nearestPlanet->radius))
|
||||
{
|
||||
makeStationary = true;
|
||||
//std::cout<<"warning: intersection should be valid!" << std::endl;
|
||||
// TODO: must be as they lie on a plane and the dist is < as
|
||||
// the radius.
|
||||
// handle if this is wrong.
|
||||
|
||||
} else {
|
||||
// simple reflection, ignoring the missile velocity: this looks good enough
|
||||
(void) missileVelocity;
|
||||
glm::vec3 planetNormal = glm::normalize(pos - glm::vec3(nearestPlanet->position, 0.0f));
|
||||
v = glm::length(v) * planetNormal;
|
||||
|
||||
// TODO
|
||||
// considering the missile velocity is not yet working:
|
||||
|
||||
// set position to the intersection point between explosion
|
||||
// center and planet surface
|
||||
//pos = intersect.pointAtDistance(intersect.distance());
|
||||
//v = glm::vec3(missileVelocity, 0.0f);
|
||||
//v = v - 2.0f*glm::dot(v, planetNormal) * planetNormal;
|
||||
//v *= 4.0;
|
||||
//maxParticleDist = 100.0;
|
||||
//v = -v;
|
||||
|
||||
//pos = glm::vec3(nearestPlanet->position, 0.0f) + nearestPlanet->radius*planetNormal;
|
||||
|
||||
// set position to the intersection point between explosion
|
||||
// center and planet surface
|
||||
//const glm::vec3 planetNormal = glm::vec3(glm::normalize(explCenter - nearestPlanet->position), 0.0f);
|
||||
|
|
@ -196,6 +228,16 @@ namespace endofthejedi {
|
|||
//glm::vec3 r = vc - 2.0f*glm::dot(vc, planetNormal) * planetNormal;
|
||||
//v = r;
|
||||
}
|
||||
} else if (isInsidePlanet && !isPlanetHit) {
|
||||
// if a planet is just hit by explosions particles but not the
|
||||
// missile itself, don't reflect the particles in the planet.
|
||||
// just set them as stationary at place of explosion
|
||||
makeStationary = true;
|
||||
}
|
||||
|
||||
if (makeStationary) {
|
||||
v = glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
pos = glm::vec3(explCenter, 0.0f);;
|
||||
}
|
||||
|
||||
batch->setParticle(i, pos, v, maxParticleDist);
|
||||
|
|
@ -218,12 +260,16 @@ namespace endofthejedi {
|
|||
}
|
||||
|
||||
if (!gotIt) {
|
||||
addExplosionEffect(expl->id, expl->position, 1000, 1.0);
|
||||
addExplosionEffect(
|
||||
expl->id, expl->position,
|
||||
expl->missileVelocity,
|
||||
(expl->hit == game::Hit::Planet),
|
||||
1000, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
//if (m_particles.size() == 0) {
|
||||
// addExplosionEffect(0, glm::vec2(0.0, 0.0), 1000, 2.0);
|
||||
// addExplosionEffect(0, glm::vec2(0.0, 0.0), glm::vec2(0.0, 0.0), false, 10000, 2.0);
|
||||
//}
|
||||
|
||||
std::vector<ParticleBatch*> rm;
|
||||
|
|
|
|||
|
|
@ -42,7 +42,10 @@ namespace endofthejedi {
|
|||
|
||||
void addModel(const std::string &filename, PolygonModel **dest);
|
||||
|
||||
void addExplosionEffect(size_t id, const glm::vec2 &pos, size_t n, float duration);
|
||||
void addExplosionEffect(
|
||||
size_t id, const glm::vec2 &pos, const glm::vec2 &missileVelocity,
|
||||
bool hitPlanet,
|
||||
size_t n, float duration);
|
||||
|
||||
void advanceGraphicObjects(float dt);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue