View Full Version : ModelView Matrix & Calc Translation factor

baconbeastnz

10-06-2008, 07:48 PM

My modelview matrix is currently:

1 0 0 0

0 cos45 -sin45 0

0 sin45 cos45 0

0 0 0 0

Now I call glTranslate(0,2,0) and multiply the above matrix with the below one.

1000

0101

0010

0001

I can figure out the first 3x3 block which is just

1 0 0

0 cos45 -sin45 0

0 sin45 cos45 0

But how do I figure out the right most column ( the translation values)

trinitrotoluene

10-06-2008, 08:02 PM

This is just a 4x4 matrix multiply (http://en.wikipedia.org/wiki/Matrix_multiplication). Multiply rows of matrix 1 by column of matrix 2. So

|1 0 0 0 |

|0 cos45 -sin45 0 |

|0 sin45 cos45 0 |

|0 0 0 1 |

*

|1 0 0 0|

|0 1 0 2|

|0 0 1 0|

|0 0 0 1|

=

| 1 0 0 0 |

| 0 cos45 -sin45 2*cos45 |

| 0 sin45 cos45 2*sin45 |

| 0 0 0 1 |

baconbeastnz

10-07-2008, 01:24 AM

Ah thankyou for the reply. have looked at the diagram and I understand it now. I did look at it before and misinterpreted it .

Thankyou! I also have another question which I will post here.

When we calculate the position of each vertex we multiply it by the modelview matrix right, so how is the new position calculated?

Do we just represent the point P (4,3,2) as a 3x1 matrix then do matrix multiplication between the point and the MV matrix?

trinitrotoluene

10-07-2008, 07:21 AM

Yes, you can represent a point P (4,3,2,1) (x,y,z,w) as a 4x1 matrix. This is called homogeneous coordinates (http://en.wikipedia.org/wiki/Homogeneous_coordinates).

In OpenGL, the modelview matrix and a vertex is multiplied in this order P' = MV * P

Duncan Champney

10-07-2008, 10:49 AM

Ah thankyou for the reply. have looked at the diagram and I understand it now. I did look at it before and misinterpreted it .

Thankyou! I also have another question which I will post here.

When we calculate the position of each vertex we multiply it by the modelview matrix right, so how is the new position calculated?

Do we just represent the point P (4,3,2) as a 3x1 matrix then do matrix multiplication between the point and the MV matrix?

Yes, as the other poster already said.

Of course, usually we don't apply our matrix transformations to vertexes directly. The video driver applies our model view and projection matrixes to our vertexes when we render them. Modern accelerated video hardware is a WHOLE lot faster for matrix math like this than the CPU.

baconbeastnz

10-07-2008, 03:29 PM

ok cool, thanks, so glad i finally understands how that all works now =D for my next assignment I need to make ray caster :p should be fun but still need to understand quite a few more concepts lol.

cheers guys!

baconbeastnz

10-07-2008, 03:53 PM

Actually, having just tried to 4x1 multiplication, I have run into another misunderstanding.

Let p = Mv x P

MV = below

1 0 0 0

0 1 0 0

0 0 -1 4

0 0 0 1

Now to calc P I get:

X = 1xX + 0xX + 0xX + 0xX

Y = 0xY + 1xY + 0xY + 0xY

Z = 0xZ + 0xZ - Z + 4Z

However the answer for z is supposed to be : "-z +4"

(O_o)/") hmph.....

trinitrotoluene

10-07-2008, 04:11 PM

No this is

Suppose we have a point P(X,Y,Z,W=1)

X = 1*X + 0*Y + 0*Z + 0*W = X

Y = 0*X + 1*Y + 0*Z + 0xW = Y

Z = 0*X + 0*Y + -1*Z + 4*W = -Z + 4 => W = 1

W = 0*X + 0*Y + 0*Z + 1*W = 1

Here P is a column vector

baconbeastnz

10-07-2008, 06:45 PM

AHHHH!! I seee I see! another hurdle leaped :D

Thanks = )

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.