Sign in to follow this  

I don't understand my code (uv-mapping)

Recommended Posts

Hello I don't know why my code work as it does. The code looks like this:
D3DXVECTOR3 vNodePos = *GetPosition(vec_adj_itr->this_node); // get position in 3D
D3DXVECTOR3 vBBoxDimensions = vBBoxMax - vBoxMin;
vNodePos -= (vBBoxDimensions * 0.5f + vBBoxMin);
D3DXVECTOR2 *vNodeUV = GetUV(vec_adj_itr->this_node); // Get pointer to set uv
vNodeUV->x = atan2(D3DXVec3Dot(&vSecondaryAxe1,&vNodePos), D3DXVec3Dot(&vPrimaryAxe,&vNodePos)) / (D3DX_PI * 2.0f) + 0.5f; // Set u based on polar coordinates mapped to [0,1], vSecondaryAxe1 is (1.0f,0.0f,0.0f), vPrimaryAxe is (0.0f,0.0f,1.0f)
vNodeUV->y = atan2(D3DXVec3Dot(&vSecondaryAxe2,&vNodePos), D3DXVec3Dot(&vPrimaryAxe,&vNodePos)) / (D3DX_PI * 2.0f) + 0.5f; // vSecondaryAxe2 is (0.0f,1.0f,0.0f)

It is supposed to sweap around some geometry and assign uv-coordinates evenly, but when processed it looks like this: The texture is a checker pattern, why is it not evenly distributed?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this