Jump to content
  • Advertisement

Archived

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

davekerr

OpenGL A simple OpenGL question?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m writing a 3D modelling app at the moment, using OpenGL. This has been fine for me, but now I''ve come up with a problem. All of my objects have an array of vertices, in Object Space. When I come to draw them, I just use commands like: glTranslate3f(m_x, m_y, m_z) etc, to translate them. However, I''m building a raytracer now, and I have to get the tranformed coordinates. I''ve been calling the same commands, and then just getting the modelview matrix, and multiplying all the vertices by that by hand, but what i''m not sure about is this: When I''ve got the matrix, in an array of 16 doubles, what parts do I multiply each vertex by? I''ve got something like this at the moment: x = (x * matrix[0]) + (y * matrix[4]) + (z * matrix[8]); y = (x * matrix[1]) + (y * matrix[5]) + (z * matrix[9]); z = (x * matrix[2]) + (y * matrix[6]) + (z * matrix[10]); but i don''t think it''s doing it properly. Any advice? Thanks in advance, Dave

Share this post


Link to post
Share on other sites
Advertisement
quote:

x = (x * matrix[0]) + (y * matrix[4]) + (z * matrix[8]);
y = (x * matrix[1]) + (y * matrix[5]) + (z * matrix[9]);
z = (x * matrix[2]) + (y * matrix[6]) + (z * matrix[10]);


If we're talking about OpenGL matrices (column-major order), then that is principally correct. But only for the rotation part. And be sure to assign to a different set of variables than the ones you use in the multiplication.

The full transform of a point (x,y,z,w) by an OpenGL matrix would be:

xt = (x * matrix[0]) + (y * matrix[4]) + (z * matrix[8]) + (w * matrix[12]);
yt = (x * matrix[1]) + (y * matrix[5]) + (z * matrix[9]) + (w * matrix[13]);
zt = (x * matrix[2]) + (y * matrix[6]) + (z * matrix[10]) + (w * matrix[14]);
wt = (x * matrix[3]) + (y * matrix[7]) + (z * matrix[11]) + (w * matrix[15]);


BTW, this belongs in the OpenGL forum. Moved.

/ Yann

[edited by - Yann L on June 23, 2002 6:32:05 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!