From cffe02f49b66a70d40816ffc8dea42f9e52da57f Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Sat, 28 Feb 2015 20:46:53 +0000 Subject: Reimplemented camera handling enabling 360-degree freelook. --- src/render/particleejector.cc | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/render/particleejector.cc') diff --git a/src/render/particleejector.cc b/src/render/particleejector.cc index 22ddf2d..51be345 100644 --- a/src/render/particleejector.cc +++ b/src/render/particleejector.cc @@ -38,7 +38,7 @@ void ParticleEjector::clear() ejector_last_eject = 0; } -void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_location, const math::Axis & ps_axis, const float thrust_factor) +void ParticleEjector::frame(const float seconds, const Camera &camera, const math::Vector3f & ps_location, const math::Axis & ps_axis, const float thrust_factor) { unsigned long now = core::application()->timestamp(); @@ -166,12 +166,13 @@ void ParticleEjector::frame(const float seconds, const math::Vector3f & ps_locat break; } - if (particles().size()) { - draw(ps_location, ps_axis); + if (particles().size()) + { + draw(camera, ps_location, ps_axis); } } -void ParticleEjector::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis) +void ParticleEjector::draw(const Camera &camera, const math::Vector3f & ps_location, const math::Axis & ps_axis) { } @@ -188,22 +189,22 @@ ParticleEjectorSprite::~ParticleEjectorSprite() } -void ParticleEjectorSprite::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis) +void ParticleEjectorSprite::draw(const Camera &camera, const math::Vector3f & ps_location, const math::Axis & ps_axis) { math::Vector3f quad[4]; Textures::bind(texture()); gl::begin(gl::Quads); - quad[0].assign((Camera::axis().up() - Camera::axis().left())); - quad[1].assign((Camera::axis().up() + Camera::axis().left())); - quad[2].assign((Camera::axis().up() * -1 + Camera::axis().left())); - quad[3].assign((Camera::axis().up() * -1 - Camera::axis().left())); + quad[0].assign((camera.axis().up() - camera.axis().left())); + quad[1].assign((camera.axis().up() + camera.axis().left())); + quad[2].assign((camera.axis().up() * -1 + camera.axis().left())); + quad[3].assign((camera.axis().up() * -1 - camera.axis().left())); for (Particles::iterator it = particles().begin(); it != particles().end(); it++) { Particle *particle = (*it); math::Axis rotation; - rotation.rotate(Camera::axis().forward(), particle->rotation()); + rotation.rotate(camera.axis().forward(), particle->rotation()); math::Vector3f l(attached() ? ps_location + ps_axis * particle->location() : particle->location()); const float r = particle->radius(); @@ -235,7 +236,7 @@ ParticleEjectorFlare::~ParticleEjectorFlare() } -void ParticleEjectorFlare::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis) +void ParticleEjectorFlare::draw(const Camera &camera, const math::Vector3f & ps_location, const math::Axis & ps_axis) { Textures::bind(texture()); gl::begin(gl::Quads); @@ -274,7 +275,7 @@ ParticleEjectorTrail::~ParticleEjectorTrail() } -void ParticleEjectorTrail::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis) +void ParticleEjectorTrail::draw(const Camera &camera, const math::Vector3f & ps_location, const math::Axis & ps_axis) { if (!particles().size()) { return; @@ -292,7 +293,7 @@ void ParticleEjectorTrail::draw(const math::Vector3f & ps_location, const math:: gl::color((*first)->color()); //math::Vector3f first_location(attached() ? ps_location + ps_axis * (*first)->location() : (*first)->location()); - math::Vector3f first_normal(math::crossproduct(((*first)->location() - ps_location), ((*first)->location() - Camera::eye()))); + math::Vector3f first_normal(math::crossproduct(((*first)->location() - ps_location), ((*first)->location() - camera.location()))); first_normal.normalize(); math::Vector3f next_normal(first_normal); @@ -312,7 +313,7 @@ void ParticleEjectorTrail::draw(const math::Vector3f & ps_location, const math:: Stats::quads++; while (next != particles().end()) { - next_normal.assign(math::crossproduct(((*next)->location() - (*first)->location()), ((*next)->location() - Camera::eye()))); + next_normal.assign(math::crossproduct(((*next)->location() - (*first)->location()), ((*next)->location() - camera.location()))); next_normal.normalize(); gl::color((*first)->color()); @@ -353,7 +354,7 @@ ParticleEjectorStreak::~ParticleEjectorStreak() } -void ParticleEjectorStreak::draw(const math::Vector3f & ps_location, const math::Axis & ps_axis) +void ParticleEjectorStreak::draw(const Camera &camera, const math::Vector3f & ps_location, const math::Axis & ps_axis) { if (!particles().size()) { return; @@ -377,7 +378,7 @@ void ParticleEjectorStreak::draw(const math::Vector3f & ps_location, const math: math::Vector3f first_location(attached() ? ps_location + ps_axis * (*first)->location() : (*first)->location()); math::Vector3f next_location(attached() ? ps_location + ps_axis * (*next)->location() : (*next)->location()); - normal.assign(math::crossproduct((first_location - Camera::eye()), (next_location - Camera::eye()))); + normal.assign(math::crossproduct((first_location - camera.location()), (next_location - camera.location()))); normal.normalize(); gl::color((*first)->color()); -- cgit v1.2.3