View Full Version : homogenous coords

I've done some reading on opengls' use of homogenous coordinates and somewhere it said that unless changed, the w value(x , y ,z ,w) is 1.00.. I've transformed and rotated the verts myself and compared them to the api's and they are not the same and dividing by 1.00 is certainly not going to give me what I want.....I'm obviously missing something... any help would be appreciated ......

MikeC

05-24-2000, 08:12 AM

How are you doing the translations? If you're adding two Vector4 coords with implicit W==1, using standard vector addition rules, the result will have W==2. AFAIK the "default W==1" only applies when multiplying a Vector4 by a matrix; I don't know about anything else.

the DEFAULT probably comes when you specify verticies with glVertex3f() and not ...4f(). after that, i reckon ogl can do what it wants with his homogenous coordinates.

cheers,

John

BTW, about homogeneous coords:

lambda*(x, y, z, w) is the same point for all lambda. so, the point

(1, 2, 3, 1) == (2, 4, 6, 2) == (3, 6, 9, 3)

etc.

to convert homogeneous to cartesian coordinates, you divide x, y & z by w. (ie. (3/3, 6/3, 9/3) == (2/2, 4/2, 6/2) == (1, 2, 3)

hope this helps clear things up

cheers,

John

That's what I'm tring to find, the w value to convert back to cartesian coords. Maybe I'm going about this wrong..

Here's what I'm doing ...after

glRotatef() and glTranslatef() I'm getting the matrix with

glGetFloatv() and transforming with something like this...

x = Set.x * T[0] + Set.y * T[4] + Set.z *

T[8] + T[12];

y = Set.x * T[1] + Set.y * T[5] + Set.z *

T[9] + T[13];

z = Set.x * T[2] + Set.y * T[6] + Set.z *

T[10] + T[14];

now at this point I think I would do a x/w y/w z/w to get the cartesian coords...

Is this correct????

Your multiplication for x,y and z is correct (no doubt about that !).

On the other hand, I can not answer for your w problem...

I would have thought you should do :

newX=T[0]*x+T[4]*y+T[8]*z+T[12]*w;

newY=T[1]*x+T[5]*y+T[9]*z+T[13]*w;

newZ=T[2]*x+T[6]*y+T[10]*z+T[14]*w;

newW=T[3]*x+T[7]*y+T[11]*z+T[15]*w;

And then :

cartesian_x=newX/newW;

cartesian_y=newY/newW;

cartesian_z=newZ/newW;

cartesian_w=newW/newW; // =1 ! //

That's what I think you should do but, to be honest, I have never used this w coordinate...

Regards.

Eric

yes; Eric is right.

oh, except when you convert homogeneous to cartesian coordinates, the w is lost (and so dividing w by w is irrelevent)

and w does not necessarily == 1. it just has to be non zero (if w is zero, the point is at infinity...)

cheers,

John

[This message has been edited by john (edited 05-25-2000).]

Thanks for the replies... I tried the solutions but still not getting the results I want..... Maybe it's the way I handle the polygons normal... I'm adding the normal to a vertice and transforming it just like the a regular vertices and then subtracting it from this vert when I need it. What I'm trying to do is implement collision detection and I know the algo works with my own transformations but fails with this...any ideas ????

Have a look there :

http://heron.cc.ukans.edu/ebt-bin/nph-dweb/dynaweb/SGI_Developer/OpenGL_PG/

It is the OpenGL programming guide.

They explain that when the vertices are transformed by a matrix M, the normals are transformed by (M-1)t which means the transpose of the invert of M.

That's probably where your problem is !

Good luck.

Eric

P.S. : I had to use that when parsing .ASE files and it worked.

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