This project is read-only.

Newbie questions (FPS Camera + "look at" camera vector)

Apr 20, 2013 at 6:22 PM
Edited Apr 27, 2013 at 10:29 PM
At first I must say that I'm quite new to coding 3D graphics so please be understanding ;)

I'm trying to code something like 3D FPS shooter. At the beginning I've faced 2 problems:
  1. [SOLVED] I need a camera that behaves like those in FPS games -> player can rotate in any direction infinitely. I assume that it's achieved by setting mouse position to center of the screen on every mouse move right? How can I make this in Nine? I made custom camera based on FreeCamera and added setting mouse position in Update method but it works not smoothly enough. Is there any other solution to this?
  2. I need a vector that points from camera position to direction where it looks. I need this information to indicate the model which camera looks at.
Any help would me appreciated :)
Apr 22, 2013 at 8:03 AM
  1. Probably has something to do with your implementation.
  2. Try Viewport.Unproject method.
Apr 22, 2013 at 8:04 AM
Edited Apr 22, 2013 at 8:05 AM
If it is always the center of the screen, then the Forward property of the view inverse matrix is what you need for the 2nd question.
Apr 22, 2013 at 10:28 AM
Edited Apr 22, 2013 at 10:29 AM
Second question:

I've written the code that will make a ray illustrating the vector of "view" of camera:
 if(e.Key == Keys.L)    {
                var dynamicPrimitive = new DynamicPrimitive(GraphicsDevice);
                dynamicPrimitive.AddRay(new Ray(scene.GetDrawingContext().CameraPosition, ((FreeCamera)scene.GetDrawingContext().Camera).View.Forward), 2.0f,
                                        Color.Azure, 5.0f);
But when i press L ingame and step backward little bit (with no mouse move of course) the ray shows in other direction Image
The ray is always in different direction than the "view of camera". I didn't add any cameras so I assume that an instance of FreeCamera is added to scene by default.
Apr 27, 2013 at 8:08 PM
I've discovered that this piece of code behaves like on the video

ray is displayed in "reversed" angle. Can you help me with investigating this issue?