Anim Testing

This commit is contained in:
lanariel 2014-02-03 12:09:11 +01:00
parent 069acee8cc
commit 34f58d4140
4 changed files with 20 additions and 65 deletions

View File

@ -40,6 +40,14 @@ namespace Oyster
Resources::Deffered::PointLightsData.Unmap();
}
Math::Matrix RecursiveBindPos(int index, Model::ModelInfo* mi)
{
if(mi->bones[index].Parent == index)
return mi->bones[index].Transform;
return mi->bones[index].Transform.GetInverse() * RecursiveBindPos(mi->bones[index].Parent,mi);
}
void Basic::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection)
{
for(int i = 0; i < count; ++i)
@ -59,67 +67,14 @@ namespace Oyster
Model::ModelInfo* info = (Model::ModelInfo*)models[i].info;
Definitions::AnimationData am;
Definitions::AnimationData am; //final
if(info->Animated && models[i].AnimationPlaying != -1)
{
Definitions::AnimationData am2;
//write default data
for (int b = 0; b < info->BoneCount; b++)
for(int b = 0; b <info->BoneCount; ++b)
{
am2.animatedData[b] = info->bones[b].Transform;
am.animatedData[b] = RecursiveBindPos(b,info);
}
//loop bones in animation
am.Animated = 1;
Model::Frame Prev, Next;
models[i].AnimationTime = fmod(models[i].AnimationTime,info->Animations[models[i].AnimationPlaying].duration);
for(int x = 0; x < info->Animations[models[i].AnimationPlaying].Bones; ++x)
{
//loop frame per bone
Prev.bone.Parent = 0;
Next = Prev;
for(int y = 0; y < info->Animations[models[i].AnimationPlaying].Frames[x]; ++y)
{
///TODO replace with binary search?
Model::Frame f = info->Animations[models[i].AnimationPlaying].Keyframes[x][y];
//if we hit frame
if(models[i].AnimationTime == f.time)
{
Prev = f;
Next = f;
break;
}
//if time is larger than frame time, store frames
if(models[i].AnimationTime < f.time)
{
Next = f;
Prev = info->Animations[models[i].AnimationPlaying].Keyframes[x][y-1];
break;
}
}
//calculate interpolated bone position
//rebase model time to between prev and next
float interpoation =(models[i].AnimationTime - Prev.time) / (Next.time - Prev.time);
//interpolate
Math::Matrix Interpolated;
Math3D::InterpolateOrientation_UsingNonRigidNlerp(Prev.bone.Transform,Next.bone.Transform,interpoation, Interpolated);
//write magic to animated data
am2.animatedData[Prev.bone.Parent] = Interpolated * am2.animatedData[info->bones[Prev.bone.Parent].Parent];
//sneaky write do correct data buffer
am.animatedData[x] = (am2.animatedData[Prev.bone.Parent] * info->bones[Prev.bone.Parent].Transform.GetInverse());
}
}
else
am.Animated = 0;

View File

@ -34,7 +34,7 @@ void main( uint3 DTid : SV_DispatchThreadID, uint3 GTid : SV_GroupThreadID )
if(DTid.x & 1 && DTid.y & 1 )
{
float AmbValue = GetSSAO(ViewPos, UV, DTid.xy, GTid.xy/2);
Ambient[DTid.xy/2] = AmbValue;
Ambient[DTid.xy/2] = float4(DiffuseGlow[DTid.xy].xyz, AmbValue);
}
}

View File

@ -8,6 +8,6 @@ RWTexture2D<float4> Output;
void main( uint3 DTid : SV_DispatchThreadID )
{
//Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy] + Diffuse[DTid.xy] * Ambient[DTid.xy/2].w;// + float4(Ambient[DTid.xy/4].xyz,1); GLOW
Output[DTid.xy] = Ambient[DTid.xy/2];
Output[DTid.xy] = float4(Ambient[DTid.xy/2].xyz * Ambient[DTid.xy/2].w, 1);
//Output[DTid.xy] = Diffuse[DTid.xy] + Specular[DTid.xy];
}

View File

@ -161,7 +161,7 @@ HRESULT InitDirect3D()
m = Oyster::Graphics::API::CreateModel(L"untitled.dan");
m2 = Oyster::Graphics::API::CreateModel(L"still.dan");
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null);
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,0,0),Oyster::Math::Float3::null);
m2->AnimationPlaying = 0;
m2->AnimationTime = 0.0f;
//m3 = Oyster::Graphics::API::CreateModel(L"box_2.dan");
@ -171,7 +171,7 @@ HRESULT InitDirect3D()
P = Oyster::Math3D::ProjectionMatrix_Perspective(Oyster::Math::pi/2,1280.0f/720.0f,.1f,10000);
Oyster::Graphics::API::SetProjection(P);
V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,200,500.4f));
V = Oyster::Math3D::OrientationMatrix_LookAtDirection(Oyster::Math::Float3(0,0,-1),Oyster::Math::Float3(0,1,0),Oyster::Math::Float3(0,0,5.4f));
V = V.GetInverse();
@ -192,11 +192,11 @@ HRESULT Update(float deltaTime)
angle += Oyster::Math::pi/16 * deltaTime;
//m->WorldMatrix = Oyster::Math3D::RotationMatrix_AxisY(angle) * Oyster::Math3D::RotationMatrix_AxisX(-Oyster::Math::pi/2);
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0)*-Oyster::Math::pi/2,Oyster::Math::Float3(0,-4,0),Oyster::Math::Float3::null);
//m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(0,1,0)*-Oyster::Math::pi/2,Oyster::Math::Float3(0,-4,0),Oyster::Math::Float3::null);
Oyster::Math::Matrix ma = Oyster::Math::Matrix::identity;
ma *= 50;
ma.m44 = 1;
m2->WorldMatrix = m2->WorldMatrix * ma;
//ma *= 50;
//ma.m44 = 1;
//m2->WorldMatrix = m2->WorldMatrix * ma;
m2->AnimationTime += deltaTime * 0.5f;
//m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3(1,0,0)*-0,Oyster::Math::Float3(3,4,-1*angle),Oyster::Math::Float3::null);
return S_OK;