Turning camera with EularOrientation

Jan 17, 2010 at 10:50 AM

Hi there,

at the moment i am playing around with the GameDemo and especially with the ExamplePlayer.cs. Im trying to implement some kind of MouseControl for the camera. The camera should turn around the model (the ball) and by pressing the upkey the ball should always roll away from the camera. So far no problems, heres my code:

private void UpdateInput(GameTime gameTime)
        {
            KeyboardState keyboardState = Engine.KeyboardState;
            float walkImpulse = onGround ? groundWalkImpulse : airWalkImpulse;
            walkImpulse *= (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (keyboardState.IsKeyDown(Keys.W)) body.ApplyWorldImpulse(camera.Orientation.Forward * walkImpulse); //i've changed Vector3.Forward to the cameras forward vector
            if (keyboardState.IsKeyDown(Keys.S)) body.ApplyWorldImpulse(camera.Orientation.Backward * walkImpulse);
            if (keyboardState.IsKeyDown(Keys.A)) body.ApplyWorldImpulse(camera.Orientation.Left * walkImpulse);
            if (keyboardState.IsKeyDown(Keys.D)) body.ApplyWorldImpulse(camera.Orientation.Right * walkImpulse);
            if (keyboardState.IsKeyDown(Keys.Space)) Jump(gameTime);
        }

private void UpdateCamera()
        {
            MouseState mouseState = Engine.MouseState;
            float dX = oldMouseState.X - mouseState.X;
            float dY = oldMouseState.Y - mouseState.Y;
            cameraOrientation.Angle2 += dX/1000; //turning the camera...
            cameraOrientation.Angle1 += dY/1000;
            oldMouseState = mouseState;

            //cameraOrientation.Angle1 = cameraAngle;
            camera.Position = Component.PositionWorld - camera.Forward * 64;
        }

 

now there's a big problem. Camera turns and ball rolls always in desired direction, but i can't turn the camera all around the ball... camera movement always stopps after a certain angle...

Can you say me what to modify in order to turn the camera all around the ball?

Thanks a lot,
Fabi

Jan 17, 2010 at 11:01 AM

Oh no... Shame about me... The problem is NOT the code... It is the mouse... I can't move it further than the edge of my screen... So dX or dY are 0...-->camera won't move... Any idea how to avoid this?

engine.Game.IsMouseVisible = false;

does not work at all, mouse is visible after this...

 

Fabi

Coordinator
Jan 17, 2010 at 11:15 AM

First, let's look at the documentation for the engine.Game property -

        /// <summary>
        /// The deprecated XNA game object (see remarks).
        /// </summary>
        /// <remarks>
        /// In Ox, the XNA Game object is deprecated in almost every way. First and foremost, the
        /// XNA Game object no longer represents a "game" in the abstract sense. For example, if
        /// you need a place to put a game-related method called "ChangeLevel()", don't add it to a
        /// subclass of XNA's Game. Instead, attach it to a script object that represents the
        /// game object of your own design. For an example of such an approach, see the GameDemo
        /// project and how it represents its game abstraction with Ox.Scripts.ExampleGame.
        ///
        /// Additionally, the XNA game object is an obsolete way to store / update / and draw
        /// components. Finally, the XNA game object is an obsolete way to store and retrieve game
        /// services.
        ///
        /// Unfortunately, some external components do use the XNA Game object in some ways that
        /// are deprecated in Ox. This is generally fine and can be worked around or otherwise
        /// accomodated. But using the XNA Game object in this way is coherent only in the face of
        /// backward-compatibility constraints. Any other usage of the XNA Game object is
        /// incoherent.
        /// </remarks>
        Game Game { get; }

Now we know not to interface with the engine.Game property except for reasons of backward-compatibility. :)

So let's look at what the engine object provides directly -

        /// <summary>
        /// Is the mouse to be centered in the application display every frame?
        /// </summary>
        bool CenterMouse { get; set; }

Additionally, let's look to the gui system object for gui configuration properties -

        /// <summary>
        /// Hide the mouse.
        /// </summary>
        void HideMouse();
        /// <summary>
        /// Show the mouse.
        /// </summary>
        void ShowMouse();

Let me know if these solve the problem!

Jan 17, 2010 at 12:48 PM

Great =) That excatly solved my problem =)

Fabi