Jump to content
  • Advertisement
Sign in to follow this  
daanyaal

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

This topic is 3606 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!