Archived

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

api independent code and a simple question

This topic is 5566 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

was wondering what the best approach is for a function such as settransform that i am setting up for api independence ( which is my reason for needing to define it ) - a) to pass in a var that specifies world/view er whatver ie. settransform( TVIEW, SOMEMATRIX ); or b) to create a seperate function ie. settransformworld( SOMEMATRIX ) to prevent having to do a switch based on what i passed in and converting to d3d/opengl specific i'm going for speed. Thx, Andy [edited by - skillfreak on September 9, 2002 4:23:07 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by AlanKemp
I would use seperate funtions for setting each matrix. Like you said the alternative is going to end up using lots of switch statements to implement.

Alan



becareful. Opengl and direct3d dont use the same axis. In fact, i suggest you have 2 copies of your matrix code. 1 left handed for direct3d and another right handed for opengl. Also note that opengl does not have a separate view and world matrix, only a combined modelview matrix.





[edited by - jwalker on September 9, 2002 9:46:25 PM]

Share this post


Link to post
Share on other sites
Lots of switch cases? you mean...like...three?

I personally go for the single method. Also please note that even if you had a lot of cases, using switch is really fast. Despite what I thought, my OOP lecturer told me that today''s compilers convert the switch statement to an indexed table (or something to the effect) which means regardless of the number of cases in your switch statement, you should get close to constant time in selecting each. I much prefer having a switch statement with a few cases, than a dozen methods which have very similar code in them.

Hope that helps

Share this post


Link to post
Share on other sites
Using 1 matrix class is possible because OpenGL and D3D takes the same memory layout. The only difference is the API generates matrice in different coordinate system.

If you use your own matrix class (or D3DX) and avoid any matrix setting calls provided in the API (like gluPerspective, glTranslate), you can use 1 matrix class fine. No switch, no double maintance.

Share this post


Link to post
Share on other sites