Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need help with transformed vertex from OpenGL matrix

0 views
Skip to first unread message

CharlieB

unread,
Jul 24, 2005, 6:01:02 PM7/24/05
to
From the OpenGL FAQ:

How do I find the coordinates of a vertex transformed only by the ModelView
matrix?

It's often useful to obtain the eye coordinate space value of a vertex
(i.e., the object space vertex transformed by the ModelView matrix). You
can obtain this by retrieving the current ModelView matrix and performing
simple vector / matrix multiplication.


This is exactly what I need. However I cannot figure out how to multiply the
vertex by the returned ModelView matrix. (It may be simple to them but not
me :-) )

Here is what I had in mind but it doesn't look right:

/* Transforms the points array in p1 to p2 by multipling by OpenGL matrix
glmatrix */
void multi_glmatrix_vertex (GLfloat *glmatrix, POINT *p1, POINT *p2,
int num_points)
{
int i;
for (i = 0; i < num_points; i++)
{
p2[i].x = (p1[i].x * glmatrix[0]) + (p1[i].y * glmatrix[4]) +
(p1[i].z * glmatrix[8]) + glmatrix[12];
p2[i].y = (p1[i].x * glmatrix[1]) + (p1[i].y * glmatrix[5]) +
(p1[i].z * glmatrix[9]) + glmatrix[13];
p2[i].z = (p1[i].x * glmatrix[2]) + (p1[i].y * glmatrix[6]) +
(p1[i].z * glmatrix[10]) + glmatrix[14];
}
}

Thanks in advance,
Charlie

fungus

unread,
Jul 24, 2005, 6:22:12 PM7/24/05
to
CharlieB wrote:
>
> Here is what I had in mind but it doesn't look right:
>

It looks right to me.


--
<\___/>
/ O O \
\_____/ FTB. For email, remove my socks.

In science it often happens that scientists say, 'You know
that's a really good argument; my position is mistaken,'
and then they actually change their minds and you never
hear that old view from them again. They really do it.
It doesn't happen as often as it should, because scientists
are human and change is sometimes painful. But it happens
every day. I cannot recall the last time something like
that happened in politics or religion.

- Carl Sagan, 1987 CSICOP keynote address

CharlieB

unread,
Jul 24, 2005, 7:09:21 PM7/24/05
to
fungus wrote:

> CharlieB wrote:
>>
>> Here is what I had in mind but it doesn't look right:
>>
>
> It looks right to me.
>
>

Oh. I'll start using it. Thanks.

0 new messages