Fixed 2d render comment

Started on Anim API
This commit is contained in:
lanariel 2014-02-10 11:53:44 +01:00
parent adb273bd5b
commit d0f36302cf
7 changed files with 66 additions and 57 deletions

View File

@ -17,7 +17,8 @@ namespace Oyster
{ {
Math::Float4x4 View; Math::Float4x4 View;
Math::Float4x4 Projection; Math::Float4x4 Projection;
std::vector<Definitions::Pointlight> Lights; std::vector<Definitions::Pointlight*> Lights;
float dt=0;
} }
API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Math::Float2 resulotion) API::State API::Init(HWND Window, bool MSAA_Quality, bool Fullscreen, Math::Float2 resulotion)
@ -50,7 +51,7 @@ namespace Oyster
{ {
if(Lights.size()) if(Lights.size())
{ {
Render::DefaultRenderer::NewFrame(View, Projection, &Lights[0], (int)Lights.size()); Render::DefaultRenderer::NewFrame(View, Projection, Lights[0], (int)Lights.size());
} }
else else
{ {
@ -86,7 +87,7 @@ namespace Oyster
Model::Model* m = new Model::Model(); Model::Model* m = new Model::Model();
m->WorldMatrix = Oyster::Math::Float4x4::identity; m->WorldMatrix = Oyster::Math::Float4x4::identity;
m->Visible = true; m->Visible = true;
m->AnimationPlaying = -1; m->Animation.data.AnimationPlaying = NULL;
m->info = (Model::ModelInfo*)Core::loader.LoadResource((Core::modelPath + filename).c_str(),Oyster::Graphics::Loading::LoadDAN, Oyster::Graphics::Loading::UnloadDAN); m->info = (Model::ModelInfo*)Core::loader.LoadResource((Core::modelPath + filename).c_str(),Oyster::Graphics::Loading::LoadDAN, Oyster::Graphics::Loading::UnloadDAN);
Model::ModelInfo* mi = (Model::ModelInfo*)m->info; Model::ModelInfo* mi = (Model::ModelInfo*)m->info;
@ -127,7 +128,7 @@ namespace Oyster
SAFE_RELEASE(Core::device); SAFE_RELEASE(Core::device);
} }
void API::AddLight(Definitions::Pointlight light) void API::AddLight(Definitions::Pointlight *light)
{ {
Lights.push_back(light); Lights.push_back(light);
} }
@ -173,5 +174,13 @@ namespace Oyster
{ {
Core::loader.ReleaseResource(tex); Core::loader.ReleaseResource(tex);
} }
float API::PlayAnimation(Model::Model* m, std::wstring name,bool looping)
{
m->Animation.data.AnimationPlaying = &(*m->info->Animations.find(name)).second;
m->Animation.data.AnimationTime=0;
m->Animation.data.LoopAnimation = looping;
return m->Animation.data.AnimationPlaying->duration;
}
} }
} }

View File

@ -56,7 +56,7 @@ namespace Oyster
//! @brief Configures Renderer to process 2D graphics, data will be passed in to EndFrame() //! @brief Configures Renderer to process 2D graphics, data will be passed in to EndFrame()
static void StartGuiRender(); static void StartGuiRender();
//! @brief Renders a single GUI element using the texture provided and the Pos in the upper right corner, %based system //! @brief Renders a single GUI element using the texture provided and the Pos in the center, %based system
static void RenderGuiElement(Texture, Math::Float2 Pos, Math::Float2 Size); static void RenderGuiElement(Texture, Math::Float2 Pos, Math::Float2 Size);
//! @brief Performs light calculations, post effects and presents the scene //! @brief Performs light calculations, post effects and presents the scene
@ -71,15 +71,21 @@ namespace Oyster
static void DeleteTexture(Texture); static void DeleteTexture(Texture);
//! @brief adds a light to the scene //! @brief adds a light to the scene
static void AddLight(Definitions::Pointlight light); static void AddLight(Definitions::Pointlight* light);
//! @brief removes all lights from the scene //! @brief removes all lights from the scene
static void ClearLights(); static void ClearLights();
//! @brief Sets Options to the graphics //! @brief Sets Options to the graphics
static State SetOptions(Option); static State SetOptions(Option);
//! @brief Gets Options to the graphics //! @brief Gets Options from the graphics
static Option GetOption(); static Option GetOption();
//! @brief Starts an animation and returns the time of the animation
static float PlayAnimation(Model::Model* model, std::wstring name, bool looping = false);
//! @brief Moves all animating models forward the specified time;
static void Update(float deltaTime);
}; };
} }
} }

View File

@ -135,16 +135,16 @@ void Oyster::Graphics::Loading::UnloadDAN(void* data)
if(info->Animated) if(info->Animated)
{ {
//clean animation //clean animation
for(int a = 0; a < info->AnimationCount; ++a) for(auto a = info->Animations.begin(); a != info->Animations.end(); ++a)
{ {
for(int x = 0; x < info->Animations[a].Bones; ++x) for(int x = 0; x < (*a).second.Bones; ++x)
{ {
delete[] info->Animations[a].Keyframes[x]; delete[] (*a).second.Keyframes[x];
} }
delete[] info->Animations[a].Frames; delete[] (*a).second.Frames;
delete[] info->Animations[a].Keyframes; delete[] (*a).second.Keyframes;
} }
delete[] info->Animations; info->Animations.clear();
} }
for(UINT i =0;i<info->Material.size();++i) for(UINT i =0;i<info->Material.size();++i)
{ {
@ -364,9 +364,6 @@ void* Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[])
name[nameLength] = 0; name[nameLength] = 0;
wchar_t* wName = charToWChar(name); wchar_t* wName = charToWChar(name);
anims[a].name = std::wstring(wName);
delete[] wName;
delete name;
//read nr of bones in animation //read nr of bones in animation
ReadData(&anims[a].Bones,danFile,4); ReadData(&anims[a].Bones,danFile,4);
@ -404,11 +401,13 @@ void* Oyster::Graphics::Loading::LoadDAN(const wchar_t filename[])
ReadData(&anims[a].Keyframes[b][f].time,danFile,sizeof(double)); ReadData(&anims[a].Keyframes[b][f].time,danFile,sizeof(double));
} }
} }
}
modelInfo->AnimationCount = animationHeader.numAnims;
modelInfo->Animations = anims;
modelInfo->Animated = true;
modelInfo->Animations.insert(std::pair<std::wstring,Model::Animation>(std::wstring(wName), anims[a]));
delete[] wName;
delete name;
}
modelInfo->Animated = true;
delete[] anims;
break; break;
} }
} }

View File

@ -10,13 +10,26 @@ namespace Oyster
namespace Model namespace Model
{ {
struct ModelInfo; struct ModelInfo;
struct Animation;
struct AnimationData
{
Animation* AnimationPlaying;
float AnimationTime;
bool LoopAnimation;
};
struct AnimationPlayer
{
AnimationData data;
ModelInfo* info;
};
struct Model struct Model
{ {
ModelInfo* info; ModelInfo* info;
Oyster::Math::Float4x4 WorldMatrix; Oyster::Math::Float4x4 WorldMatrix;
bool Visible, LoopAnimation; bool Visible;
int AnimationPlaying; AnimationPlayer Animation;
float AnimationTime;
}; };
} }

View File

@ -24,7 +24,6 @@ namespace Oyster
}; };
struct Animation struct Animation
{ {
std::wstring name;
int Bones; int Bones;
int* Frames; //! Bone as index int* Frames; //! Bone as index
Frame** Keyframes; //! @brief [Bone][Frame] Frame** Keyframes; //! @brief [Bone][Frame]
@ -37,7 +36,7 @@ namespace Oyster
bool Indexed, Animated; bool Indexed, Animated;
int VertexCount, IndexCount, BoneCount, AnimationCount; int VertexCount, IndexCount, BoneCount, AnimationCount;
Bone* bones; Bone* bones;
Animation* Animations; std::map<std::wstring,Animation> Animations;
}; };
} }
} }

View File

@ -49,23 +49,6 @@ namespace Oyster
Resources::Post::Data.Unmap(); Resources::Post::Data.Unmap();
} }
Math::Matrix RecursiveBindPosRotation(int index, Model::ModelInfo* mi)
{
if(mi->bones[index].Parent == index)
return mi->bones[index].Relative;
return mi->bones[index].Relative*mi->bones[mi->bones->Parent].Relative;
}
Math::Vector4 RecursiveBindPosPosition(int index, Model::ModelInfo* mi)
{
//return Math::Vector4::standard_unit_w;
if(mi->bones[index].Parent == index)
return mi->bones[index].Relative.v[3];
return Math::Vector4(RecursiveBindPosPosition(mi->bones->Parent, mi).xyz + (mi->bones[index].Relative.v[3] * RecursiveBindPosRotation(mi->bones->Parent,mi)).xyz,1);
}
void DefaultRenderer::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection) void DefaultRenderer::RenderScene(Model::Model* models, int count, Math::Matrix View, Math::Matrix Projection)
{ {
for(int i = 0; i < count; ++i) for(int i = 0; i < count; ++i)
@ -81,7 +64,7 @@ namespace Oyster
Model::ModelInfo* info = models[i].info; Model::ModelInfo* info = models[i].info;
Definitions::AnimationData am; //final Definitions::AnimationData am; //final
if(info->Animated && models[i].AnimationPlaying != -1) if(info->Animated && models[i].Animation.data.AnimationPlaying != NULL)
{ {
cube->WorldMatrix = Math::Matrix::identity; cube->WorldMatrix = Math::Matrix::identity;
////store inverse absolut transform ////store inverse absolut transform
@ -108,11 +91,11 @@ namespace Oyster
cube2->WorldMatrix.v[3] = info->bones[b].Absolute.v[3]; cube2->WorldMatrix.v[3] = info->bones[b].Absolute.v[3];
} }
int b = 0; int b = 0;
Model::Animation A = info->Animations[models[i].AnimationPlaying]; Model::Animation A = *models[i].Animation.data.AnimationPlaying;
while(models[i].AnimationTime>A.duration) while(models[i].Animation.data.AnimationTime>A.duration)
models[i].AnimationTime -= (float)A.duration; models[i].Animation.data.AnimationTime -= (float)A.duration;
float position = models[i].AnimationTime; float position = models[i].Animation.data.AnimationTime;
for(int b = 0; b < A.Bones;++b) for(int b = 0; b < A.Bones;++b)
{ {
//find current frame //find current frame

View File

@ -23,6 +23,7 @@ Oyster::Graphics::Model::Model* m3 = NULL;
Oyster::Graphics::API::Texture t = NULL; Oyster::Graphics::API::Texture t = NULL;
Oyster::Math::Float4x4 V; Oyster::Math::Float4x4 V;
Oyster::Math::Float4x4 P; Oyster::Math::Float4x4 P;
Oyster::Graphics::Definitions::Pointlight pl;
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -169,8 +170,7 @@ HRESULT InitDirect3D()
m = Oyster::Graphics::API::CreateModel(L"crate_colonists.dan"); m = Oyster::Graphics::API::CreateModel(L"crate_colonists.dan");
m2 = Oyster::Graphics::API::CreateModel(L"T_reskinned.dan"); m2 = Oyster::Graphics::API::CreateModel(L"T_reskinned.dan");
m2->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,0,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; Oyster::Graphics::API::PlayAnimation(m2, L"Bend",true);
m2->AnimationTime = 0.0f;
//m3 = Oyster::Graphics::API::CreateModel(L"box_2.dan"); //m3 = Oyster::Graphics::API::CreateModel(L"box_2.dan");
//m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null); //m3->WorldMatrix = Oyster::Math3D::OrientationMatrix(Oyster::Math::Float3::null,Oyster::Math::Float3(0,5,0),Oyster::Math::Float3::null);
@ -183,13 +183,13 @@ HRESULT InitDirect3D()
V = V.GetInverse(); V = V.GetInverse();
Oyster::Graphics::Definitions::Pointlight pl;
pl.Color = Oyster::Math::Float3(1,0,1); pl.Color = Oyster::Math::Float3(1,0,1);
pl.Bright = 1; pl.Bright = 1;
pl.Pos = Oyster::Math::Float3(0,-20.0f,0.4f); pl.Pos = Oyster::Math::Float3(0,-20.0f,0.4f);
pl.Radius = 90; pl.Radius = 90;
Oyster::Graphics::API::AddLight(pl); Oyster::Graphics::API::AddLight(&pl);
return S_OK; return S_OK;
@ -205,7 +205,7 @@ HRESULT Update(float deltaTime)
//ma *= 50; //ma *= 50;
//ma.m44 = 1; //ma.m44 = 1;
//m2->WorldMatrix = m2->WorldMatrix * ma; //m2->WorldMatrix = m2->WorldMatrix * ma;
m2->AnimationTime += deltaTime;// * 0.5f; m2->Animation.data.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); //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; return S_OK;
} }
@ -218,7 +218,7 @@ HRESULT Render(float deltaTime)
Oyster::Graphics::API::RenderModel(*m); Oyster::Graphics::API::RenderModel(*m);
Oyster::Graphics::API::RenderModel(*m2); Oyster::Graphics::API::RenderModel(*m2);
//Oyster::Graphics::API::RenderModel(*m3); //Oyster::Graphics::API::RenderModel(*m3);
Oyster::Graphics::API::StartGuiRender(); //Oyster::Graphics::API::StartGuiRender();
Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(0.2f,0.2f)); Oyster::Graphics::API::RenderGuiElement(t,Oyster::Math::Float2(0.5f,0.5f),Oyster::Math::Float2(0.2f,0.2f));
Oyster::Graphics::API::EndFrame(); Oyster::Graphics::API::EndFrame();
@ -259,13 +259,13 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam
break; break;
//Z - //Z -
case 0x5A: case 0x5A:
m2->AnimationTime -= 0.1f; //m2->AnimationTime -= 0.1f;
if(m2->AnimationTime < 0) //if(m2->AnimationTime < 0)
m2->AnimationTime = 0; //m2->AnimationTime = 0;
break; break;
//X + //X +
case 0x58: case 0x58:
m2->AnimationTime += 0.1f; //m2->AnimationTime += 0.1f;
break; break;
} }