Jump to content
  • Advertisement
Sign in to follow this  
guinux

Question concerning "W" coordinates

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 2
float fClipx = (float)(Width >> 1);
float fClipy = (float)(Height >> 1);
// transform x
float fX = (mat._11*vec.x) + (mat._21*vec.y) + (mat._31*vec.z) + mat._41;
// transform y
float fY = (mat._12*vec.x) + (mat._22*vec.y) + (mat._32*vec.z) + mat._42;
// transform w
float fW = (mat._14*vec.x) + (mat._24*vec.y) + (mat._34*vec.z) + mat._44;

// invert the W coord
float fWpInv = 1/fW;

// coords range [-1, 1]
fX *= fWpInv;
fY *= fWpInv;


// then convert to pixel space
pt.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 this post


Link to post
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 this post


Link to post
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 this post


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

Share this post


Link to post
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 :(

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!