Animation extensions

Feb 1, 2010 at 11:37 PM
Edited Feb 1, 2010 at 11:39 PM

Back again with a new questions for you :))


I've been playing around with animation's, but i have stumbled in to a problem i don't really know how to get aroung using OX, so i was hoping you had som smart solution for me.

Iam trying to add extensions to my animations, but i dont really know how, sens i cant manipulate the local Matrix for my "weapon" component in this case
Iv'e tryed to create a new matrix from the animation hand and the bodys local, and then decomposed its postion and rotaion to use. But cant seem to get it right.

I really would prefer doing this caluclation directly to my local, but i guess that is out of the question :)

My code so far;


int handIndex = mAnimation.AnimationClip.Channels.Keys.IndexOf("L_Index1");

                Matrix[] worldTransforms = mAnimation.SkinnedBoneTransforms;
                Matrix mat = worldTransforms[handIndex] * mComponent.LocalToWorld;

                Vector3 scale;
                Quaternion rot;
                Vector3 pos;
                mat.Decompose(out scale, out rot, out pos);

                PositionWorld = pos;
                OrientationWorld = Matrix.CreateFromQuaternion(rot);



If it helps any, this is the tutorial i've been using:



A feature that would be really nice later on, would be if  it was possible to add a child component directly in the Scene-Editor, and attach to a parent bone, there by exstensions would work almost instantly.

Might be alot of work though :)



Feb 1, 2010 at 11:49 PM
Edited Feb 2, 2010 at 12:03 AM

This is an image taken with the the code stated above:

The bat is moving and rotating after the enemy, but not right. The bat is currently in his fot :)

Feb 2, 2010 at 1:38 AM

I've had plans for implementing an editor for hierarchically composting scene components for a while, but it's so much work that I've not been able to dedicate myself to it.

As to the immediate problem of mounting scene components to a specific bone of another scene component, I will extend the engine in the following way -

I/TransformableComponents will now expose 1 to many MountPoints where the first is always at the center and the rest bones (and / or other possible mount points). To mount one transformable component to another, you do the same as you currently do by setting its Parent property to the component you want to mount onto. To make it mount to a certain mount point rather than the center, set the child's MountPoint to the desired bone index + 1.

Expect this functionality in SVN very soon (likely tonight).


Feb 2, 2010 at 2:58 AM

Okay, bone mounting is in SVN. Be great if someone can test this. Just set the held object's Parent to a boned model of some sort then set held object's MountPoint property to the desired bone index PLUS 1.


Feb 2, 2010 at 3:01 AM

Er, hold on, think I spotted a bug :(


Feb 2, 2010 at 3:08 AM

Alright, I think it's working now :)


Feb 2, 2010 at 9:53 AM
Edited Feb 2, 2010 at 9:54 AM

Gotta say I love ur speed of implenting new scoure code :)

However, I do get a bugg at:

        private void RecreateDepthStencilBuffer()
            if (depthStencilBuffer != null) depthStencilBuffer.Dispose();
            resolution = CalculateResolution(engine.GraphicsDevice, SurfaceToScreenRatio);
            depthStencilBuffer = new DepthStencilBuffer(engine.GraphicsDevice, resolution.X, resolution.Y, format, msType, msQuality);

Resource size must be greater than zero.
Parameternamn: width


in: ManagedDepthStencilBuffer.cs


The problem is that "surfaceToScreenRatio", is allways zero. Any idea? or have i missed an update

Feb 2, 2010 at 2:20 PM

Ack, found the bug. I was improperly using DefaultValueAttribute for backward compatibility of ox and scene configuration files.

SVN is updated with fixes now, tho.

Feb 2, 2010 at 2:45 PM

Great, that fixed the bugg :)

Trying to get the exstension right now, but aint working quite right.


If i got ur previous post right all i have to do is:

int handIndex = mAnimation.AnimationClip.Channels.Keys.IndexOf("L_Index1");
Parent = mComponent;
MountPoint = handIndex + 1;

(mComponent is the animated component)



Fresh out of the box, without any tweaking, it isent working, the bat inherits a very tiny scale, and is positioned wrong.

A picture might be worth a bit more:


Feb 2, 2010 at 2:46 PM

>> A feature that would be really nice later on, would be if  it was possible to add a child component directly in the Scene-Editor, and attach to a parent bone, there by exstensions would work almost instantly.

You know what? I think I CAN implement this somewhat easily after all. I'll do my best :)


Feb 2, 2010 at 2:55 PM

Cool! That would really be an awsome feature :)

Feb 2, 2010 at 3:05 PM

I'm assuming that you have not placed the bat's 'mount point' in the world center of your 3D modeler. A 3D model should always have its point of rotation placed at [0,0,0] in the modeler. The engine has no way to know where you want the bat to be positioned otherwise.

Also, your character model should be scaled properly in the modeler or in the importer. In your case, its not, so you seem to have manually scaled the model down in the game. This will cause problems with any children attached to it, as you have seen.

While my code may likely have issues, you should verify your data first.


Feb 2, 2010 at 3:39 PM

Bat has both rotation, and postion at 0,0,0;
The bat you saw on the left, was just for scale comparison.


Ur' right about the scale though, the model is downscaled in the edtior, and thereby the bat inherits this smaller scale.
But still the same issue, with the bat positioned wrong.


>> While my code may likely have issues, you should verify your data first.

Dident have any attention to offend you or anything. Just to give some feedback..

Feb 2, 2010 at 3:46 PM

Not offended :)

Let me think about the issue for a moment here.


Feb 2, 2010 at 3:49 PM

>> Bat has both rotation, and postion at 0,0,0;

I doubt I've explained it properly. Actually, just send me the bat's model file and I'll verify it from here -


Feb 2, 2010 at 3:57 PM

Also, make sure that the mounted bat's Position property is [0,0,0] and its Orientation property is Matrix.Identity. This is probably already the case, but it should be verified.


Feb 2, 2010 at 4:11 PM

Yes, i've verifed that is [0,0,0] and  Matrix.Identity.
still the same issue :)

Feb 2, 2010 at 4:14 PM

The strange thing is that X and Z - led seams to be somewhat correct, but Y-led is way of down in the ground.

Feb 2, 2010 at 5:12 PM
Edited Feb 2, 2010 at 5:58 PM

I think I've narrowed down where things are going wrong and posted a query here -



Feb 3, 2010 at 3:26 PM

I might have solved the issue. I think the issue is that XNAnimation makes finding a bone in absolute space a little harder than one would expect.

Pull down the latest and test if you would :)


Feb 3, 2010 at 5:54 PM
Edited Feb 3, 2010 at 5:54 PM

Alright, Torshall and I have got bone mounting working now thanks to his helpful efforts in testing my random guesses ;)

Further, bone mounting is also enabled in the scene editor by dragging one item over another in the tree view and setting the MountPoint property. The usage is still a little inconvenient (position is retained after mounting, so you'll like have to 0 it out before or after to see the mounted object). Mounted object manipulation in the scene editor is also from the parent object's perspective. This could be overly awkward, or might actually be useful. Hard to say.

Once I polish mounting in the editor, I'll likely post up a new full release.


Feb 5, 2010 at 3:53 PM


I was completely wrong about objects inhreiting their parents scale. Not only does this limit flexibility directly, it actually "skews" the object's vertices when the child is rotated! Argh!!!

So I removed the concept of ScaleWorld entirely and the problems go away :) This is checked in SVN, and I will do yet another release soon.