1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- /*
- * 2D Physic Engine
- * particle.h:
- * Based on pikuma.com Learn Game Physics Engine Programming course.
- * Copyright (c) 2022 986-Studio. All rights reserved.
- *
- * Created by Manoël Trapier on 07/06/2022.
- */
- #ifndef PHYSICENGINE_PHYSICS_PARTICLE_H
- #define PHYSICENGINE_PHYSICS_PARTICLE_H
- #include <physics/vec2.h>
- class particle
- {
- public:
- uint16_t radius;
- vec2 position;
- vec2 acceleration;
- vec2 velocity;
- vec2 sum_of_forces;
- double mass;
- double invMass;
- public:
- particle(double x, double y, double mass, double radius = 4.0): radius(radius), position(x, y),
- mass(mass)
- {
- this->invMass = 0;
- if (mass != 0.0)
- {
- this->invMass = 1 / mass;
- }
- };
- ~particle() = default;
- void clearForces()
- {
- this->sum_of_forces = vec2(0, 0);
- }
- void addForce(const vec2 &force);
- void integrate(double dt);
- };
- #endif /* PHYSICENGINE_PHYSICS_PARTICLE_H */
|