#### Archived

This topic is now archived and is closed to further replies.

# Vector Coordinates

This topic is 5978 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi guys, bear with me! I''m not very good on math... And I have a big problem... I''m trying to make my own function of OPENGL gluProject and I''m passing trough hard days until now... The gluProject function, converts a object vector coordinates to screen coordinates. In OpenGL Red Book, they say I have to do this: v'' = ProjectionMatrix * ModelViewMatrix * v where v = [objectX, objectY, objectZ, 1] after this, to get the window 2d coordinates, you have to do the following (let''s say the resolution is at 640x480): winX = (640 * v(objectX) + 1) / 2 winY = (480 * v(objectY) + 1) / 2 winZ = (v(objectZ) + 1) / 2 So, I did everything described there, and the final results is still having wrong values... What Do I have to do? Is something missing? Thank you a lot guys! Any help will be apreciatted. Fernando

##### Share on other sites
Did you normalize the coordinates after the projection, i.e. divide through by w? x'/x=z'/z or x'=x*z'/z and w ends up being the z of the coordinate being transformed. A projection matrix can only project onto a plane passing through the origin which is one of the reasons you use homogeneous coordinates. Translation is another reason.

Well, on second thought strike that last part. I think it is true with an orthographic projection, but I don't think you can do a perspective projection period with a matrix of constants.

[edited by - LilBudyWizer on June 3, 2002 10:32:27 PM]

##### Share on other sites
Sorry LilBudyWiser, but could you explain to me what is a NORMALIZED MATRIX? Cause I hear this everytime and until now, can''t figure out what it is.

I have 3 books of Linear Algebra at home (they are to old - I think they were wrote before 1990) and no of them tells you how to normalize a matrix.

I looked up on the Internet and I faced to a lot of fórmulas to arrive to the NORMALIZED MATRIX...

Which formula I have to choose?

Thank you

Fernando

##### Share on other sites
Not the matrix, the homogeneous coordinates. You divide through by the fourth component of the coordinate after multiplying by the perspective projection matrix. x''/x=z''/z or x''=x*z''/z, but z is the z component of the point being transformed. You can''t do that with a matrix of constants so the perspective projection matrix just sets the w component to z/z'' and leaves x and y unchanged. When you divide through you get x''=x*z''/z and y''=y*z''/z.

##### Share on other sites
Ok! Thankyou LilBudyWizer!!!

I always have to normalize the vector after I multiple it with a matrix?

In what other cases I have to normalize it?

Fernando

##### Share on other sites
aê manow... vai estudar ALGEBRA LINEAR...
hehe

##### Share on other sites
Só!

Me passa alguns sites aí!

Você é da onde?

##### Share on other sites
Not all matrices. The perspective projection matrix is one where you do. Rotation, scaling and translation should leave the w component as 1. I don''t know what else might change the w component though.

##### Share on other sites
Thanks for your help LilBudyWizer, I got what you told me, but there is a problem...

It didn''t work yet!

I don''t know, but I think the problem are in these multiplications:

v'' = ProjectionMatrix * ModelViewMatrix * v

To do the line that I described above, I''m doing the following:

r = projMatrix * modelMatrix; // here i''m multiplying the Projection Matrix by ModelView Matrix

// Here, I set the three values to zero because in modelMatrix I already have these values (at column 4)
fv.x = 0.0f;
fv.y = 0.0f;
fv.z = 0.0f;
fv.w = 1.0f;

fv = r * fv; // and here, I multiply r by fv (vector)

mtxNormalizeVector(&fv);

Is this the correct order?

Fernando

##### Share on other sites
It depends upon your matrices. Where did you get them? From OpenGL? If so they are the transposes of the standard matrices and it would be v*ModelView*Projection. The documentation describes the transposes of the actual matrices you get from OpenGL. You can double check that by looking at a translation matrix. The translation values are in the last row rather than the last column. Microsoft''s documentation here shows it as the last column though. That will change your vector/matrix multiplication as well to a row vector times a matrix rather than a matrix times a column vector.

I think they describe it that way because mathematically that is what they are doing. I think they just store the transposes and change their definition of matrix multiplication to a row times a row instead of a row times a column. So the matrices they show are the actual matrices they multiply by, but when you multiply the identity matrix by it you get the transpose. With their modified matrix multiplication A times B transpose is the transpose of A times B using standard matrix multiplication.

1. 1
Rutin
25
2. 2
3. 3
4. 4
5. 5

• 9
• 10
• 13
• 19
• 14
• ### Forum Statistics

• Total Topics
632943
• Total Posts
3009354
• ### Who's Online (See full list)

There are no registered users currently online

×