Archived

This topic is now archived and is closed to further replies.

Error in design?

This topic is 5536 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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 ]

Share this post


Link to post
Share on other sites
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.''

Share this post


Link to post
Share on other sites
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)...

Share this post


Link to post
Share on other sites