Sign in to follow this  

HELP : trying to pin a weapon/character mesh to the camera

This topic is 3301 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

Hey guys, Im trying to pin a character/weapon mesh to the camera (like a FPS view)... at the moment when i move using the keyboard, the mesh moves but when i use the mouse to rotate around for example it seems to go around the mesh, where the mesh is still and doesnt rotate with it. (directx using C++) here is the code: ///// begin scene case GS_MOVETO: { renderScene(); drawChar(cameraObj.cView.x,0.0f,cameraObj.cView.z); /// <------------------ cameraObj.mouseMove(SCREEN_WIDTH,SCREEN_HEIGHT); keyMovement(); } break; } ///// end scene void drawChar(float x, float y, float z) { D3DXMATRIX world4; D3DXMatrixTranslation(&world4, x, 0.0, z); d3ddev->SetTransform(D3DTS_WORLD, &(world4)); for(DWORD n=0; n<numCharMaterials; n++) //looping throught each subset { d3ddev->SetMaterial(&char1Material[n]); if(texture2[n] !=NULL) d3ddev->SetTexture(0, texture2[n]); //set the material meshChar1->DrawSubset(n); //render } } //////////////////////////////////////////////

Share this post


Link to post
Share on other sites
Just make a world matrix that specifies how you want your weapon mesh to be positioned and oriented relative to your camera, and set your view matrix to identity. So for example if you wanted the weapon mesh to be 5 units in front of the camera, 2 to the right, and 2 to the left, you would do this:


D3DXMATRIX world;
D3DXMatrixTranslation(&world, 2, 2, 5);
d3ddev->SetTransform(D3DTS_WORLD, &world);
D3DXMATRIX view;
D3DXMatrixIdentity(&view);
d3ddev->SetTransform(D3DTS_VIEW, &view);

// Draw your mesh subsets




BTW, if you want proper formatting when you post code here you can use the "code" or "source" tags. See the forum FAQ.

Share this post


Link to post
Share on other sites

This topic is 3301 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