Archived

This topic is now archived and is closed to further replies.

skeletal animation with matrices

This topic is 5091 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to get skeletal animation wirking with normal matrices and not quaterions.... is this possible? i think it should be, i have done a shader with some code but cant manage to get it to work. I will post code if it will help: shader: [cpp] float4x4 worldViewProj : WorldViewProjection; float4x4 boneMatrices[24]; texture testTexture; // This texture will be loaded by the application sampler Sampler = sampler_state { Texture = (testTexture); MipFilter = LINEAR; MinFilter = LINEAR; MagFilter = LINEAR; }; struct vertex { float3 position : POSITION; float3 normal : NORMAL; float2 texture0 : TEXCOORD0; float4 weight : BLENDWEIGHT; float4 boneId : BLENDINDICES; }; struct fragment { float4 position : POSITION; float3 normal : TEXCOORD1; float2 texture0 : TEXCOORD0; }; struct pixel { float4 color : COLOR; }; float4 skinPoint( inout float4 io_value, float4x4 blendMats[24], float4 indices, float4 weights) { int i; float4 incoming_io_value = io_value; for( i = 0; i < 4; i++ ) { io_value += mul( blendMats[ indices ], incoming_io_value) * weights[i]; } return io_value; } fragment vertexSkin( vertex IN ) { fragment OUT; float4 pos = float4( IN.position, 1); skinPoint( pos, boneMatrices, IN.boneId, IN.weight); OUT.position = mul( worldViewProj, pos ); OUT.texture0 = IN.texture0; OUT.normal = IN.normal; return OUT; } pixel fragmentSkin( fragment IN ) { pixel OUT; OUT.color = tex2D( Sampler, IN.texture0 ); return OUT; } technique Technique0 { pass Pass0 { VertexShader = compile vs_1_1 vertexSkin(); //PixelShader = compile ps_1_1 fragmentSkin(); } } [/cpp] skeletal code (note: i am only doing the first bone ATM, as my model only has one bone for testing purposes): [cpp] D3DXMATRIXA16 parent; D3DXMATRIXA16 matRotation; D3DXMATRIXA16 matTranslation; Transform(); D3DXMATRIX viewProjection; viewProjection = matWorld * ENGINE.GetRenderMgr()->GetCamera()->matView * ENGINE.GetRenderMgr()->GetCamera()->matProjection; D3DXMatrixIdentity( &parent ); D3DXMatrixIdentity( &boneArray[i] ); D3DXMatrixRotationYawPitchRoll( &matRotation, boneKeys[i].rotation.x, boneKeys[i].rotation.y, boneKeys[i].rotation.z); D3DXMatrixMultiply( &boneArray[i], &boneArray[i], &matRotation ); [/cpp] so this causes some animation, but its not correct, you can see the rotation happening, but it seems to be scaled smaller than larger causing some weird results! ideas welcome. here is a link to a bunch of screen shots with it being rotated and you can see the funny affect: http://www.users.on.net/amathews/skeletal.rar

Share this post


Link to post
Share on other sites
perhaps you should check how they did it for the SDK "skinmesh" sample. it uses 4x4 matrices.

if you''re getting weird scaling, i would assume that some transforms may be happening in the wrong order, or that you''re assuming some similarity between quaternions and matrices that just plain isnt there. i know i had trouble learning to use quaternions after assuming that 4d rotation vectors would be axis, angle (which quats are deifnitely not )

Share this post


Link to post
Share on other sites
problem with the dx code is they use the mesh classes or thier animation classes which does most of the work behind the scenes :-/ i looked into it anyway, but with little success, seems they do all the matrix stuff behind the scenes.

Share this post


Link to post
Share on other sites
i managed to get it sort of working, but when i rotate a bone it wants to rotate around the pivot point, not around the bone, and when i try to do a translation to try to get it to rotate around the bone, funkey stuff occurs

Share this post


Link to post
Share on other sites