setting up Weapon in FPS

Started by
4 comments, last by crazy_crab 13 years, 6 months ago
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.
Advertisement
I suggest you to try "fps gun" with the forum's search feature.
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
Crazy dude smoking D3D11, AngelScript, PhysX, 3D Sound, Network, DB, FBX, and some other weird things, doing that on Visual Studio 2010 + Visual Assist X on Overclocked CPU
I just made this post on this thread, which should clear up the same issue you are having. Hope it helps.

Cheers.

http://www.gamedev.net/community/forums/topic.asp?topic_id=584106
just simply render at world*projection, make sure you set the z to something like 5.0f so the mesh inview else its defaulted off screen..
:)
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...

This topic is closed to new replies.

Advertisement