Hello, I am curious whether do you prefer do prefer to write your own Matrix/Vector class, with all stuff that's needed (multiply, add, inverse, rotate, scale etc...) or if you prefer to use some already-done-matrices/vectors(if they are available). So far I had written my own class and methods, but I would like to know whether there is already solution to this, so I don't have to reinvent wheel every time.
My language is C++
Thanks!
Matrices
Use glm. This library is writte against the GLSL Spec and you can send them to your shaders directly.
Also nifty things from GLSL like vec3 m = vec3(vec2(1.0f, 2.0f), 1.0f); work.
It has also replacement functions for deprecated glOrtho and glTranslate etc.
Here a short usage sample:
And it is a header only library, so no need to compile it.
http://www.g-truc.ne...-0016.html#menu
HTH
Also nifty things from GLSL like vec3 m = vec3(vec2(1.0f, 2.0f), 1.0f); work.
It has also replacement functions for deprecated glOrtho and glTranslate etc.
Here a short usage sample:
// Send Projection Matrix
glm::mat4 projMatrix = glm::mat4(1);
projMatrix = glm::ortho<float>(0.0f, w, h, 0, -1.0f, 1.0f);
glUniformMatrix4fv(m_perspective_id, 1, false, glm::value_ptr(projMatrix));
And it is a header only library, so no need to compile it.
http://www.g-truc.ne...-0016.html#menu
HTH
Thanks! Really helpful stuff
Use glm. This library is writte against the GLSL Spec and you can send them to your shaders directly.
Also nifty things from GLSL like vec3 m = vec3(vec2(1.0f, 2.0f), 1.0f); work.
It has also replacement functions for deprecated glOrtho and glTranslate etc.
Here a short usage sample:
// Send Projection Matrix
glm::mat4 projMatrix = glm::mat4(1);
projMatrix = glm::ortho<float>(0.0f, w, h, 0, -1.0f, 1.0f);
glUniformMatrix4fv(m_perspective_id, 1, false, glm::value_ptr(projMatrix));
And it is a header only library, so no need to compile it.
http://www.g-truc.ne...-0016.html#menu
HTH
There is also my library. See my signature.
The code would look something like
and mymatrix is ready. You send it to GL
glUniformMatrix4fv(m_perspective_id, 1, FALSE, mymatrix);
The code would look something like
float mymatrix[16];
glhLoadIdentityf2(mymatrix);
glhTranslatef2(mymatrix, 0.0, 5.0, 6.0);
glhScalef2(mymatrix, 1.0, 1.0, 2.0);
glhPerspectivef2(mymatrix, 45.0, aspectRatio, 0.1, 1000.0);
and mymatrix is ready. You send it to GL
glUniformMatrix4fv(m_perspective_id, 1, FALSE, mymatrix);
I would use an existing library unless you have a particular interest in implementing one yourself.
You've already got some good suggestions, but if you're interested in more options, you can find a list of math libraries here.
You've already got some good suggestions, but if you're interested in more options, you can find a list of math libraries here.
I use my own based on the D3D matrix functions for the sole reason that it's what I'm used to and it helps with porting code from one API to the other. Otherwise I'd say definitely use an existing library.
Bout to rip your code V-Man since I'm lazy, really just going to steal the GL matrix emulation.
Actually nevermind, I thought it would implement its own stack rather than having to pass in a pointer for a matrix each time.
dpadam450,
It doesn't do a stack although I had that at one point, I removed it. Your own classes should store the matrix for your objects.
Yea, but I still wanted the stack based idea with a single stack so I'm just setting the object matrix at the end which winds the stack down and gives me the object matrix, either by passing in there, or returning a matrix.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement