Jump to content
  • Advertisement
Sign in to follow this  
vicviper

generic math library

This topic is 4888 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 been using some heavily math driven APIS for some time... DirectX, OpenGL, several 3D engines, phisics engines, MAXSDK .... and there's something that always bugged me... all of them use their own math libs, regardless that they use the same matrix multiplication at the end... I mean, apart from extreme optimizations done in SSE assembly, a matrix multiplication is the same in a phisics engine, in OpenGL or any other math driven API... so, why do all of them have their own math lib? My question here is... is there any generic, reliable math lib we all should start begin using in order to make more compatible modules? I'm asking for something like STL:Port , but with maths in mind... you know, vectors, matrices, quaternions, etc If this doesn't exist, is there something in the works that we should check from time to time?

Share this post


Link to post
Share on other sites
Advertisement
Try Blitz++:

http://sal.jyu.fi/B/0/BLITZ++.html
But it requires a newer compler to run, that allows template members. Doesn't work on Visual C++6.0, but runs good on MingW Gcc 3.x.

A listing of available libraries can be found here:
http://www.oonumerics.org/oon/#libraries

Also, take a look for the Wild Magic library at:
http://www.geometrictools.com/
Has a lot of geometric utilities. Also, this lib can be used as a game engine.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by vicviper

I been using some heavily math driven APIS for some time... DirectX, OpenGL, several 3D engines, phisics engines, MAXSDK .... and there's something that always bugged me... all of them use their own math libs, regardless that they use the same matrix multiplication at the end... I mean, apart from extreme optimizations done in SSE assembly, a matrix multiplication is the same in a phisics engine, in OpenGL or any other math driven API... so, why do all of them have their own math lib?


Many of these API's cut corners, especialy in their matrix and quaternion math routines, meaning that there could be issues when switching between them.

At the extreme end, quaternion routines often need to keep the quats normalized.

The 'obvious' method of doing so is quite slow (7 adds, inverse sqrt, 4 muliplies) but is also accurate.

The faster methods differ in both immediate accuracy and differed accuracy. Some 'normalize' their quats by doing a single iteration of newtons method per timestep/frame, so that over time they have the accuracy of the 'obvious' method while giving a rapid approximation immediately.

Others use SSE approximated inverse sqrt's.. which are very fast but always have that same reduced accuracy.

I guess the point is that game algorithms USUALY dont need the best accuracy, but sometimes they do. Different parts of the engine have different accuracy needs hence the use of different math libraries.

Share this post


Link to post
Share on other sites
Quote:
Original post by vicviper
If this doesn't exist, is there something in the works that we should check from time to time?
I'm actually involved in a project which may be of interest to you. It's an open-source vector, matrix and quaternion library that's intended to be easy to use and provide a broad range of functionality. It's currently in development, but we are looking for beta testers, so feel free to contact me if you'd be interested.

[Edited by - jyk on December 5, 2005 12:39:38 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by jyk
The defining feature of the CML is that it can be configured to reflect your particular choice of conventions. For example, you can choose row or column vectors, row- or column-major matrices, left- or right-handed coordinate systems, standard or 'reverse' quaternion multiplication, radians or degrees, and so on.


That’s a really bad symptom right there of an ill implementation. There is not such thing as left or right hand in mathematics. Any library that could be configured to such ill idea is just a sign that the people making it have very little some practice very little theoretical background.
For the record Dx and Open GL are already compatible, there is not need to make more compatible.
Making another math Library is not going to solve that problem. Because there is way is earth project like Max, Maya, XSI, DirectX, OpenGL will adopted.

So essentially it will be another math library in the mist. It is Ok if you want a math library for your own use and you do not one to write one, but there is not hope for the STL of game Math library, that will never happens, and there is not reason for it either.



Share this post


Link to post
Share on other sites
Quote:
That’s a really bad symptom right there of an ill implementation. There is not such thing as left or right hand in mathematics. Any library that could be configured to such ill idea is just a sign that the people making it have very little some practice very little theoretical background.
You're jumping to some incorrect conclusions here, but unfortunately I don't have time to respond in full now. I do appreciate the input though, and I look forward to responding to your points in more detail later today.

Share this post


Link to post
Share on other sites
Quote:
That’s a really bad symptom right there of an ill implementation. There is not such thing as left or right hand in mathematics. Any library that could be configured to such ill idea is just a sign that the people making it have very little some practice very little theoretical background.
I think you're somewhat off base here. The LH-RH issue is just a small detail, and only affects a few matrix construction functions, such as for projection and 'lookat' matrices. It's actually similar to functionality found in the DirectX math library, so I doubt that the inclusion of this feature could be considered a design flaw.

However, your response made me aware that my original post probably didn't accurately convey my intent. So to rephrase, I'm fairly certain the library we're developing will be useful to at least a few people, and I'm hoping it will be useful to others as well. As for whether that will turn out to be the case, well, we'll see :) But, I have edited my original post to be more reflective of my intent.

Thanks again for your reply.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Umm you say I am out of base, I think not. However I give you the benefic of the doubt and accept that perhaps I am ignorant of some new development on linear algebra, so I ask you to get me out of my ignorance.
If there is such a thing as some kind of small detail that will only affect some matrix construction, then could you expressed the result of such construction of a matrix in one coordinate system, and then write the same matric in the other system?

I am an Opengl user since I can remember, and in the last few years I had been forces to work with DirectX, I had to admit directX is not as bad as it has been portrayed to be.
I had never had problem with coordinate system, Opengl and DirectX work as well in a left-handed system as they do in a right-handed system.

As for your library, I have not doubt it will be used; I seriously doubt it will become the “new standard”. One thing you cannot deny is that it will be another library in the way, requiring more glue code and nasty casting from one data type to another.
I see not reason for a game math library that is not going to do anything different or better than what is already out there.

For me is a simple as this:
A game matrix is an array of 4 x 4 adjacent floats
A game vector is an array of 1 x 4 adjacent floats
A quaternion rotation is also an array of 1 x 4 adjacent floats
And there is a set of operations on then, not need for classes just the data types

This is how it is done in DirectX, OpenGL, and any other respectable application; it is only the naive programmer that decided to term theses basics arithmetic typex into classes creating solutions in search of problems.
In 99.99% of the case that this basics data type are converted into classes at best you get 60 to 80% efficiency, because of all of the hidden overhead classes have to go thought in other to keep conformance with the law of algebra. J




Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
Umm you say I am out of base, I think not. However I give you the benefic of the doubt and accept that perhaps I am ignorant of some new development on linear algebra, so I ask you to get me out of my ignorance.
I am an Opengl user since I can remember, and in the last few years I had been forces to work with DirectX, I had to admit directX is not as bad as it has been portrayed to be.
I had never had problem with coordinate system, Opengl and DirectX work as well in a left-handed system as they do in a right-handed system.

The issue is with the fact that DirectX stores its matrices differently to OpenGL. DirectX stores them as row-major and OpenGL as column-major, ie. DirectX matrices are the transpose of OpenGL matrices, and vice-versa. This means that while one is calculating V*M the other has to either calculate M*V or V*M' (with V being treated as a row or column vector as appropriate), and since the later would be pointless they choose the former.

Quote:

For me is a simple as this:
A game matrix is an array of 4 x 4 adjacent floats
A game vector is an array of 1 x 4 adjacent floats
A quaternion rotation is also an array of 1 x 4 adjacent floats
And there is a set of operations on then, not need for classes just the data types

So you rewrite the code to perform a matrix multiplication every time one is needed? If not, then what you're doing is no different to using classes.

Quote:

This is how it is done in DirectX, OpenGL, and any other respectable application; it is only the naive programmer that decided to term theses basics arithmetic typex into classes creating solutions in search of problems.

Rubbish. Using classes is just a different way of organising your code.

Quote:
In 99.99% of the case that this basics data type are converted into classes at best you get 60 to 80% efficiency, because of all of the hidden overhead classes have to go thought in other to keep conformance with the law of algebra.

Don't mean to be rude, but you really have no idea what you're talking about.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Joanusdmentia: I am not saying you should not use your classes, you are very welcome to use them all you want, in fact you can even made your new standard library and shared with the world, then there will be more choices of standards.

Matrices in DirectX and OpenGL are exactly the same in format and in memory. However even if they were different that is not reason enough for a new standard. A set of math function will have a functionality like

Multiply (vector* out, const matrix* mat, const vector* vec);
Multiply (vector* out, const vector* vec, const matrix* mat);

Check that fact out and then maybe you may reconsider who does not know more about what it is talking about. With all do respect every I think you should read a little bit more on object oriented programming to learn a bit more.
Here is a simple example

Mat A = mat B * mat C;

Is twice slower if not more than

Multiply (vector* A, const mat* A, const matrix* B);

Like I say, anyone is welcome to use his / her own library, I just want to point out that making another library will to solve anything, it will do just the opposite, because there is nothing to fix.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!