Error in design?

Started by
2 comments, last by _DarkWIng_ 21 years, 5 months ago
I've come to a wierd problem in my engine design. Part of my hiearchy so far was this. class Scene -list of Entitys -list of Lights -list of Cameras class Entity -pointer to Object -transformation matrix class Object -pointer to Mesh -pointer to Shader This worked just fine. I could have one instance of mesh with different shaders (or vice versa) at diferent locations. But now I have some troubble implementing stuff like tangent space bump mapping since it requires light and eye positions in local space. Shader would have to grab transformation matrix from Entity and world space light and eye positions from Scene when I draw an object with it. But I can't access methods/members of those classes from Shader since it has to be defined first. And I also can't add pointer to those things to it since one can be used for more than one object. Any idea how to slove this? Is my design way off? You should never let your fears become the boundaries of your dreams. [edited by - _DarkWIng_ on October 22, 2002 4:44:55 AM]
You should never let your fears become the boundaries of your dreams.
Advertisement
Placing forward declarations in headers and function bodies (where the classes are actually used) in source files, with all appropriate headers included usually takes care of dependencies.

If not, the pImpl idiom (google) may help.


Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
This seems to be a problem with the class structure, not the file structure. Couldn''t you just pass a pointer to the mesh/entity into the shader? If you are refering to which is defined first in the file - just use ''class Entity'' instead of just ''Entity''. ''class'' will tell the compiler ''Don''t worry about it, you''ll find it when you link.''
Probably you should have the Scene class calculate local light and eye positions and keep them updated for each Entity.

That way, you can avoid cyclic dependencies which are A Bad Thing (TM)...

This topic is closed to new replies.

Advertisement