Sign in to follow this  

setting up Weapon in FPS

This topic is 2624 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi,
i am making a simple FPS game in DirectX and c++.
i have a weapon mesh and want to show it as the camera rotate and move,i tried for many hours but can not succeed.

-I know the camera forward,up and right directions (in vector forms)
g_vLook,g_vUp,g_vRight
-I know the current position of camera.
g_vEye

so, how can i set up the rotations and translation of the weapon.

my code is..


D3DXMATRIX matWorld,temp;
g_pd3dDevice->GetTransform( D3DTS_VIEW, &matView );
D3DXMatrixInverse(&matWorld, 0, &matView);
//scaling
D3DXMatrixScaling(&mat,.02,.02,.02);
D3DXMatrixMultiply(&matWorld,&matWorld,&mat);
//translation
D3DXMatrixTranslation(&mat,g_vEye.x,g_vEye.y,g_vEye.z);
D3DXMatrixMultiply(&matWorld,&matWorld,&mat);

gun->Draw();


by this code not working well.
please help me.

Share this post


Link to post
Share on other sites
there was similar thread, but how about try creating second camera?
render world from first cam
render fps weapon+hand with second cam

otherwise u can try D3DXMatrixTransfomration functions to make hand+gun rotate around point - player position

Share this post


Link to post
Share on other sites
i solve the problem...


D3DXMatrixScaling(&mat,.02,.02,.02);
D3DXMatrixMultiply(stack->GetTop(),stack->GetTop(),&mat);

D3DXMatrixRotationY(&mat,D3DXToRadian(-10));
D3DXMatrixMultiply(stack->GetTop(),stack->GetTop(),&mat);

D3DXMatrixRotationX(&mat,D3DXToRadian(-5));
D3DXMatrixMultiply(stack->GetTop(),stack->GetTop(),&mat);

stack->Translate(.6,-.6,0);

D3DXMATRIX matWorld;
d3ddev->GetTransform( D3DTS_VIEW, &matView);
D3DXMatrixInverse(&matWorld, 0, &matView);
D3DXMatrixMultiply(stack->GetTop(),stack->GetTop(),&matWorld);

d3ddev->SetTransform( D3DTS_WORLD, stack->GetTop() );
gun->Draw();


actually i sholud multyply the inverse view matrix after all the rotation and translations.this simple thing gave me a bad headach...

Share this post


Link to post
Share on other sites

This topic is 2624 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this