I'm trying to program a really simple rigid body physics simulation (using c++ and OpenGL) for learning purposes (also please excuse me in advance but English is not my first language).
Now, so far my classes are structured like this:
Agent class:
Obstacle class:
Simulation class:
Renderer class:
Now everything works but I'm having problems on how to structure my program further to implement the following features:
Stuff like vertex, textures and which shader to use is currently hard-coded in the renderer. I'd like to being able to change those on a per Agent object basis but I recognize that those variables have no place in neither the Agent class nor the Simulation class. Where should I keep track of those?
I'd like to add some debug / visualization stuff in the program. For example, given a selected agent, the program will plot a dot after a certain amount of distance traveled (eg: 1 dot every 2 unity traveled) so I can have kind of a trail to visualize where the agent went. What class would be responsable of:
Sorry for the long-winded post but I've been trying to solve those problems for two weeks now but nothing good spring to mind.
I know I could probably mitigate those problems using an Entity Component Systems architecture but I really prefer to keep it as simple as possible.
Entity / Component architectures are what you need I guess.There is a lot of stuff about this over the internet and I encourage you to google it and look for it on stack overflow and gamedev stackexchange.
An example of this (not the only one and maybe not good for you, but it's an example) could be something like
struct Entity
{
int m_Id;
};
struct PhysicsComponent {
unsigned long m_Flags;
// Some data
};
struct GraphicsComponent {
Texture m_Texture;
Mesh m_Mesh;
// Some other data
};
Actor actors[MAX_ACTORS];
Wall walls[MAX_WALLS];
GraphicsComponent graphics_components[MAX_GRAPHICS_COMPONENTS];
void UpdatePhysics(float dt) {
// Do you logic stuff, using your flags and so on
}
void Render() {
// Render your stuff by retrieving position / orientation via entities ID
}