XNA Game Development Forums
2012/05/21 20:51:53 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Search Calendar Login Register  
Pages: 1 [2]
  Print  
Author Topic: Tutorial 4 :: Moving Cameras and a Simple Input Component  (Read 8464 times)
kolorahl
Newbie
*
Offline Offline

Posts: 1


View Profile
« Reply #15 on: 2006/12/10 02:39:03 »

First on the agenda: thanks for the great tutorials. They're fairly short and get you into XNA development pretty quickly. Also thanks to Chr0n1x for the awesome post processor tutorial. I'm having far too much fun messing around with it.

Second: I'm having a problem similar to matb's. You say that the rotate + translate methods make the camera act like it would in a FPS. I was wondering if you could elaborate, because the code for rotations cause rotations around an arbitrary axis (thanks to the quaternion rotation variable). This seems like the kind of behaviour you don't want. Aren't first-person camera views suppoed to make a camera rotate around a y-axis that is always up/down (i.e. a person standing up could be called the y-axis) and that side-to-side rotations are done on this and only this axis? Similarily for the x-axis, do we not want to rotate around a somewhat absolute axis that goes from side-to-side for up/down rotations? The behaviour from the quaternion rotation definitely doesn't seem to mimick a peron's head/neck very well, which is what I think first-person camera views, at least in video games, try to emulate.

Unless I'm missing something here or didn't understand the tutorial/source code it seems like we almost want a gimbal lock camera system, using only vectors, so that we don't get a camera that can rotate itself upside-down due to rotations around an arbitrary axis.

Thanks for any clarification!
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #16 on: 2006/12/10 08:04:11 »

Since you are sending in the axis to be rotated by, you can simply control that the amount of rotation around the y axis always be zero based on the quaternions you are sending into the functions. Since this concept seems to be a tough one for people to understand, I will probably fit a second camera tutorial in that actually implements them into the demo class so you can see exactly how it all would work. I'll probably get the octree tutorial out there first before I get to this, but it should be soonish.
Logged
bkdougan
Newbie
*
Offline Offline

Posts: 1


View Profile
« Reply #17 on: 2006/12/22 14:00:49 »

I'm having the same problem as noted by others with translation+rotation causing an odd roll around the z-axis.  While I didn't find the correct way to fix the problem, I did find a quick solution that gives a working FPS type camera.

1: Create a new method in HMCamera.cs that resets rotation, something like the following.

    public void ResetRotation()
    {
        myRotation = new Quaternion(0, 0, 0, 1);
        Update();
    }


2: Comment out the transform axis line in the Rotate() method of HMCamera.cs (you could also create a separate method if desired)

    //axis = Vector3.Transform(axis,Matrix.CreateFromQuaternion(myRotation));

3: Create two global float variables in HMDemo.cs called yaw & pitch.  Edit CameraControls() method of HMDemo.cs to add the following.

    static float pitch=0,yaw=0;

    public static void CameraControls()
    {
        //Existing code

        pitch+=mouseMove.Y * -0.01f;
        yaw+=mouseMove.X * -0.01f;

        HMCameraManager.ActiveCamera.ResetRotation();
        HMCameraManager.ActiveCamera.Rotate(
            new Vector3(0, 1, 0), yaw);
        HMCameraManager.ActiveCamera.Rotate(
            new Vector3(1, 0, 0), pitch);

        //Existing code
    }


This solution has at least one odd quirk...If you invert the camera by having pitch (rotation around x-axis) >90 or <-90, the yaw (rotation around the y-axis) becomes inverted.  This isn't really an issue for me because I lock the pitch between these two points, but I thought I'd let you know.


PS, if you want to lock the height of the camera (so you don't get the noclip mode of travel), then this is a quick solution

-Create a new method in HMCamera.cs and call it from HMDemo.cs instead of Translate()

public void Translate_Lock_Y(Vector3 distance)
{
    distance = Vector3.Transform(distance,Matrix.CreateFromQuaternion(myRotation));
    distance.Y = myPosition.Y;
    myPosition += distance;
    Update();
}



Hope that helps anybody having issues with a FPS camera.  Third-person should be able to use the same idea, but edit Revolve() instead of Rotate().

Brian

« Last Edit: 2007/01/07 03:35:07 by mikeschuld » Logged
sashah
Newbie
*
Offline Offline

Posts: 1


View Profile
« Reply #18 on: 2007/01/20 09:10:02 »

Hi. Great tutorials. Just wondering how would i go about modifying the camera so that it behaves like that of a standard FPS game???

thanks
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #19 on: 2007/01/21 14:32:39 »

More advanced tutorials about imlpementing specific camera models are coming later on as there have been quite a few requests for things like that.
Logged
dzambi
Newbie
*
Offline Offline

Posts: 3


View Profile
« Reply #20 on: 2008/12/11 02:05:25 »

OK, great work in this one, but i have found something that i don't thik is intended behavior.
And have a fix for it.

It's all about your HMMouseDevice, you have the freeze property which is set to false in Initialize() method, which is bad, because the initializer
iz run at the runtime of a game (game.Run()), so if i try to set mouse.Freeze=false; before running the game, i cannot, it will be overridden by your
initialize() method, and i have to set it in the game runtime.

So, my solution was simple, i have just added a default constuctor to your HMMouseDevice class which sets Freeze to false, and removed
freezeMouse = false; line from initialize().
Logged
mikeschuld
Administrator
Sr. Member
*****
Offline Offline

Posts: 389


View Profile WWW
« Reply #21 on: 2008/12/11 10:42:13 »

Thanks! I'll play around with the change and see what I think and stick it in the pdf and svn source if it works out. Technically, the bool is default false anyway, so you could probably just take out the constructor as well and assume that it is false to start with.
Logged
Pages: 1 [2]
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Moving to DX 2.0 dll Hazy Mind 3D Engine mikeschuld 9 3207 Last post 2006/08/19 23:01:30
by Chr0n1x
Tutorial 3 :: More Rendering Complexity - Shaders and Cameras Tutorial Discussion « 1 2 3 4 » mikeschuld 52 17445 Last post 2009/12/12 17:04:40
by Mikeske
Tutorial 5 :: Building on what we've got, A Simple Skybox Tutorial Discussion mikeschuld 5 3800 Last post 2007/05/26 11:05:01
by Yubastard
Tutorial 10 :: Preparing for Object Culling, a Simple Octree Tutorial Discussion « 1 2 » mikeschuld 17 7381 Last post 2010/11/23 09:07:20
by Neil_Knight
World (Mesh) orientation and cameras Hazy Mind XNA Engine letsrock 4 2000 Last post 2007/03/13 11:09:49
by Robin Sarac
Moving the models aroung Hazy Mind XNA Engine Squeezle42 6 2478 Last post 2007/03/07 14:40:48
by Squeezle42
Mouse Input Issues Hazy Mind XNA Engine Silvo 3 2466 Last post 2008/09/15 00:10:11
by mikeschuld
Have a few questions about the Component Exception in the Engine Hazy Mind XNA Engine ckslayer22 2 1557 Last post 2009/08/06 20:13:19
by InstrallFer
About the use of static in the component manager Hazy Mind XNA Engine Sandoval 2 1333 Last post 2009/08/16 05:00:43
by Sandoval
Powered by MySQL Powered by PHP Powered by SMF 1.1.12 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.123 seconds with 19 queries.