Welcome! Log In Create A New Profile

Advanced

# Help to coding unproject function

Posted by Paipum
 Paipum Help to coding unproject function November 09, 2011 04:04PM Registered: 7 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 * in.x + projection * in.x + projection * in.x + projection * in.x;
out.y = projection * in.y + projection * in.y + projection * in.y + projection * in.y;
out.z = projection * in.z + projection * in.z + projection * in.z + projection * in.z;
out.w = projection * in.w + projection * in.w + projection * in.w + projection * 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.

Click here to login