Big update

This commit is contained in:
2026-03-07 03:14:10 +03:00
parent f8f69d3b88
commit a998771486
33 changed files with 1788 additions and 577 deletions

View File

@@ -674,24 +674,24 @@ void Model::Draw(const glm::mat4& model, SkeletonInstance* instance /*= nullptr*
}
// debug draw
if (instance)
{
glm::mat4 worldMat;
glm::mat4 worldMatParent;
for (int i = 0; i < instance->m_jointMatrices.size(); i++)
{
worldMat = model * instance->m_jointMatrices[i];
glm::vec3 worldPos = worldMat[3];
// g_debugRender->DrawAxis(worldPos);
//if (instance)
//{
// glm::mat4 worldMat;
// glm::mat4 worldMatParent;
// for (int i = 0; i < instance->m_jointMatrices.size(); i++)
// {
// worldMat = model * instance->m_jointMatrices[i];
// glm::vec3 worldPos = worldMat[3];
// // g_debugRender->DrawAxis(worldPos);
const Joint& joint = instance->m_joints[i];
if (joint.parentId != -1)
{
worldMatParent = model * instance->m_jointMatrices[joint.parentId];
g_debugRender->DrawLine(worldMat[3], worldMatParent[3], glm::vec3(1.0f, 1.0f, 1.0f));
}
}
}
// const Joint& joint = instance->m_joints[i];
// if (joint.parentId != -1)
// {
// worldMatParent = model * instance->m_jointMatrices[joint.parentId];
// g_debugRender->DrawLine(worldMat[3], worldMatParent[3], glm::vec3(1.0f, 1.0f, 1.0f));
// }
// }
//}
}
@@ -764,7 +764,7 @@ void Model::UpdateSkeletonInstance(SkeletonInstance* instance, float dt)
instance->m_time += dt;
float frameTime = 1.0f / animation.framerate;
float totalDuration = animation.numFrames * frameTime;
float totalDuration = (animation.numFrames - 1) * frameTime;
if (instance->m_time >= totalDuration && instance->m_looped)
instance->m_time = 0.0f;
@@ -772,11 +772,17 @@ void Model::UpdateSkeletonInstance(SkeletonInstance* instance, float dt)
float animationFrame = instance->m_time / frameTime;
int frameA = (int)(floor(animationFrame));
int frameB = (frameA + 1) % animation.numFrames;
float t = animationFrame - frameA;
if (!instance->m_looped && frameA >= animation.numFrames - 1)
frameA = animation.numFrames - 1;
float t = animationFrame - frameA;
if (instance->m_time >= totalDuration)
{
frameA = animation.numFrames - 1;
frameB = animation.numFrames - 1;
t = 0.0f;
}
for (int i = 0; i < instance->m_joints.size(); ++i)
{

View File

@@ -14,7 +14,7 @@
static GLuint g_VAO = 0;
static int g_NumModels = 0;
int g_NumModels = 0;
// TEMP
glm::vec3 g_viewOrigin;
@@ -77,7 +77,8 @@ Render::Render() :
m_pWindow(nullptr),
m_pGLContext(nullptr),
m_pStretchedPicVBuf(nullptr),
m_usingVAO(false)
m_usingVAO(false),
m_showStats(true)
{
m_viewMatrix = glm::identity<glm::mat4>();
m_projectionMatrix = glm::identity<glm::mat4>();
@@ -296,6 +297,9 @@ void Render::RenderScene() {
void Render::RenderStats()
{
if (!m_showStats)
return;
char buffer[256];
snprintf(buffer, sizeof(buffer), "FPS: %.1f", ImGui::GetIO().Framerate);
@@ -343,6 +347,11 @@ void Render::LoadSceneXML(const char* filename)
g_sceneManager->loadScene(filename);
}
void Render::ToggleShowStats()
{
m_showStats = !m_showStats;
}
//IRender* GetRender()
//{
// return g_render;

View File

@@ -36,6 +36,8 @@ public:
SDL_GLContext GetGLContext() { return m_pGLContext; }
void ToggleShowStats();
private:
glm::mat4 m_viewMatrix;
glm::mat4 m_projectionMatrix;
@@ -46,6 +48,7 @@ private:
GPUBuffer* m_pStretchedPicVBuf;
bool m_usingVAO;
bool m_showStats;
};
extern Render* g_render;

View File

@@ -18,6 +18,9 @@
#include <pugixml.hpp>
extern int g_NumModels;
static bool g_debugRenderScene = false;
static std::string getFileExtension(const std::string& filename)
{
size_t whereIsDot = filename.find_last_of('.');
@@ -398,7 +401,8 @@ void SceneManager::renderScene(const glm::mat4& cameraTranslation)
(*it)->RenderObjects();
g_debugRender->DrawBoundingBox((*it)->GetBoundingBox(), glm::vec3(1.0f));
if (g_debugRenderScene)
g_debugRender->DrawBoundingBox((*it)->GetBoundingBox(), glm::vec3(1.0f));
}
}
@@ -482,6 +486,11 @@ const char* SceneManager::getSceneName()
return m_sceneName.c_str();
}
void SceneManager::toggleDebugRender()
{
g_debugRenderScene = !g_debugRenderScene;
}
// SceneStaticMesh
SceneStaticMesh::SceneStaticMesh() :
@@ -818,7 +827,7 @@ void R_SceneStaticMesh_BindShader(const glm::mat4& worldMatrix, Texture2D* albed
{
glm::vec4 lightPos = glm::vec4(1.0f, 1.0f, 1.0f, 0.0f);
g_debugRender->DrawAxis(glm::vec3(lightPos));
// g_debugRender->DrawAxis(glm::vec3(lightPos));
Camera* camera = g_cameraManager.GetActiveCamera();
if (camera)
@@ -853,4 +862,6 @@ void SceneStaticMesh::RenderObjects()
R_SceneStaticMesh_BindShader(s_identity, m_albedoTexture);
g_renderDevice->DrawArrays(PT_TRIANGLES, 0, m_vbcount);
g_NumModels++;
}

View File

@@ -43,6 +43,9 @@ public:
// \brief Get current scene name.
const char* getSceneName();
// \brief Toggle an debug rendering.
void toggleDebugRender();
private:
void LoadSceneXML(const char* filename);
void loadSkybox(const char*);