PDA

View Full Version : local/global coordinate system problem



Dalhia
01-27-2001, 01:07 PM
When I translate and rotate to a local coordinate system, how do i find the local coordinates of a point in global coordinates. In other words, I know the global coordinates for a vertex, then I move to a local coordinate system, how would I find the coordinates of the vertex with respect to the new local coordinate system?

chennes
01-27-2001, 01:18 PM
Get the matrix that does the translations and multiply your vertex by it.

Chris

Dalhia
01-27-2001, 01:41 PM
so, you mean use



glGetFloatv(GL_MODELVIEW_MATRIX,Minv);

to store the system into Minv and then do something like this?:



void VMatMult(GLmatrix16f M, GLvector4f v)
{
GLfloat res[4];
res[0]=M[ 0]*v[0]+M[ 4]*v[1]+M[ 8]*v[2]+M[12]*v[3];
res[1]=M[ 1]*v[0]+M[ 5]*v[1]+M[ 9]*v[2]+M[13]*v[3];
res[2]=M[ 2]*v[0]+M[ 6]*v[1]+M[10]*v[2]+M[14]*v[3];
res[3]=M[ 3]*v[0]+M[ 7]*v[1]+M[11]*v[2]+M[15]*v[3];
v[0]=res[0];
v[1]=res[1];
v[2]=res[2];
v[3]=res[3];
}

chennes
01-27-2001, 02:33 PM
I think that's right - I'm never quite sure what order GL's matrices are in but I think you've got it.

Chris

Elixer
01-27-2001, 11:15 PM
Look at the other topic on matrix, I think we cover it pretty well now, it is over 70 replies now. http://www.opengl.org/discussion_boards/ubb/smile.gif

chennes
01-29-2001, 05:28 AM
I stopped following when it hit 50 http://www.opengl.org/discussion_boards/ubb/smile.gif

Chris