   [C++, DX9] FPS Camera, Weapon position
  I'm using DirectX Input for most of mouse functions, as well as camera movement:xrot-=(float)MouseState.lX/100;yrot+=(float)MouseState.lY/100;if(yrot>D3DX_PI) yrot=D3DX_PI-0.001f;else if(yrot<0) yrot=0;And this updates my camera:typedef D3DXVECTOR3 Vector3;Vector3 m_UpVector(0, 0, 1);void SetUpCamera() {Matrix m_View;m_EyePos.x = player.model->vecPos.x;m_EyePos.y = player.model->vecPos.y;m_EyePos.z = player.model->vecPos.z + 10;m_TargetPos.x = m_EyePos.x + D3DX_PI * sin(yrot) * sin(xrot);m_TargetPos.y = m_EyePos.y + D3DX_PI * sin(yrot) * cos(xrot);m_TargetPos.z = m_EyePos.z + D3DX_PI * cos(yrot);D3DXMatrixLookAtLH(&m_View, &m_EyePos, &m_TargetPos, &m_UpVector);device->SetTransform(D3DTS_VIEW, &m_View);}I use this code to keep weapon in my screen, however it doesn't seem to be fully right:Rifle->vecRot.x=-yrot;Rifle->vecRot.z=-xrot;Rifle->vecPos.x = m_EyePos.x + 3 * D3DX_PI * sin(yrot+0.65f) * sin(xrot-0.25f);Rifle->vecPos.y = m_EyePos.y + 3 * D3DX_PI * sin(yrot+0.65f) * cos(xrot-0.25f);Rifle->vecPos.z = m_EyePos.z + 3 * D3DX_PI * cos(yrot+0.65f);Rifle->Draw();When I look forward, it's pretty much alright, except it goes through things: http://dl.dropbox.com/u/2637453/sdg/Capture1.PNGWhen I look up weapon disappears at all: http://dl.dropbox.com/u/2637453/sdg/Capture2.PNGWhen I look down it moved to other side of screen (wtf) and goes through terrain: http://dl.dropbox.com/u/2637453/sdg/Capture3.PNGFPS Camera works right, however I'm trying to make weapon stay on-screen like in FPS games but it doesn't seem to work for me.[Edited by - Ripiz on May 27, 2010 4:16:52 AM]
  thats some trippy code man , tried rendering the gun at the inverse of view?   ;  It's even worse then =/ I'm like.. Inside weapon or something, totally doesn't work   ;  Why not render the weapon at the same screen position, independent of the camera view? See the more recent post about rendering camera/weapons (poster=Anddos).Most FPS show the weapon in the same screen position all the time. Just use the camera direction (with a different position to account for the difference between eye and rifle position) for the weapon direction.   ;  buckeye i havent figured how todo it yet   ;Quote:Original post by RipizIt's even worse then =/ I'm like.. Inside weapon or something, totally doesn't work"inside the weapon". Is the "inside" image of the weapon static or not?If it's static, then you are on the right track. you only have to set the weapon to the right position (since orientation is fine).   ;Quote:Original post by Anddosbuckeye i havent figured how todo it yetI saw that thread. The solution have been given to you. If you can't make something of it....   ;Quote:Original post by BuckeyeWhy not render the weapon at the same screen position, independent of the camera view? See the more recent post about rendering camera/weapons (poster=Anddos).Most FPS show the weapon in the same screen position all the time. Just use the camera direction (with a different position to account for the difference between eye and rifle position) for the weapon direction.Well that worked, but it still goes through terrain if I look straight down, any idea how to fix that one, or you think it's normal?   ;  what do you mean by same screen positon?,my gun model is 3d so you have to render it in a d3dxvector or are you talking about x,y screencords?   ;Quote:Original post by RipizQuote:Original post by BuckeyeWhy not render the weapon at the same screen position, independent of the camera view? See the more recent post about rendering camera/weapons (poster=Anddos).Most FPS show the weapon in the same screen position all the time. Just use the camera direction (with a different position to account for the difference between eye and rifle position) for the weapon direction.Well that worked, but it still goes through terrain if I look straight down, any idea how to fix that one, or you think it's normal?you can clear the depth buffer.Do you use the same projection matrix? (So the near and far plane are in the same distance).I think if you use the same projection matrix, then the gun shouldn't go through the terrain, if well positioned.Your gun is either too big (compared to the scene), or the center of the head's (player's) rotation is too low, or the gun (thus the center of the camera) is placed too far in front of the player.An other possible issue: if your near plane is too far from the camera center (which is not a problem by itself), then you can't place the gun close enough to the center (because it would be clipped). In this case, you have to clear the depth buffer, or set the near plane closer (which will probably make the depth test very imprecise).So, after all these text: clear your depth buffer, so your gun will never intersect the scene.Yup, all the stuff I wrote is pretty much stupid, (I haven't done FPS/gun stuff before). Anyways, clear that buffer [grin]   