Jump to content

  • Log In with Google      Sign In   
  • Create Account


Matrices


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 MarsTeam   Members   -  Reputation: 122

Like
0Likes
Like

Posted 08 February 2011 - 08:43 AM

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!

Sponsor:

#2 GothSeiDank   Members   -  Reputation: 156

Like
2Likes
Like

Posted 08 February 2011 - 08:56 AM

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
If you say "pls", because it is shorter than "please", I will say "no", because it is shorter than "yes"
http://nightlight2d.de/

#3 MarsTeam   Members   -  Reputation: 122

Like
0Likes
Like

Posted 08 February 2011 - 09:17 AM

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



#4 V-man   Members   -  Reputation: 797

Like
1Likes
Like

Posted 08 February 2011 - 11:57 AM

There is also my library. See my signature.
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);
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

#5 scgames   Members   -  Reputation: 1961

Like
0Likes
Like

Posted 08 February 2011 - 02:58 PM

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.

#6 mhagain   Crossbones+   -  Reputation: 6354

Like
0Likes
Like

Posted 08 February 2011 - 04:14 PM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#7 dpadam450   Members   -  Reputation: 807

Like
0Likes
Like

Posted 08 February 2011 - 11:27 PM

Bout to rip your code V-Man since I'm lazy, really just going to steal the GL matrix emulation.

#8 dpadam450   Members   -  Reputation: 807

Like
0Likes
Like

Posted 08 February 2011 - 11:36 PM

Actually nevermind, I thought it would implement its own stack rather than having to pass in a pointer for a matrix each time.

#9 V-man   Members   -  Reputation: 797

Like
0Likes
Like

Posted 09 February 2011 - 03:11 PM


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.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

#10 dpadam450   Members   -  Reputation: 807

Like
0Likes
Like

Posted 09 February 2011 - 03:44 PM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS