My question is fairly simple, though I'm not experienced enough to really answer this one.
Let's say I'm designing a game, or a simulation of real world physics. I have my physics functions that I've wrote, regarding acceleration, velocity, momentum, force, power, energy, and etc.
Let's say I have an object class for an object in my simulation to be placed under the constraints of these physical equations. Do I design my object class to track it's own physical attributes? Or do I design a driver to run an objects physical attributes? Things like mass, physical dimensions, and other object specific things need to be associated with the object class only I'm sure. But what about when that object is at a velocity, or under acceleration, or impacting with something? Would it function better with the class tracking these attributes as well?
My guess is going to be no. Because we may change the physical world that these objects interact with. An example would be that there is air resistance here on Earth, but in space, there isn't. Also, the acceleration due to gravity decreases the further out in space we go away from massive objects. So gravity will become negligible if we change the simulation constraints.
So my next question. In my design is it better to have an environment class? For which we have the local air resistance factor, wind speed, and etc. Or would it be better to have this in a driver set up? Another thing I want to mention about this is: What if my simulation involved launching an object from ground, and going into orbit, or even further? Here the environment itself acting on the object changes.
This may be a little complex for the initial stages of creation and design, but I don't want to get far into building something, to realize it's flawed on the basic of levels.
I suppose a solution to the environmental problem above could be another object class, for which the object is a planet for instance, with a coordinate system. There the air resistance can be a ratio of elevation I suppose. I just like things to be accurate.
Any comments, suggestions, ideas are welcome. I'm a student and I'm trying to stretch my legs a bit in learning how to fully manipulate ideas in programming. This is something I think is learned with experience, but sadly, the time a modern (non-traditional, married, father) student has for piddling around with the language before receiving the degree... is very limited.
I've always had objects control their own attributes, although this is only because that's what I have been taught at university. My 'World' class usually contains an std::vector of entities such as ships, projectiles etc. Each of these entities derives from a base class so that every single entity can be stored in the same vector in the World class. So you might have "std::vector<Entity*>" in your world class, Entity being the base class from which all entities derive, and it is also essential that you store pointers to entities so that when looping through this vector each entity can run it's own update and draw functions for example. This simplifies things quite a lot since you only have one list of items to loop through and as long as their update functions have the same function prototype, derived from the base, due to the miracle of polymorphism, each entity will call it's own update functions and not the one in the base class.
I hope you're doing this in c++ because I've just realised I made the assumption that you are =P
Good luck.
You are thinking about this problem properly. Ultimately only you can answer these questions. Different types of simulation will lend themselves to different approaches depending on the requirements.
One thing I thought about as I was reading your thoughts is allowing your object class to contain objects. So each object would provide the environment and control for the objects it contains.
Then if you put an object into a building, it will not suffer from the wind that objects are subject to outside.
So for the task of simulating the solar system it might be sufficient for the sun to be an object that contains all the planets. Each planet could contain their moons. And there could be a universe object containing the sun and providing the stellar sphere.
With respect to what attributes the objects should contain. I would tend to think that the objects should record all their physical attributes within themselves like position, velocity, acceleration, temperature etc...everything that has unique value to each object The surrounding environment factors that are the same for a whole group of objects could then be held in the environment object. Those factors would lead different objects to behave differently.
For example a given temperature in the environment will raise the temperature of different objects at different rates. So the environment 'applies' temperature to each object and each object raises its own temperature accordingly.
Awesome answers everyone, I like the thought process on all of this.
@Galik
You have a really good point at which I am beginning to realize, this is a broad set of possibility and is going to depend on what it is specifically I'm doing at the time. I can see where it would be beneficial to have the object track itself in some instances. I can also see where it would be more beneficial to have the environment track the object in others.
I was hoping to keep my own library of items I could draw from later on. It may be better for me to do both, and store them as such. Thanks for the input all!