Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I've been following a guide I found here (http://knol.google.com/k/matrices-for-3d-applications-view-transformation) on constructing a matrix that will allow me to 3D coordinates to an object's local coordinate space, and back again. I've tried to implement these two matrices using my object's look, side, up and location vectors and it seems to be working for the first three coordinates. I'm a little confused as to what I should expect for the w coordinate.

Here are couple of examples from the print outs I've made of the matricies that are constructed. I'm passing a test vector of [9, 8, 14, 1] each time to see if I can convert both ways:

Basic example:

localize matrix:
Matrix: 0.000000    -0.000000   1.000000    0.000000
        0.000000    1.000000    0.000000    0.000000
        1.000000    0.000000    0.000000    0.000000
        5.237297    -45.530716  11.021271   1.000000
globalize matrix:
Matrix: 0.000000    0.000000    1.000000    0.000000
        -0.000000   1.000000    0.000000    0.000000
        1.000000    0.000000    0.000000    0.000000
        -11.021271  -45.530716  -5.237297   1.000000

test:
Vector4f(9.000000, 8.000000, 14.000000, 1.000000)
localTest:
Vector4f(14.000000, 8.000000, 9.000000, -161.812256)
worldTest:
Vector4f(9.000000, 8.000000, 14.000000, -727.491455)

More complicated example:

localize matrix:
Matrix: 0.052504    -0.000689   -0.998258   0.000000
        0.052431    0.998260    0.002068    0.000000
        0.997241    -0.052486   0.052486    0.000000
        58.806095   2.979346    -39.396252  1.000000
globalize matrix:
Matrix: 0.052504    0.052431    0.997241    0.000000
        -0.000689   0.998260    -0.052486   0.000000
        -0.998258   0.002068    0.052486    0.000000
        -42.413120  5.975957    -56.419727  1.000000

test:
Vector4f(9.000000, 8.000000, 14.000000, 1.000000)
localTest:
Vector4f(-13.508600, 8.486917, 9.290090, 2.542114)
worldTest:
Vector4f(9.000190, 7.993863, 13.990230, 102.057129)

As you can see in the more complicated example, the coordinates after converting both ways loose some precision, but this isn't a problem. I'm just wondering how I should deal with the last (w) coordinate? Should I just set it to 1 after performing the matrix multiplication, or does it look like I've done something wrong?

Thanks in advance for your help!

share|improve this question
    
kudos to ya ... that just went way over my head :) –  Wardy Mar 18 '13 at 16:21
add comment

1 Answer 1

up vote 2 down vote accepted

It looks like you are confusing rows and columns in your matrices, either in the way your load or store them, or when you perform the matrix×vector multiplication. The w coordinate should always yield 1 with the matrices you are using.

share|improve this answer
    
Hi - thanks for the reply. My matrix is in row vector notation and the vectors that I'm multiplying are column vectors. I've multiplied the same matrices and vectors in matlab and get the same answers. –  James Bedford Mar 6 '11 at 14:15
    
Ahhh I've just tried the tanspose of this matrix in Matlab multiplied with the vector and the w coordinate yields 1, so when I'm constructing my transformation matrices I must be using the wrong matrix notation. –  James Bedford Mar 6 '11 at 14:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.