Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Translation 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.

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

#1 SM ForeveR   Members   -  Reputation: 138

Like
0Likes
Like

Posted 06 February 2012 - 02:26 AM

Hi, I am developing on android and I have encountered one problem. In opengl documentation it says, that matrices are in column-major order and translation matrix looks like this:
1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1
But in my program I use method like this:
public static final float[] translation(float x, float y, float z) {

  // 4x4 translation matrix.

  return new float[] {

	1.0f, 0.0f, 0.0f, 0.0f,

	0.0f, 1.0f, 0.0f, 0.0f,

	0.0f, 0.0f, 1.0f, 0.0f,

	x, y, z, 1.0f,

  };

}

And it works until I try to change x, y, z position to last column.
Does this have to do with the fact that I use 1D array and not 2D? Does each row in this array represents a column when passed to opengl methods?

Thank you,
Martin

Sponsor:

#2 V-man   Members   -  Reputation: 805

Like
0Likes
Like

Posted 06 February 2012 - 03:39 AM

yes
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);

#3 mhagain   Crossbones+   -  Reputation: 8275

Like
0Likes
Like

Posted 06 February 2012 - 04:51 AM

You can use row major in your own code if you want - absolutely nothing to stop you. What's important is that you're consistent (otherwise you'll risk confusing yourself) and that you transpose the matrix to column-major before sending it to OpenGL. Yes, that's a few extra operation, but it's something you should be doing relatively few times per frame, so any performance impact will be down in the noise.

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.





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