Sign in to follow this  
schupf

Design Question

Recommended Posts

Hello! I have a question about my design. I'm writing a little C++ (DirectX10) Engine and currently I am writing on the math classes (Matrix, Spline etc). I put all math classes in the namespace "math" and obviously I thought this namespace has no dependecies. But now I want to be able to render some of my math classes; for example I want to be able to render my Spline or my Line. Of course I could add a D3DX10Device* member and a method render() to all my math classes that a renderable, but this would make my pure math classes dependent from render details. I dont like this idea because actually my math classes should just be concerned about the math and not some Device/DirectX/Render Details. How could I solve this problem? Thanks!

Share this post


Link to post
Share on other sites
Introduce a helper class such as LineRenderer, which is a friend class of Math::Line. Pass the LineRenderer a Math::Line on construction. Place the rendering logic in the LineRenderer implementation, using the information it pulls out of the Math::Line to actually do the rendering.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this