# Question concerning "W" coordinates

This topic is 4904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hello there, i am new here. what brought me here was a problem i couldn't fix with any documentation i found on the internet. on wikipedia, the 3d projection article, they say that after you applied your global matrix to a vertex you have {x', y', z', w'} with {x'/w', y'/w', z'/w'} the normalized coordinates between -1 and 1. unfortunately i do not get this at all. here is a dump of the matrices in my test program: world 0.960000 0.000000 0.000000 0.000000 0.000000 0.960000 0.000000 0.000000 0.000000 0.000000 0.960000 0.000000 0.000000 0.000000 0.000000 1.000000 camera 0.707108 -0.645973 -0.262741 0.000000 0.707106 0.645975 0.262742 0.000000 0.000000 -0.406737 0.834565 0.000000 28.625141 592.021973 -30.149647 1.000000 tmp ( = camera * world) 0.678823 -0.620134 -0.252231 0.000000 0.678822 0.620136 0.252232 0.000000 0.000000 -0.390467 0.801183 0.000000 27.480135 568.341064 -28.943661 1.000000 perspective 0.732600 0.000000 0.000000 0.000000 0.000000 0.976800 0.000000 0.000000 0.000000 0.000000 1.002002 -2.002002 0.000000 0.000000 1.000000 0.000000 global ( = perspective * tmp) 0.497306 -0.454311 -0.184785 0.000000 0.663073 0.605749 0.246380 0.000000 -55.015285 -1138.211182 58.748055 -2.002002 0.000000 -0.390467 0.801183 0.000000 what seems suspect is the 3rd line of the global matrix... no? i get w' ~= -50 and after division by w', i have (x, y, z) ~= (28, 569, -29), that's almost the translation of the camera matrix... i tried to substract the translation values but this is absolutely not valid. so, as you see i get values completely out of the desired range [-1;1]... have i missed something? thank you a lot for helping because i'm a bit stuck at the moment... guinux

##### Share on other sites
Just a guess -- only points within the view frustum are in the range [-1,1].

##### Share on other sites
then no point are in the frustum, which is not possible i think... but i had a thought, when they mean in the range [-1;1], do the local coordinates (ie the one given in the 3d file) have to be in the range [-1;1]? (im reading from a .ASE)

##### Share on other sites
Are you trying to project a point and then get it's screen coords?
you need the matrix World*View*Proj

Transform3Dto2D(D3DVECTOR3 vec){POINT pt;// divide the screen width and height by 2float fClipx = (float)(Width >> 1);float fClipy = (float)(Height >> 1);// transform xfloat fX = (mat._11*vec.x) + (mat._21*vec.y) + (mat._31*vec.z) + mat._41;// transform yfloat fY = (mat._12*vec.x) + (mat._22*vec.y) + (mat._32*vec.z) + mat._42;// transform wfloat fW = (mat._14*vec.x) + (mat._24*vec.y) + (mat._34*vec.z) + mat._44;// invert the W coordfloat fWpInv = 1/fW;// coords range [-1, 1]fX *= fWpInv;fY *= fWpInv;// then convert to pixel spacept.x =(LONG)((1.0f + fX) * fClipx);pt.y =(LONG)((1.0f + fY) * fClipy);}

[Edited by - Gorwooken on August 16, 2005 3:33:57 PM]

##### Share on other sites
i was trying to do a projection using the last matrix in here:
http://en.wikipedia.org/wiki/3D_projection
but the stuff is wrong

does your code convert to [-1;1] ? could you comment it a bit ?

thank you a lot for your help guys

guinux

##### Share on other sites
fX*fWpInv;
and
fY*fWpInv;
will give you the coords at [-1,1] adding one to it gives you [0,2] then you can multiply it by fClipx for x and fClipy for the y coord in screen space

##### Share on other sites
espacially: what is "fWpInv" (not defined)

##### Share on other sites
sorry i didn't you have just replided... but still don't know : "fWpInv" <- how do you define this?

##### Share on other sites
sorry i just kinda wrote that from memory, i edited it again

##### Share on other sites
yes so you divide by W x and y, this is my code... it's the same no?

GX3D_VectorTransform(Vertices, GlobalMatrix, Object->Vertices); /*x,y,z transformation*/
w_ = GlobalMatrix[0][3]*Object->Vertices[0] +
GlobalMatrix[1][3]*Object->Vertices[1] +
GlobalMatrix[2][3]*Object->Vertices[2] +
GlobalMatrix[3][3];
Vertices[0] /= w_;
Vertices[1] /= w_;
Vertices[2] /= w_;

except that the values i get are something like 500.0f :s see (first post)

i really don't understand :(

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 11
• 9
• 9
• 40
• ### Forum Statistics

• Total Topics
634130
• Total Posts
3015704
×