Skinned Animation problem

Started by
18 comments, last by MohammadAhmed 11 years ago

wooooow , thank you Vinn , I will never forget your help :) , I done using BEPU , now it's time to check out Animation library , so I will post questions later .

Advertisement

still have some problems with rendering the hands in front of the camera ! ,

bmudn5ir9fjq75z4g.jpg


            // Update Transformation Data of CharachterController
            CharachterControllerPosition = camera.Position;
            CharachterControllerRotaion = Matrix.CreateFromYawPitchRoll(cci.Camera.Yaw,cci.Camera.Pitch,0);
            CharachterControllerWorldTransform = cci.CharacterController.Body.WorldTransform;
            #endregion

            // Update Player
            Matrix translatePlayer = Matrix.CreateTranslation(camera.Position);
            Matrix scalePlayer = Matrix.CreateScale(0.08f);
            Matrix rotatePlayer = Matrix.CreateFromYawPitchRoll(cci.Camera.Yaw, cci.Camera.Pitch, 0) ;
            staticModel.Transform = scalePlayer * rotatePlayer * translatePlayer;

the hands not front of the camera , it just move with the camera and rotate but not in front of the camera

hello any suggestion ??

hello again ! ,

I am very happy to be with experienced game developers , so I hope some one try to see the problem in my code , as the hands associated with the gun did not positoned in front of camera !!! , I tried out a lot of ways to figure it out but ?? here is the code ????????????????????? :/ I hate this code very much !


           
{..
..
...
..
.
            // Update player Weapon and hands
            weaponWorldMatrix = WeaponWorldMatrix(0.45f, -0.75f, 1.65f);
            staticModel.Transform = weaponWorldMatrix;
            /*
            Vector3 forward = cameraa.ViewMatrix.Forward * new Vector3(40);
            Matrix translatePlayer = Matrix.CreateTranslation(cameraa.ViewMatrix.Translation + forward);
            Matrix scalePlayer = Matrix.CreateScale(10f);
            Matrix rotatePlayer = Matrix.Invert(Matrix.CreateFromYawPitchRoll(cameraa.Yaw, cameraa.Pitch, 0));
            staticModel.Transform = (scalePlayer * rotatePlayer * translatePlayer );
            */
}

        /// <summary>
        /// Calculates the world transformation matrix for the weapon attached
        /// to the FirstPersonCamera. The weapon moves along with the camera.
        /// The offsets are to ensure the weapon is slightly in front of the
        /// camera and to one side.
        /// </summary>
        /// <param name="xOffset">How far to position the weapon left or right.</param>
        /// <param name="yOffset">How far to position the weapon up or down.</param>
        /// <param name="zOffset">How far to position the weapon in front or behind.</param>
        /// <returns>The weapon world transformation matrix.</returns>
        public Matrix WeaponWorldMatrix(float xOffset, float yOffset, float zOffset)
        {
            Vector3 weaponPos = cci.Camera.Position;

            weaponPos = cci.Camera.WorldMatrix.Translation + new Vector3(10, -10, 10);

            return Matrix.CreateRotationX(MathHelper.ToRadians(cci.Camera.Yaw))
                    * Matrix.CreateRotationY(MathHelper.ToRadians(cci.Camera.Pitch))
                    * Matrix.CreateTranslation(weaponPos);
        }

I don't know if the problem was from my Camera implementation :


        public void Update(float dt, KeyboardState keyboardInput, MouseState mouseInput)
        {
            Yaw += (200 - mouseInput.X) * dt * .32f;
            Pitch += (200 - mouseInput.Y) * dt * .32f;


            WorldMatrix = Matrix.CreateFromAxisAngle(Vector3.Right, Pitch) * Matrix.CreateFromAxisAngle(Vector3.Up, Yaw);

            WorldMatrix = WorldMatrix * Matrix.CreateTranslation(Position);
            ViewMatrix = Matrix.Invert(WorldMatrix);
        }

few pictures that show exactly what happened

this is first pos :
8x6lda07jcnf3na6g.jpg


after rotating by 15 degree using mouse of course :

dhk5taecpo6k6mp6g.jpg

furthor rotation degree

cl22ixerwedx9z26g.jpg

then :
cl22ixerwedx9z26g.jpg

then :
fmiu6ck02c67fdv6g.jpg

then :

384bp84n3a6g32h6g.jpg

What it looks like if you put it like this:

public Matrix WeaponWorldMatrix(float xOffset, float yOffset, float zOffset)
{
    return Matrix.Invert(cci.Camera.ViewMatrix) * Matrix.CreateTranslation(new Vector3(10, -10, 10));
}

I don't know C#/XNA syntax so this might not compile.

Hello again belfegor ,

Nothing shown at all !!

This is full code for my camera ( I think it's the problem !! )

Camera.cs



    /// <summary>
    /// Simple camera class for moving around the demos area.
    /// </summary>
    public class Camera : DrawableGameComponent
    {
        /// <summary>
        /// Gets or sets the position of the camera.
        /// </summary>
        public Vector3 Position { get; set; }

        public Matrix projection;

        private float yaw;
        private float pitch;
        
        /// <summary>
        /// Gets or sets the yaw rotation of the camera.
        /// </summary>
        public float Yaw
        {
            get { return yaw; }
            set { yaw = MathHelper.WrapAngle(value); }
        }

        /// <summary>
        /// Gets or sets the pitch rotation of the camera.
        /// </summary>
        public float Pitch
        {
            get { return pitch; }
            set
            {
                pitch = value;
                if (pitch > MathHelper.PiOver2 * .99f)
                    pitch = MathHelper.PiOver2 * .99f;
                else if (pitch < -MathHelper.PiOver2 * .99f)
                    pitch = -MathHelper.PiOver2 * .99f;
            }
        }

        /// <summary>
        /// Gets or sets the speed at which the camera moves.
        /// </summary>
        public float Speed { get; set; }

        /// <summary>
        /// Gets the view matrix of the camera.
        /// </summary>
        public Matrix ViewMatrix { get; private set; }

        /// <summary>
        /// Gets or sets the projection matrix of the camera.
        /// </summary>
        public Matrix ProjectionMatrix { get; set; }

        /// <summary>
        /// Gets the world transformation of the camera.
        /// </summary>
        public Matrix WorldMatrix { get; private set; }

        /// <summary>
        /// Whether or not to use the default free-flight camera controls.
        /// Set to false when using vehicles or character controllers.
        /// </summary>
        public bool UseMovementControls = true;

        /// <summary>
        /// Creates a camera.
        /// </summary>
        /// <param name="pos">Initial position of the camera.</param>
        /// <param name="s">Speed of the camera per second.</param>
        /// <param name="p">Initial pitch angle of the camera.</param>
        /// <param name="y">Initial yaw value of the camera.</param>
        public Camera(Game game, Vector3 pos, float s, float p, float y) : base (game)
        {

            float aspectRatio = (float)Game.Window.ClientBounds.Width /
                                (float)Game.Window.ClientBounds.Height;
            // 45 degrees
            float fieldOfView = MathHelper.PiOver4;

            projection = Matrix.CreatePerspectiveFieldOfView(fieldOfView, aspectRatio, 0.1f, 7000);

            Position = pos;
            Speed = s;
            Yaw = y;
            Pitch = p;
            ProjectionMatrix = projection;

            //rayCastFilter = RayCastFilter;
        }

        /// <summary>
        /// Moves the camera forward.
        /// </summary>
        /// <param name="distance">Distance to move.</param>
        public void MoveForward(float distance)
        {
            Position += WorldMatrix.Forward * distance;
        }

        /// <summary>
        /// Moves the camera to the right.
        /// </summary>
        /// <param name="distance">Distance to move.</param>
        public void MoveRight(float distance)
        {
            Position += WorldMatrix.Right * distance;
        }

        /// <summary>
        /// Moves the camera up.
        /// </summary>
        /// <param name="distance">Distanec to move.</param>
        public void MoveUp(float distance)
        {
            Position += new Vector3(0, distance, 0);
        }


        /// <summary>
        /// Updates the state of the camera.
        /// </summary>
        /// <param name="dt">Time since the last frame in seconds.</param>
        /// <param name="keyboardInput">Input for this frame from the keyboard.</param>
        /// <param name="oldMouseInput">Input from the previous frame from the mouse.</param>
        /// <param name="mouseInput">Input for this frame from the mouse.</param>

        public void Update(float dt, KeyboardState keyboardInput, MouseState mouseInput)
        {
            Yaw += (200 - mouseInput.X) * dt * .32f;
            Pitch += (200 - mouseInput.Y) * dt * .32f;


            WorldMatrix = Matrix.CreateFromAxisAngle(Vector3.Right, Pitch) * Matrix.CreateFromAxisAngle(Vector3.Up, Yaw);

            WorldMatrix = WorldMatrix * Matrix.CreateTranslation(Position);
            ViewMatrix = Matrix.Invert(WorldMatrix);
        }
    }

Here my modelManager.cs


// this methode updated , by calling it in the main Update methode inside my game :

class ModelManager{

.
.
.
.

        
public void Update(GameTime gameTime, KeyboardState KeyboardInputt, 
            KeyboardState PreviousKeyboardInputt, MouseState MouseInput)
        {

            // Update player Weapon and hands
            //weaponWorldMatrix = WeaponWorldMatrix(0.45f, -0.75f, 1.65f);
            //staticModel.Transform = weaponWorldMatrix;
            //staticModel.model.CopyAbsoluteBoneTransformsTo(weaponTransforms);

            
            Vector3 forward = cci.Camera.WorldMatrix.Forward + new Vector3(5, -5, 0);
            Matrix translatePlayer = Matrix.CreateTranslation(cci.Camera.Position + cci.Camera.WorldMatrix.Forward + forward);
            Matrix scalePlayer = Matrix.CreateScale(0.05f);
            Matrix rotatePlayer = Matrix.Invert(Matrix.CreateFromAxisAngle(cci.Camera.ViewMatrix.Right,
                cci.Camera.Pitch) * Matrix.CreateFromAxisAngle(cci.Camera.ViewMatrix.Up, cci.Camera.Yaw));
            staticModel.Transform = scalePlayer * rotatePlayer * translatePlayer ;
            
        }
.
.
.
.
}

This is the game.cs which is the main class ,


protected override void Initialize() {

            camera = new Camera(this, new Vector3(0, 50, 50), 1000, 0, 0);

            Components.Add(camera);

            modelManager = new ModelManager(this, camera, GraphicsDevice);

        }

        protected override void LoadContent() {
            
            spriteBatch = new SpriteBatch(GraphicsDevice);

            modelManager.LoadContent(Content);

            base.LoadContent();
        }



        protected override void Update(GameTime gameTime) {

            graphics.GraphicsDevice.RasterizerState = RasterizerState.CullNone;

            AMInput_PreviousKeyboardInput = AMInput_KeyboardInput;
            AMInput_KeyboardInput = Keyboard.GetState();

            AMInput_MouseInput = Mouse.GetState();

.
.
.
.
            else if (state == GameState.game){
.
.
.

                camera.Update((float)gameTime.ElapsedGameTime.TotalSeconds, AMInput_KeyboardInput, AMInput_MouseInput);

                // Updating Modesl data such as Transformations
                modelManager.Update(gameTime, AMInput_KeyboardInput, AMInput_PreviousKeyboardInput , AMInput_MouseInput);
.
.
.
.
.
.


            base.Update(gameTime);
        }

This topic is closed to new replies.

Advertisement