[SOLVED] Rendering First Person Weapons

Started by
3 comments, last by spartanx 17 years, 11 months ago
I cannot seem to figure this out. How can I use the up, look, and eye vectors of my camera along with it's view matrix to figure out how to place a weapon mesh for my player? I've tried a few different things, but nothing has actually worked yet. [Edited by - NickGravelyn on May 24, 2006 12:38:53 PM]
Advertisement
The camera shouldn't have anything to do with how you place models in relation to your character. You should look into either some type of scene management (scene graphs) or at least how to make an object heirarchy for your game objects. This way you can simply offset from your players' world matrix by the guns local matrix, and viola! You have the correct position.

Obviously in an FPS you won't have a character (unless you also support a 3rd person mode). So in your case you would instead, simply offset from your cameras world matrix by your guns local matrix. If you are using some sort of 3D rendering software to create the gun, just place your camera at origin, then move the gun until it looks to be in the right position. Save this position and feed it to the gun models local matrix when you load the mesh.
That sounds easy enough, but I don't know how to get the world matrix for the camera. All I have are those three vectors and the view matrix. How do I get the world matrix?
Nevermind. I found it. Just do an inverse matrix of the view matrix and I'm all set.
Your "view matrix" is probably just an inverted camera world matrix, eh?

If it is what you're describing; the view matrix transforms world coordinates to viewspace by reversing a virtual camera's world transformations (this is what is described as "moving the world about the camera", if you've heard that before). So by "unreversing" your view matrix you'll have the camera's world matrix.

Use it's forward vector to place your weapon/whatever slightly afore and you're set.

edit - Good job on figuring it out! I got distracted by a blog while writing this... :-P

This topic is closed to new replies.

Advertisement