Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool WorldToScreen(const Vector3 pos,Vector3& screen, float matrix[16], int windowWidth,int windowHeight) {
- Vector4 clipCoords;
- clipCoords.x = matrix[0] * pos.x + matrix[4] * pos.y + matrix[8] * pos.z + matrix[12];
- clipCoords.y = matrix[1] * pos.x + matrix[5] * pos.y + matrix[9] * pos.z + matrix[13];
- clipCoords.z = matrix[2] * pos.x + matrix[6] * pos.y + matrix[10] * pos.z + matrix[14];
- clipCoords.w = matrix[3] * pos.x + matrix[7] * pos.y + matrix[11] * pos.z + matrix[15];
- if (clipCoords.w < 1.f)
- {
- return false;
- }
- Vector3 NDC;
- NDC.x = clipCoords.x / clipCoords.w;
- NDC.y = clipCoords.y / clipCoords.w;
- NDC.z = clipCoords.z / clipCoords.w;
- screen.x = (windowWidth / 2 * NDC.x) + (NDC.x + windowWidth / 2);
- screen.y = -(windowHeight / 2 * NDC.y) + (NDC.y + windowHeight / 2);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement