Original Post
Well, I want to make my object bounce. The object has a specified elasticity to determine how much it should bounce. My problem is, I don't know how to translate it into code. My ball will change directions but continue to accelerate upwards after changing directions. Also, feel free to tell me if I am taking the completely wrong approach to this as I am almost brand new to physics. Here is the code, the physics calculations are in Physics.cpp. Physics.cpp: Physics.h:
#include "Physics.h"
#include <math.h>
object::object(int objectx, int objecty, int objectweight, int objectelasticity)
{
gravity = 1;
weight = objectweight;
force_x = 0;
force_y = 0;
force2_x = 0;
force2_y = 0;
velocity_x = 0;
velocity_y = 0;
x = objectx;
y = objecty;
force_magnitude = 0;
force_direction = 0;
elasticity = objectelasticity;
}
void object::calcphysics(int& x,int& y,bool& collision)
{
if(collision == true)
{
force2_y = elasticity * -1;
}
force_y = (gravity * weight) + force2_y;
velocity_x += force_x;
velocity_y += force_y;
x += velocity_x;
y += velocity_y;
}
class object
{
private:
int weight;
int velocity_x;
int velocity_y;
int elasticity;
public:
int gravity;
int x;
int y;
int force_x, force_y;
int force2_x, force2_y;
float force_direction;
int force_magnitude;
bool collision;
object (int, int, int, int);
void calcphysics(int& x, int& y,bool& collision);
};