• Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at \$59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

# Skinned Animation problem

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

19 replies to this topic

### #1mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 28 March 2013 - 06:12 AM

Hello every one ,

I am using Microsoft skinned model sample  , and my problem is Transformation problem ( Rotation).

Q : How to rotate the skinned model around when the camera move , and how to show the skinned model hand ?.( I just use camera.translation to translate the model and it's okay but it's not rotated ?? ).

Q2 : I assign a gun for  the model hand , now how to rotate the model hand + gun ?

### #2belfegor  Crossbones+   -  Reputation: 2722

Like
0Likes
Like

Posted 28 March 2013 - 06:48 AM

You want hands and gun to follow camera like in FPS games?

// offset matrix of gun/hand to reposition it where you like
matrix offMat;
offMat.rotate(...);
offMat.translate(...);

// take camera view matrix and invert it
matrix viewInvMat = camera->view;
viewInvMat.inverse();

// final transform
matrix finalMat = offMat * viewInvMat;


### #3vinnyhalts  Members   -  Reputation: 174

Like
0Likes
Like

Posted 28 March 2013 - 07:10 AM

You want hands and gun to follow camera like in FPS games?

// offset matrix of gun/hand to reposition it where you like
matrix offMat;
offMat.rotate(...);
offMat.translate(...);

// take camera view matrix and invert it
matrix viewInvMat = camera->view;
viewInvMat.inverse();

// final transform
matrix finalMat = offMat * viewInvMat;


This causes the model to behave oddly. The model lags behind where your camera is actually looking and the movement is jagged. Maybe a render target would work? I had a problem with my model's alpha a little while ago; it has since been fixed. The source I posted in this thread (http://www.gamedev.net/topic/639931-rendertargets-and-transparency) covers pretty much everything you need (both the code, and the shader).

### #4belfegor  Crossbones+   -  Reputation: 2722

Like
0Likes
Like

Posted 28 March 2013 - 07:25 AM

This causes the model to behave oddly. The model lags behind where your camera is actually looking and the movement is jagged

Thats for you maybe, for me it works fine.

I assume that model is centered at origin and "pointing" in positive Z axis. Camera view matrix must be updated before you extract view matrix and use it for gun/hand final matrix.

### #5mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 29 March 2013 - 02:52 AM

Thanks for both of you  , vinn your code is great I will try it and post a reply okay , belfegor I try it before and did not work for me :/ sorry , by the way thank you .

Q1 : How to show just the model hand  and the gun ?
Q2 : How to make the town hands catch the gun (not just one !) , is that should be done in modeling software or I can make this as transformation matrices based on View    matrices ....etc ?

Edited by mrmohadnan, 29 March 2013 - 06:15 AM.

### #6vinnyhalts  Members   -  Reputation: 174

Like
1Likes
Like

Posted 29 March 2013 - 06:22 AM

This causes the model to behave oddly. The model lags behind where your camera is actually looking and the movement is jagged

Thats for you maybe, for me it works fine.

I assume that model is centered at origin and "pointing" in positive Z axis. Camera view matrix must be updated before you extract view matrix and use it for gun/hand final matrix.

Yeah, I see what you mean. It'll be easier to just draw the model in front of the camera.

Thanks for both of you  , vinn  your code is great I will try it and post a reply okay  , belfegor I try it before and did not work for me :/ sorry , by the way thank you .

Q1 : How to show just the model hand  and the gun ?
Q2 : How to make the town hands catch the gun (not just one !) , is that should be done in modeling software or I can make this as transformation matrices based on View    matrices ....etc ?

One: You normally make a model of just the hands and the gun, then draw it in front of the screen or on a render target.

Two: You want the same model to hold and use multiple weapons? It'll probably be easier to just model the hands onto the guns, and animate it from there. So you will have to use some modeling software. Blender is free, if you don't have anything to use.

I use two models, one is the third person model; I only use it in multiplayer or for shadows. The second is the first person view. Which is just the arms and weapons.

Here is a debug photo to help you visualize how the model looks and how to draw it.

Edited by vinnyhalts, 29 March 2013 - 06:33 AM.

### #7mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 29 March 2013 - 06:33 AM

s

Edited by mrmohadnan, 29 March 2013 - 06:55 AM.

### #8mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 29 March 2013 - 06:38 AM

woooooow vin  I am so happy for your code and the result , I will post comments ok If I face any problem so pls check my post while you are here if you have time .

### #9mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 29 March 2013 - 06:42 AM

This causes the model to behave oddly. The model lags behind where your camera is actually looking and the movement is jagged

Thats for you maybe, for me it works fine.

I assume that model is centered at origin and "pointing" in positive Z axis. Camera view matrix must be updated before you extract view matrix and use it for gun/hand final matrix.

Yeah, I see what you mean. It'll be easier to just draw the model in front of the camera.

>>>>>Thanks for both of you  , vinn  your code is great I will try it and post a reply okay  , belfegor I try it before and did not work for me :/ sorry , by the way thank you .

Q1 : How to show just the model hand  and the gun ?
Q2 : How to make the town hands catch the gun (not just one !) , is that should be done in modeling software or I can make this as transformation matrices based on View    matrices ....etc ?

One: You normally make a model of just the hands and the gun, then draw it in front of the screen or on a render target.

Two: You want the same model to hold and use multiple weapons? It'll probably be easier to just model the hands onto the guns, and animate it from there. So you will have to use some modeling software. Blender is free, if you don't have anything to use.

I use two models, one is the third person model; I only use it in multiplayer or for shadows. The second is the first person view. Which is just the arms and weapons.

Here is a debug photo to help you visualize how the model looks and how to draw it.

Yeah , I got it , but for  enemy models ? I can't do the same for them , so I can't just draw their hands ( Right vinn ?) . I see  you just make a trick by drawing the Model hands ! and used person model to simulate shadows , but you don't draw the person model . Instead , you used him to draw shadow  ? ( Right Vinn ?)

Q : OK but what about the ragDoll to simulate model when dies ?

Q2 : Second , Vinn in your post  "http://www.gamedev.net/topic/639931-rendertargets-and-transparency/  " why did you use render target ? why just not draw the model with it's transformation matrices to rotate the hands ? is that hard implementation or what ?

Q3 : Can you Vinn summarize the process of rotating Model hand and the gun ?( as I am now a little bit confusing as I did not even think to draw just model hands , I am using skinned model sample from Microsoft  and I do every thing for the model (sit , run , stop ...etc) and all I need is to rotate his hands and gun while his body just follow the camera by changing it's translation matrices )

Edited by mrmohadnan, 29 March 2013 - 06:57 AM.

### #10vinnyhalts  Members   -  Reputation: 174

Like
1Likes
Like

Posted 30 March 2013 - 01:57 AM

This causes the model to behave oddly. The model lags behind where your camera is actually looking and the movement is jagged

Thats for you maybe, for me it works fine.

I assume that model is centered at origin and "pointing" in positive Z axis. Camera view matrix must be updated before you extract view matrix and use it for gun/hand final matrix.

Yeah, I see what you mean. It'll be easier to just draw the model in front of the camera.

>>>>>Thanks for both of you  , vinn  your code is great I will try it and post a reply okay  , belfegor I try it before and did not work for me :/ sorry , by the way thank you .

Q1 : How to show just the model hand  and the gun ?
Q2 : How to make the town hands catch the gun (not just one !) , is that should be done in modeling software or I can make this as transformation matrices based on View    matrices ...

.etc ?

One: You normally make a model of just the hands and the gun, then draw it in front of the screen or on a render target.

Two: You want the same model to hold and use multiple weapons? It'll probably be easier to just model the hands onto the guns, and animate it from there. So you will have to use some modeling software. Blender is free, if you don't have anything to use.

I use two models, one is the third person model; I only use it in multiplayer or for shadows. The second is the first person view. Which is just the arms and weapons.

Here is a debug photo to help you visualize how the model looks and how to draw it.

Yeah , I got it , but for  enemy models ? I can't do the same for them , so I can't just draw their hands ( Right vinn ?) . I see  you just make a trick by drawing the Model hands ! and used person model to simulate shadows , but you don't draw the person model . Instead , you used him to draw shadow  ? ( Right Vinn ?)

Q : OK but what about the ragDoll to simulate model when dies ?

Q2 : Second , Vinn in your post  "http://www.gamedev.net/topic/639931-rendertargets-and-transparency/  " why did you use render target ? why just not draw the model with it's transformation matrices to rotate the hands ? is that hard implementation or what ?

Q3 : Can you Vinn summarize the process of rotating Model hand and the gun ?( as I am now a little bit confusing as I did not even think to draw just model hands , I am using skinned model sample from Microsoft  and I do every thing for the model (sit , run , stop ...etc) and all I need is to rotate his hands and gun while his body just follow the camera by changing it's translation matrices )

Most of the time the ragdoll is tied in with the physics. BEPUPhysics is excellent and free. Take a look at their action figure and one armed man demos. They should solve your ragdoll problems.

As for the render target, I was going to use different rendering styles for the environment and weapons.

To move the hands, you would simply play the animation you want to use. So for example, when you press W to go forward (on the PC), you set the current playing animation to your walking animation. When you are idle, play the idle animation. It's less than ideal to draw an entire player's model, then put the camera behind the arms. The 3rd person model and the arms should be two different models.

So just to summarize:

1. Draw the arms on screen, in front of the camera.

2. Set the current animation based on player movement.

3. Play the animation.

Here is a pretty decent animation library: http://animationcomponents.codeplex.com/

### #11mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 30 March 2013 - 02:00 PM

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 .

### #12mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 06 April 2013 - 02:58 PM

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

            // 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;


Edited by mrmohadnan, 06 April 2013 - 03:20 PM.

### #13mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 07 April 2013 - 12:13 PM

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

### #14mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 10 April 2013 - 02:42 PM

hello any suggestion ??

### #15mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 14 April 2013 - 02:55 PM

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);

* Matrix.CreateTranslation(weaponPos);
}


Edited by mrmohadnan, 14 April 2013 - 02:56 PM.

### #16mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 15 April 2013 - 09:52 AM

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);
}


### #17mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 15 April 2013 - 11:32 AM

few pictures that show exactly what happened

this is first pos :

after rotating by 15 degree using mouse of course :

furthor rotation  degree

then :

then :

then :

### #18belfegor  Crossbones+   -  Reputation: 2722

Like
0Likes
Like

Posted 15 April 2013 - 11:51 AM

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.

### #19mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 15 April 2013 - 12:24 PM

Hello again belfegor ,

Nothing shown at all !!

### #20mrmohadnan  Members   -  Reputation: 279

Like
0Likes
Like

Posted 15 April 2013 - 12:31 PM

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);

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

}

spriteBatch = new SpriteBatch(GraphicsDevice);

}

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);
}


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS