EDIT: See my next post for revised code to show the HUD with fixed relationship to the eyepoint.
I made some assumptions and errors in my previous post. I do apologize for that.
Regarding the weapons draw - how do you set the world position of the weapon for each render frame? Do you set it according to the current eye position and direction?
Putting together some quick code, I got the following to work:
- set viewport.MaxZ = 0
- set the world transform to position the object (for instance) forward and to the right of the eye position
- set the projection to 0.2, 10.0 (near/far), other parameters otherwise the same as for the rest of the scene
- draw the object
- set viewport.MaxZ = 1
- set the projection back to (whatever you use for the rest of the scene)
- set the world transform back to (whatever you use for the rest of the scene)
- continue rendering
I found that the "hugeness" of the weapon is due to not setting the viewport parameters.
You might try that algorithm and see what happens. FYI, you needn't draw the weapons first provided you reset the viewport / projection / world transforms as indicated. However, by drawing the weapons first, as mentioned above, you'll save the overdrawing of a few pixels.
EDIT: Here's what I did. vBufAxes is just a set of axes for the world. "aspect" is the aspect ratio of the window (or backbuffer, depending on what you're drawing).
////// testing - the origin always appears in the foreground
vp.MaxZ = 0;
// world axes
// draw them near the camera
D3DXVECTOR3 camPos = vDxChildren[dxChildNum].dxChild->camPos;
D3DXVECTOR3 camDir = vDxChildren[dxChildNum].dxChild->camDir;
D3DXVECTOR3 camUp = vDxChildren[dxChildNum].dxChild->camUp;
D3DXVec3Normalize(&camRight, D3DXVec3Cross(&camRight, &camUp, &camDir));
D3DXVECTOR3 axesPos = camPos + 3.0f*camDir - camUp + camRight;
D3DXMatrixTranslation(&axesWorld, axesPos.x, axesPos.y, axesPos.z);
D3DXMatrixPerspectiveFovLH(&tmpProj, D3DX_PI * 0.25f, aspect, 0.20f, 10.0f);
gd3dDevice->SetStreamSource(0, vBufAxes, 0, sizeof(COLORVERTEX));
gd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 24);
vp.MaxZ = 1;
NOTE: this draws the axes to reflect the orientation of the camera! I have to change the code to draw them as a fixed object. I'll be back in a while.
Edited by Buckeye, 15 February 2014 - 10:41 AM.