How to draw a weapon in a fps
Crossbones+ - Reputation: 4083
Posted 07 January 2013 - 05:43 PM
You don't need to translate to the player position. Use a special camera that is located at the origin and draw the 1st person model there too.
Most games also clear the z buffer before drawing the hand model and set the projection matrix near/far values very close to the camera to get more precision and prevent the gun from sticking into walls and objects.
You can even experiment with the projection's fov, sometimes it looks good to choose a different fov for the 1st person model.
Crossbones+ - Reputation: 6304
Posted 07 January 2013 - 08:55 PM
You could do it as you have described, or just set the view matrix to be identity and render the model only in object space. That would position it relative to the camera, without doing the extra translation (they will likely be equal in performance, so it really is just your preference).
Have you tried doing one way or the other yet, or are you just getting ready to try it out? I would suggest trying both ways and see how they work in your engine, and then also see how flexible your engine is - can you support doing it either way? Is it a data driven solution, or is it all hard coded? I always try to push myself to make things configurable enough that solutions can be added later on, allowing for easy extensibility as you go!
Jason Zink :: DirectX MVP
Direct3D 11 engine on CodePlex: Hieroglyph 3
Direct3D Books: Practical Rendering and Computation with Direct3D 11, Programming Vertex, Geometry, and Pixel Shaders
Articles: Dual-Paraboloid Mapping Article :: Parallax Occlusion Mapping Article (original):: Fast Silhouettes Article
Games: Lunar Rift