
Maths function inheritance from one project to an other
Posted Wednesday, 23 June, 2010 - 13:21 by iliak inHi
I'm currently making a framework using OpenTK. Everything is OK, but now, I'm facing a problem...
OpenTK uses its own maths (Matrix4, Vector3...) and my framework tries to hide most of the internal and technical parts. I want the final project to link only with my framework (see adding reference to the project). The problem is how can I "let" final project use those maths functions ? I see two solutions :
- Struct inheritance : Not allowed in C#
- Copying all OpenTK maths source to my framework. The problem is when OpenTK update maths functions, I need to update mines... More, I have to cast structs...
Do you see any better one ?


Comments
Re: Maths function inheritance from one project to an other
Hi.
Perhaps you can go the way over interface(s)?
Re: Maths function inheritance from one project to an other
Can you elaborate a little bit ?
Re: Maths function inheritance from one project to an other
Interfaces have the disadvantage that they cause boxing when accessing structures through them. For a while I thought there was no good solution to this issue, but someone posted an ingenious hack on gamedev.net recently:
You can also define implicit operators to cast your Vector2 from/to any other library you care to support (XNA, from/to OpenTK.Vector2 (and XNA, SlimDX etc).
The downside is that you'll have to reimplement any operations you wish to support (I'd suggest using extension methods for this) but at least this gives you a simple way to interoperate with different math libraries.
Re: Maths function inheritance from one project to an other
I quickly read the license of OpenTK and this is allowed that I copy some part of the source code to use them in my project. Is this right ?
If so, I can easily steal, *cough*... copy needed structs in my framework... With the hint given by The Fiddler (using implicit operators), the cast will be easy.
is it feasible ?
Re: Maths function inheritance from one project to an other
Please read the full license text. You are required to add notion of OpenTK's usage/parts of it, accompanied by the same licensing text. If in doubt ask some lawyers about the MIT/X11 licensing.
Re: Maths function inheritance from one project to an other
From what I saw, I just have to let the header of each file and it's good, right ?
Re: Maths function inheritance from one project to an other
You can do pretty much anything with it except:
1) If you're redistributing part of OpenTK source do not remove the original license from the files.
2) If you're also offering binary only packages for download, an explicit "OpenTK License.txt" would be necessary. That's what I did a couple of months ago. No lawsuits yet :)
Re: Maths function inheritance from one project to an other
Ok, thank you.
Experimenting Fiddler's suggestion...