#### Archived

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

# 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.

## 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 on other sites
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]

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633322
• Total Posts
3011360
• ### Who's Online (See full list)

There are no registered users currently online

×