For a physics engine I am working on, I need to know two object's friction coefficient (for bouncing, collision detection, friction in general etc.). Since this physics engine will have lots of different materials, it would be inefficient to have a list of every pair of materials, with their friction coefficient. So, I would like to know if there is any value I can assign to each material, which would mean I could work out the friction coefficient between the two objects, using the two material's values.
Answer
There are no simple "mixing" rules for defining pretty much any aspect of the physics of composite materials. Materials science is not that simple: chemical bonding of the same elements is radically different in different combinations.
I think adding a new object to running code through the Factory Pattern for each and every new material you need is a pretty standard method in all kinds of simulation software from EM materials to optical glasses to mechanical properties of materials, whether it be a numerical analysis or design software, whether commercial or research grade. See:
Gamma, Helm, Johnson and Vlissedes,"Design Patterns: Elements of Reusable Object-Oriented Software"
and read about the Factory Pattern - you REALLY need to see this before attempting building code like what you thinking of. Once you have built your "factory" in software, you then either link in prototype objects for the factory from a DLL or other library or encode and read them from, say, an XML file at startup. There are sample codes in the book, and the factory classes are a page of code at the most.
No comments:
Post a Comment