# Math feature requests

Posted Saturday, 13 March, 2010 - 13:54 by texel inHi,

i have tried to port JigLibX to OpenTK.

I think i will not continue because i do not have the time and knowledge to do it quickly.

But here are some problems i had when i tried to port JigLibX to OpenTK:

Some math functions, are not implemented in OpenTK:

MathHelper.Clamp

MathHelper.Min

MathHelper.Max

MathHelper.ToRadians

Matrix4:

"+=" operator

and Matrix4.Add methode

Matrix4.Right;

Matrix4.Up;

Matrix4.Backward;

... and others

Vector3:

Constructor with one argument: float assigned to the 3 components

Vector3.Right;

Vector3.Up;

Vector3.Backward;

... and others

This classes are not present:

BoundingBox

BoundingSphere

Plane

There are also a lot of functions which are differents between XNA math and OpenTK (some times it is just a "ref" which is not present). Maybe it would have been great to have the same conventions and math function in OpenTK and XNA, to ease the port of all libraries which can be found on the web (because XNA will always be more used than OpenTK). But it's probably too late.

I hope it can help.

## Comments

## Re: Math feature requests

Many of these methods and classes are already a work-in-progress for OpenTK 1.1. Indeed, the idea is to bring the math API as close to XNA as possible but there's a lot of other stuff that requires attention and progress is rather slow. Any help appreciated!

Two suggestions:

## Re: Math feature requests

Does it mean that you will break compatibility between the current version of OpenTK and the next ?

A lot of things have to be modified.

## Re: Math feature requests

Actually, most of the work involves missing classes/methods. My working copy of the OpenTK demo contains much of this work while using a vanilla OpenTK.dll - which means the changes are purely additive.

The plan is to maintain backwards compatibility throughout the 1.x series, starting with the 1.0 betas. If this means we'll have to settle for 95% compatibility with XNA math in the end, so be it (95% is still better than what we have now).

## Re: Math feature requests

ok.

If i find the time, maybe i will try to write some code.

## Re: Math feature requests

I have modified OpenTK and JigLibX so they work together. On the OpenTK side it just needed some additions to the Math classes. The only thing that needed to be modified are the Vector3.Min and Vector3.Max functions as they do different things in XNA.

Maybe it would be good to merge the changes to OpenTK. Its quick&dirty right now but it shouldnt break anything that isnt using Vector3.Min/Max.(but i think they should be changed anyway, they behave really strange in OpenTK)

I only tested box collisions which work ok, see a video here:

http://www.youtube.com/watch?v=3pCRXFXeFN4

## Re: Math feature requests

That Min/Max are indeed interesting implementations in OpenTK, though quite logic they are different from XNA and afaik the goal of OpenTK's math library was to have a similar interface as XNA (component-wise Min/Max if I understand the docs correctly??).

## Re: Math feature requests

Take a look into Mono.GameMath, which is a proper, XNA-compatible, SIMD-accelerated and unit-tested math library. I will probably switch OpenTK to that once it matures (keeping the old library in a separate assembly for backwards compatibility).

## Re: Math feature requests

I just gonna open a new topic and then I saw this one.

OpenTK have a method to convert Quaternion to Matrix4, but not opposite.

I have a method for Matrix4->Quaternion that I would like that OpenTK implicit it.

Here it is(see notes):

As said in the code, I took it from: http://www.euclideanspace.com/maths/geometry/rotations/conversions/matri...

And I think that OpenTK should have that method too in Matrix:

Donno if you have already implicit those method in branch/trunk, but I hope that it will help OpenTK!

## Re: Math feature requests

I finished porting JigLibX to OpenTK 1.0. No changes to OpenTK are required anymore.

Get it here:

https://sourceforge.net/projects/jiglibopentk/