I’m creating a minimal circle-circle physics engine in a static library, and I’ve came across a problem. I have a header file for object manipulation, one of the variables is the objects position. The position variable is declared in bpObject.h, and I have a void function, SetPosition(), that accesses the current position and sets its to the parameters specified (also declared in bpObject.h). My problem is that in the source file, I need to access the position variable (private). I can’t access it through the bpObject class, because, being a class, it won’t have the correct value when it is used as a type. So, how would I access the position variable within the class?
Thanks in advance,
Greg Treleaven
EDIT
Code for bpObject.h
#include "bpMath.h"
namespace bp
{
class Object
{
private:
static bp::Vector position;
static bp::Vector velocity;
static bp::Vector acceleration;
public:
static single restitution;
static single radius;
static void setPosition(single X, single Y);
static bp::Vector getPosition();
static void applyPosition(single X, single Y);
static void setVelocity(single X, single Y);
static bp::Vector getVelocity();
static void applyVelocity(single X, single Y);
static void setAcceleration(single X, single Y);
static bp::Vector getAcceleration();
static void applyAcceleration(single X, single Y);
}
}
I’m guessing you don’t actually want all those ‘static’s in there, is your first problem (as it stands, you pretty much can only access a single object)
Once you get rid of those, you can implement SetPosition in your source file by:
Yes, position is private, but when you actually define the method, you get to access the members. Is this at all what you are asking?