I'm using a orthographic projection view to render my game ui but, can't get the offset from my quad to align to the true centre
of the screen.
this is what Im doing I fist get the size of the quad by finding the min and max vertices of the quad then get the distance from
min and max I use this value to get the percentage of the screen, with this percentage divided by 2 I get the size in relation to the screen, then these locations get projected to 3d world space so they can be added to the unprojected screens 0,0 location in 3d space.
But the quad is not centre its off to the right what could be wrong if its all not wrong.
thanks for any help.
The quad we exported from 3dsmax at (0.0.0) in 3ds max world but the quads axis is the topleft of the quad if it helps.
here is the code I use to calculate the percentage and offsets
width and height are the quads size in object space(how its exported.)
//calculate the percentage of the ui quad to the screen float px = (width / viewport.Width) * 100.0; float py = (height / viewport.Height) * 100.0; px *= 0.5;//we want half the percentage py *= 0.5; //we now want the percentage in size in relation to the screen float screenpercentx = (viewport.Width * px / 100); float screenpercenty = (viewport.Height * py / 100); //now we want half and offseted from screen centre screenpercentx = ((viewport.Width * 0.5) - (screenpercentx * 0.5)); screenpercenty = ((viewport.Height * 0.5) - (screenpercenty * 0.5)); DialogBox_GameLobby->SetCamera(&Cam); D3DXMATRIX matView ; Cam.getViewMatrix(&matView); DialogBox_GameLobby->ReSetCam(&Cam); D3DXVECTOR3 v; D3DXVECTOR3 rayOrigin(0.0f, 0.0f, 0.0f); v.x = screenpercentx; v.y = screenpercenty; v.z = 0.0f; //unproject the screen base ofset 3d space D3DXVec3Unproject(&rayOrigin, &v, &viewport, &OrthograpicProjection, &matView, &Identityworld); //set the conversion screenpercentx = rayOrigin.x; screenpercenty = rayOrigin.y; rayOrigin= D3DXVECTOR3 (0.0f, 0.0f, 0.0f); //the left side of the screen v.x = 0.0; v.y = 0.0; v.z = 0.0f; //unproject the the left side of the screen to 3d space D3DXVec3Unproject(&rayOrigin, &v, &viewport,& OrthograpicProjection, &matView, &Identityworld); // //we have the left side of the screen projected to 3d world space //add the quads projected location to the left side Dialog_GameLobby->SetWorldPosition( rayOrigin.x - screenpercentx ,rayOrigin.y - screenpercenty, -1.0, 1.0, 1.0, 1.0);