# Help to coding unproject function

Posted by Paipum
 Paipum Help to coding unproject function November 09, 2011 04:04PM Registered: 11 years agoPosts: 2
I'm coding a function to getting the coordinates of wii mote pointer in a 3D environment. I'm not sure if the code is correct or wrong because x,y coord are between -1 and 1. The code seems of gluUnProject from opengl. Someone can help me???

```int Engine::unProject(float winx, float winy, float winz, Mtx44 projection, guVector *position) {

guQuaternion in;
guQuaternion out;

if(guMtxInverse(projection, projection) == 0) {
return GX_FALSE;
}

in.x = (winx - 0) / screen->getWidth();
in.y = (winy - 0) / screen->getHeight();
in.z = winz;
in.w = 1.0f;

in.x = in.x * 2.0f - 1.0f;
in.y = in.y * 2.0f - 1.0f;
in.z = in.z * 2.0f - 1.0f;

out.x = projection[0][0] * in.x + projection[0][1] * in.x + projection[0][2] * in.x + projection[0][3] * in.x;
out.y = projection[1][0] * in.y + projection[1][1] * in.y + projection[1][2] * in.y + projection[1][3] * in.y;
out.z = projection[2][0] * in.z + projection[2][1] * in.z + projection[2][2] * in.z + projection[2][3] * in.z;
out.w = projection[3][0] * in.w + projection[3][1] * in.w + projection[3][2] * in.w + projection[3][3] * in.w;

if(out.w == 0.0f) {
return GX_FALSE;
}

out.x /= out.w;
out.y /= out.w;
out.z /= out.w;

position->x = out.x;
position->y = out.y;
position->z = out.z;

return GX_TRUE;
}```

Thanks and sorry for my bad english.
Sorry, only registered users may post in this forum.