96 lines
2.9 KiB
C++
96 lines
2.9 KiB
C++
|
|
#include <LearnOpenGL/LearnOpenGL.h>
|
|
|
|
#include <rewindow/types/window.h>
|
|
#include "LearnOpenGL/Grid.h"
|
|
|
|
Matrix4x4 animation_model_matrix = Matrix4x4(1.f);
|
|
Matrix4x4 projection_matrix = Matrix4x4::OpenGLPerspProjLH(0, 1, 1, 1);
|
|
|
|
class SkeletalAnimationDemo : public ReWindow::RWindow
|
|
{
|
|
public:
|
|
Model ourModel;
|
|
Animation animation;
|
|
Animator animator;
|
|
Shader shader;
|
|
Shader skeletal_animation_shader;
|
|
Camera3D camera;
|
|
SkeletalAnimationDemo() : ReWindow::RWindow("Skeletal Animation Demo", 1024, 768, RenderingAPI::OPENGL)
|
|
{
|
|
|
|
}
|
|
void InitGraphics()
|
|
{
|
|
Matrix4x4 view_matrix = camera.GetViewMatrix();
|
|
//animation = Animation("");
|
|
shader = Shader(std::string("resources/shaders/basic.vert.glsl"), "resources/shaders/basic.frag.glsl");
|
|
//shader.use();
|
|
shader.setMat4("projection", projection_matrix);
|
|
shader.setMat4("view", view_matrix);
|
|
shader.setMat4("model", Matrix4x4(1.f));
|
|
|
|
// Setup skeletal animation shader
|
|
animation_model_matrix = animation_model_matrix.Translate({0.01f, 0.01f, 0.01f});
|
|
skeletal_animation_shader = Shader(std::string("resources/shaders/skeletal_animation.vert.glsl"), "resources/shaders/textured.frag.glsl");
|
|
skeletal_animation_shader.setMat4("projection", projection_matrix);
|
|
skeletal_animation_shader.setMat4("view", view_matrix);
|
|
skeletal_animation_shader.setMat4("model", animation_model_matrix);
|
|
|
|
Grid grid{};
|
|
|
|
// TODO: support loading fbx files
|
|
ourModel = Model("resources/entity/Wolf_One_dae.dae");
|
|
|
|
unsigned int texture_id;
|
|
auto res = Texture();
|
|
|
|
|
|
camera = Camera3D();
|
|
animation = Animation("resources/entity/Wolf_One_dae.dae", &ourModel);
|
|
animator = Animator(&animation);
|
|
}
|
|
void OnRefresh(float dt) override
|
|
{
|
|
std::cout << dt << std::endl;
|
|
|
|
animator.UpdateAnimations(1.f/60.f);
|
|
|
|
glClearColor(0.1f, 0.05f, 0.05f, 1.f);
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
//shader.use();
|
|
|
|
|
|
//shader.setMat4("projection", Projection);
|
|
//shader.setMat4("view", View);
|
|
auto transforms = animator.GetFinalBoneMatrices();
|
|
for (int i = 0; i < transforms.size(); ++i)
|
|
shader.setMat4("finalBoneMatrices[" + std::to_string(i) + "]", transforms[i]);
|
|
Matrix4x4 model = Matrix4x4(1.f);
|
|
model = model.Translate(Vector3(0.f, -0.4f, 0.f));
|
|
model = model.Scale({.5f, .5f, .5f});
|
|
shader.setMat4("model", model);
|
|
ourModel.Draw(shader);
|
|
|
|
glSwapBuffers();
|
|
}
|
|
protected:
|
|
private:
|
|
|
|
};
|
|
|
|
int main()
|
|
{
|
|
auto* window = new SkeletalAnimationDemo();
|
|
window->setRenderer(RenderingAPI::OPENGL);
|
|
window->Open();
|
|
gladLoadGL();
|
|
window->InitGraphics();
|
|
|
|
while (window->isAlive())
|
|
{
|
|
window->pollEvents();
|
|
window->refresh();
|
|
}
|
|
return 0;
|
|
} |