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

Started by
2 comments, last by ravindran 16 years, 1 month ago
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
Advertisement
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 ;)
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)
Thanks for replying.

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.





This topic is closed to new replies.

Advertisement