View Full Version : Help with matrix and point coordinates

Alessandro_dup1

04-26-2005, 05:07 AM

I need some help with the following theory matter:

I have a point initially at 0,0,0

Suppose i do some translations and rotations. How do i get the new point coordinates ?

I suppose i have to get the resulting matrix with the glGetfloatv function, but which matrix values hold the xyz info ?

Thanks

MMMovania

04-26-2005, 06:14 AM

Originally posted by Alessandro:

I need some help with the following theory matter:

I have a point initially at 0,0,0

Suppose i do some translations and rotations. How do i get the new point coordinates ?

I suppose i have to get the resulting matrix with the glGetfloatv function, but which matrix values hold the xyz info ?

ThanksHello there,

All the info regarding the modelling (your points or object coordinates) and the viewing information is contained in the modelview matrix. Thanx

MMM

Alessandro_dup1

04-26-2005, 06:53 AM

can you explain a little bit more ?

CrazyButcher

04-26-2005, 07:25 AM

when you get the matrix from ogl I think it was

glGetMatrix

you get a array of 16 floats, which is a column major matrix, so your first column is 0-3, second 4-7 and so on

rotation/scale is stored in 0-11

translation is stored at 12-14

as modelview typically has no perspective stuff, 3,7,11 are 0 and 15 is 1

so matrix[12] = x, matrix[13] = y and matrix[14] = z

best you learn about matrix math and homogenous space to understand what it is done to your vertices when they are transformed with the matrix, also how those matrices were created...

Alessandro_dup1

04-26-2005, 07:39 AM

Thanks for your help. So if i translate and rotate an object as follows:

glTranslatef(0,0,-100);

glRotatef(-90,0,0,1);

The relative matrix is:

| 0 1 0 0 |

|-1 0 0 0 |

| 0 0 1 -100|

| 0 0 0 1 |

As you said, values from 0 to 11 contains the rotation, value 12,13,14 are the translation ones.

Where do i go from here if i want to get the new point coordinates ?

CrazyButcher

04-26-2005, 11:06 PM

you multiply your vector with the matrix.

vector[0] = v1[0]*mat[M00]+v1[1]*mat[M01]+v1[2]*mat[M02]+mat[M03];

vector[1] = v1[0]*mat[M10]+v1[1]*mat[M11]+v1[2]*mat[M12]+mat[M13];

vector[2] = v1[0]*mat[M20]+v1[1]*mat[M21]+v1[2]*mat[M22]+mat[M23];

the M<row><column> indices would be like M01 = 4, M21 = 6 and so on

v1 is your input vector and mat the matrix

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.