Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ERROR
- =====
- libsupertux2.a(fireworks.cpp.o): In function `void __gnu_cxx::new_allocator<PhysicsParticles>::construct<PhysicsParticles, Vector&, int, int, int, int, int, Color, int, float, int, float, float, float, float, float, bool>(PhysicsParticles*, Vector&, int&&, int&&, int&&, int&&, int&&, Color&&, int&&, float&&, int&&, float&&, float&&, float&&, float&&, float&&, bool&&)':
- fireworks.cpp:(.text._ZN9__gnu_cxx13new_allocatorI16PhysicsParticlesE9constructIS1_JR6Vectoriiiii5ColorififffffbEEEvPT_DpOT0_[_ZN9__gnu_cxx13new_allocatorI16PhysicsParticlesE9constructIS1_JR6Vectoriiiii5ColorififffffbEEEvPT_DpOT0_]+0x301): undefined reference to `PhysicsParticles::PhysicsParticles(Vector const&, int, int, float, float, int, Color, int, float, int, float, float, float, float, float, bool)'
- collect2: error: ld returned 1 exit status
- CMakeFiles/supertux2.dir/build.make:112: recipe for target 'supertux2' failed
- make[2]: *** [supertux2] Error 1
- CMakeFiles/Makefile2:68: recipe for target 'CMakeFiles/supertux2.dir/all' failed
- make[1]: *** [CMakeFiles/supertux2.dir/all] Error 2
- Makefile:151: recipe for target 'all' failed
- make: *** [all] Error 2
- =====================
- physics_particles.hpp
- =====================
- #ifndef HEADER_SUPERTUX_OBJECT_PHYSICS_PARTICLES_HPP
- #define HEADER_SUPERTUX_OBJECT_PHYSICS_PARTICLES_HPP
- #include "object/particles.hpp"
- class PhysicsParticles : public Particles
- {
- private:
- struct Particle
- {
- Vector pos, vel;
- Particle() :
- pos(),
- vel()
- {
- }
- };
- float m_gravity = -9.8f; // adjust as needed
- public:
- PhysicsParticles(const Vector& epicenter, int min_angle, int max_angle,
- const float min_initial_velocity, const float max_initial_velocity,
- int number, Color color,
- int size, float life_time, int drawing_layer,
- float a, float b, float c, float sin_coeff, float cos_coeff,
- bool use_gravity);
- virtual bool is_saveable() const {
- return false;
- }
- virtual void update(float elapsed_time);
- virtual void draw(DrawingContext& context);
- Color m_color;
- Timer m_timer;
- bool m_live_forever;
- float m_size;
- int m_drawing_layer;
- std::vector<std::unique_ptr<Particle>> m_particles;
- float m_a;
- float m_b;
- float m_c;
- float m_sin_coeff;
- float m_cos_coeff;
- bool m_use_gravity;
- };
- #endif
- /* EOF */
- ==============
- physics_particles.cpp
- =====================
- #include "object/physics_particles.hpp"
- #include <math.h>
- #include "math/random_generator.hpp"
- #include "math/util.hpp"
- #include "object/camera.hpp"
- #include "supertux/sector.hpp"
- #include "video/drawing_context.hpp"
- #include "video/video_system.hpp"
- #include "video/viewport.hpp"
- PhysicsParticles::PhysicsParticles(const Vector& epicenter, int min_angle, int max_angle,
- const float min_initial_velocity, const float max_initial_velocity,
- int number, Color color,
- int size, float life_time, int drawing_layer,
- float a, float b, float c, float sin_coeff, float cos_coeff,
- bool use_gravity);
- m_timer(),
- m_live_forever(),
- m_color(color_),
- m_size(static_cast<float>(size_)),
- m_drawing_layer(drawing_layer),
- m_a(a),
- m_b(b),
- m_c(c),
- m_sin_coeff(sin_coeff),
- m_cos_coeff(cos_coeff),
- m_use_gravity(use_gravity),
- particles()
- {
- if(life_time == 0)
- {
- m_live_forever = true;
- }
- else
- {
- m_live_forever = false;
- timer.start(life_time);
- }
- // create particles
- for(int i = 0; i < number; i++)
- {
- Particle particle = std::unique_ptr<Particle>(new Particle);
- particle->pos = epicenter;
- float velocity = (min_initial_velocity == max_initial_velocity) ? min_initial_velocity :
- graphicsRandom.randf(min_initial_velocity, max_initial_velocity);
- float angle = (min_angle == max_angle) ? static_cast<float>(min_angle) * (math::PI / 180.0f) :
- graphicsRandom.randf(static_cast<float>(min_angle), static_cast<float>(max_angle)) * (math::PI / 180.0f); // convert to radians
- // vel.x = a * x^3 + b * x^2 + cx + m_sin_coeff(sin(x)) + m_cos_coeff(cos(x))
- particle->vel.x = (sinf(angle)) * velocity;
- particle->vel.y = (-cosf(angle)) * velocity;
- particles.push_back(std::move(particle));
- }
- }
- void
- ParticlesParticles::update(float dt)
- {
- // first pass will update particle velocities
- for(int i = 0; i < m_particles.size(); i++)
- {
- m_particles[i]->vel.x += m_a * powf(dt, 3.0f) + m_b * powf(dt, 2.0f) + m_c * dt +
- m_sin_coeff * sin(particle->pos.x) + m_cos_coeff * cos(particle->pos.x);
- m_particles[i]->vel.y += m_a * powf(dt, 3.0f) + m_b * powf(dt, 2.0f) + m_c * dt +
- m_sin_coeff * sin(particle->pos.y) + m_cos_coeff * cos(particle->pos.y);
- if(m_use_gravity)
- {
- m_particles[i]->vel.y += m_gravity * powf(dt, 2.0f);
- }
- }
- // now we can update positions based on velocity
- for(int i = 0; i < m_particles.size(); i++)
- {
- m_particles[i]->pos.x += m_particles[i]->vel.x * dt;
- m_particles[i]->pos.y += m_particles[i]->vel.y * dt;
- if(m_particles[i]->pos.x < camera.x || m_particles[i]->pos.x > static_cast<float>(SCREEN_WIDTH) + camera.x ||
- m_particles[i]->pos.y < camera.y || m_particles[i]->pos.y > static_cast<float>(SCREEN_HEIGHT) + camera.y)
- {
- m_particles.erase(i);
- }
- }
- /*
- Vector camera = Sector::current()->camera->get_translation();
- // update particles
- for(auto i = particles.begin(); i != particles.end(); ) {
- (*i)->pos.x += (*i)->vel.x * dt;
- (*i)->pos.y += (*i)->vel.y * dt;
- (*i)->vel.x += accel.x * dt;
- (*i)->vel.y += accel.y * dt;
- if((*i)->pos.x < camera.x || (*i)->pos.x > static_cast<float>(SCREEN_WIDTH) + camera.x ||
- (*i)->pos.y < camera.y || (*i)->pos.y > static_cast<float>(SCREEN_HEIGHT) + camera.y) {
- i = particles.erase(i);
- } else {
- ++i;
- }
- }
- if((timer.check() && !live_forever) || particles.size() == 0)
- remove_me(); */
- }
- ===========================
- fireworks.cpp modifications
- ===========================
- /*sector->add_object(std::make_shared<Particles>(pos, 0, 360, 140, 140,
- Vector(0, 0), 45, Color(red, green, 0), 3, 1.3f,
- LAYER_FOREGROUND1+1));*/
- sector->add_object(std::make_shared<PhysicsParticles>(pos, 0, 360, 140, 140,
- 45, Color(red, green, 0), 3, 1.3f,
- LAYER_FOREGROUND1+1,
- .01f, .02f, .03f, 0.0f, 0.0f, true));
- ===========================
- ERROR (repeated from above)
- ===========================
- libsupertux2.a(fireworks.cpp.o): In function `void __gnu_cxx::new_allocator<PhysicsParticles>::construct<PhysicsParticles, Vector&, int, int, int, int, int, Color, int, float, int, float, float, float, float, float, bool>(PhysicsParticles*, Vector&, int&&, int&&, int&&, int&&, int&&, Color&&, int&&, float&&, int&&, float&&, float&&, float&&, float&&, float&&, bool&&)':
- fireworks.cpp:(.text._ZN9__gnu_cxx13new_allocatorI16PhysicsParticlesE9constructIS1_JR6Vectoriiiii5ColorififffffbEEEvPT_DpOT0_[_ZN9__gnu_cxx13new_allocatorI16PhysicsParticlesE9constructIS1_JR6Vectoriiiii5ColorififffffbEEEvPT_DpOT0_]+0x301): undefined reference to `PhysicsParticles::PhysicsParticles(Vector const&, int, int, float, float, int, Color, int, float, int, float, float, float, float, float, bool)'
- collect2: error: ld returned 1 exit status
- CMakeFiles/supertux2.dir/build.make:112: recipe for target 'supertux2' failed
- make[2]: *** [supertux2] Error 1
- CMakeFiles/Makefile2:68: recipe for target 'CMakeFiles/supertux2.dir/all' failed
- make[1]: *** [CMakeFiles/supertux2.dir/all] Error 2
- Makefile:151: recipe for target 'all' failed
- make: *** [all] Error 2
- -----------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement