From matrix to Point

So here’s the problem…

I’m going through an optimization phase and now it comes to mathematic (and god know i totally su*k at mathematics… :frowning: )

I load 3Dds models using the great lib3ds (lib3ds download |
and i try to adapt their great 3ds player on my cellphone.

right now, i load all the vertices in one big array and i use one gldrawarrays(); to draw the stuff and it works pretty well.

But, since 3ds modellers are lazy (eh did you say developers ?)
they develop their models part by part and then rotate + translate them in order to fit in the rest of the model.

Then it leads to the following situation.

(the original 3ds player)

getting the mesh matrix, (4x4 matrix), getting the vertexes, drawing -> OK.

(my player)

not getting the mesh matrix, getting the vertexes, drawing -> OMG, everything’s screwed ! -> NOT OK.

so in my code i have the following lines :

for (j = 0; j < 3; ++j)
		if (_tex_vertices)
			_tex_vertices[(int)(*count / 1.5) + j * 2] = mesh->texelL[f->points[j]][0] * self._scalex;
			_tex_vertices[(int)(*count / 1.5) + j * 2 + 1] = self._scaley - mesh->texelL[f->points[j]][1] * self._scaley;
		for (i = 0; i < 3; ++i)
			_vertices[*count + j * 3 + i] = mesh->pointL[f->points[j]].pos[i];
	*count += 9;

The thing is that i’m looking for a way to muliply each vertices by the 4x4 matrix of each mesh in order to avoid calling each time glmultmatrixf();

See what i mean ? (i would understand if not ^^)

So i googled openGL matrix on the net and i found that

The rotation matrix is a little bit more advanced, you will infact need 3 matrices for 3 dimensions.
One for the X-Axis, one for the Y-Axis and one for the Z-Axis, like this:

X - Axis:
|1 0 0 0|
|0 cos sin 0|
|0 -sin cos 0|
|0 0 0 1|

Y - Axis:
|cos 0 -sin 0|
|0 1 0 0|
|sin 0 cos 0|
|0 0 0 1|

Z - Axis:
|cos sin 0 0|
|-sin cos 0 0|
|0 0 1 0|
|0 0 0 1|

Note! Above I’m talking about rotating in radians not degrees!

I think i need to rotate (or translate ?) each vertices in order to render them correctly, but i just can’t seem the right way to find how to translate a full matrix rotation into a single point…

Thanks in advance for the post, and sorry for the long post ^^’

Ok. Why? Performance? That’s the best I can come up with.

I think i need to rotate (or translate ?) each vertices in order to render them correctly, but i just can’t seem the right way to find how to translate a full matrix rotation into a single point…

I have no idea what this means. Explaining what “the original 3DS player” and “my player” are might help.

It sounds like 3DS is providing transform info in a form other than a 4x4 transform matrix, and you’re having trouble cooking the 4x4 transform matrix … (??) Don’t know if I’m even close.

What specifically is the problem you’re having?

A screenshot will be clearer sorry :stuck_out_tongue:

Yup performance !
On the left, the original player (glut + opengl)

On the right, my player (openGLES) where everything’s upside down

The ‘original’ player is a 3dsfile player given by lib3ds with the source code.

in the code i posted, there is a line

_vertices[*count + j * 3 + i] = mesh->pointL[f->points[j]].pos[i];

I’d like to transform this point, into another point using a 4x4 matrix taken from the file, and this in order to prevent calling glmultmatrixf();

I mean, i don’t know how to transform a point into another point with a 4x4 matrix, and how goes the math behind that.

Sorry for the bad explanation :s

Just google vector by matrix transformation (multiplication) and transform the vertices on the CPU (it is really very simple).

you mean that i take the vertices and transform them with the matrix ??

anyways thanks for the hint =)


I think that i can use the rotation formula on the vertices and not each point, looks like it’s becoming clearer in my mind !


Ok here’s the real deal !

I have a 4x4 matrix, let’s say this one

1 0 0 0
0 0 -1 0
0 1 0 0
24 11 0 1

And i have this vertice

x = 1
y = 2
z = 3

In order to simulate the glmultmatrixf();
I have to transform the vertice in a matrix in something like that

x 0 0 0
0 y 0 0
0 0 z 0
0 0 0 0

And then multiply the two matrixes to get

x1 0 0 0
0 y1 0 0
0 0 z1 0
0 0 0 0


x = x1
y = y1
z = z1

Am i correct ???(at least in reasonment, i’m probably sure my multiplication is bad)

I’m going nuts !!!


You don’t build matrices out of vertices. You just do a simple vector matrix multiplication (google this if you need more explanations).
And since you need a vector with 4 components to multiply it with a 4x4 matrix your vertex becomes (x,y,z,w) = (1,2,3,1). Your w coordinate is always 1.

And here you have a nice and beautiful explanation :slight_smile: