# rotating the gun along with camera-------help me pls

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

## Recommended Posts

hi members, Iam a DirectX beginner, I managed to create First Person Camera & created a walkthrough as moving arround a room(X file). Then I placed a gun before the camera and gave movement to it. moving camera forward, backward,strafing left or right works fine. When I rotate the camera the gun is not rotating along the camera. It goes out of the window. What should I do in order to rotate the gun. The gun should rotate and and face the new direction as pointed by the viewing frustum

##### Share on other sites
Hey, took me a while to figure this out, but i used this method

Draw everything in your scene, correctly with the right tansforms

such as

VIEW, view Matrix
Proj, proj Matrix
world, world Matrix

Then when it comes to your gun, just do

matrix identity (world)
matrix identity (view)
world x= 1, y=0, z=2, (position the gun right abit, and infront of camera,

VIEW, view Matrix
Proj, proj Matrix
world, world Matrix

and now your gun will be drawn last thing, and whereever the camera is, including rotation ;)

##### Share on other sites
Set gun's transformation matrix to inverse of your camera matrix or set camera matrix to identity before you render the gun. Then add some displacement to make it appear like holding it in a hand.

EDIT: ok wforl nailed it already :o)

##### Share on other sites

When I rotate the camera, the z axis before rotation becomes x axis after the rotation & x axis before rotation becomes the z axis.(I learned frm tutorials that

DirectX uses Left handed co-ordinate system in which +ve z axis is towards the screen & -ve z axis heads outwards from the screen)

Possibly this is my problem.

how to change the gun's x,y,z with respect to the rotation of viewing frustum.

• 18
• 11
• 16
• 9
• 50
• ### Forum Statistics

• Total Topics
631396
• Total Posts
2999783
×