Sign in to follow this  
ravindran

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

Recommended Posts

ravindran    122
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 this post


Link to post
Share on other sites
wforl    169
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 this post


Link to post
Share on other sites
MaR_dev    154
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 this post


Link to post
Share on other sites
ravindran    122
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.





Share this post


Link to post
Share on other sites

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