Skip to content

Commit 01acfa6

Browse files
committed
refactor: move eigen conversion helper to lightprops
1 parent 2e9914d commit 01acfa6

3 files changed

Lines changed: 17 additions & 19 deletions

File tree

include/rendering/LightProperties.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ namespace rendering
3737
const unsigned int shadowWidth = 1024;
3838
const unsigned int shadowHeight = 1024;
3939

40+
/**
41+
* @brief Convert GLM mat4 to Eigen::Matrix4f.
42+
*
43+
* @param m GLM mat4 to convert.
44+
* @return Eigen::Matrix4f Converted Eigen matrix.
45+
*/
46+
Eigen::Matrix4f glmToEigen(const glm::mat4 &m);
47+
4048
private:
4149
void initShadowResources();
4250
};

src/rendering/LightProperties.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,12 @@ namespace rendering
6464
LOG_INFO("Shadow map initialized.");
6565
}
6666

67+
Eigen::Matrix4f toEigen(const glm::mat4 &m)
68+
{
69+
Eigen::Matrix4f e;
70+
for (int r = 0; r < 4; ++r)
71+
for (int c = 0; c < 4; ++c)
72+
e(r, c) = m[c][r]; // glm is indexed [column][row]
73+
return e;
74+
}
6775
} // namespace rendering

src/rendering/Lights.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,6 @@
55
#include <Eigen/Geometry>
66
#include <glad/glad.h>
77

8-
namespace
9-
{
10-
/**
11-
* @brief Convert GLM mat4 to Eigen::Matrix4f.
12-
*
13-
* @param m GLM mat4 to convert.
14-
* @return Eigen::Matrix4f Converted Eigen matrix.
15-
*/
16-
Eigen::Matrix4f toEigen(const glm::mat4 &m)
17-
{
18-
Eigen::Matrix4f e;
19-
for (int r = 0; r < 4; ++r)
20-
for (int c = 0; c < 4; ++c)
21-
e(r, c) = m[c][r]; // glm is indexed [column][row]
22-
return e;
23-
}
24-
}
25-
268
namespace rendering
279
{
2810

@@ -39,7 +21,7 @@ namespace rendering
3921
void DirLight::confShadowMap(Shader &shader)
4022
{
4123
// Since shader.setUniform expects Eigen matrices
42-
const Eigen::Matrix4f lightSpaceEigen = toEigen(m_lightSpaceMatrix);
24+
const Eigen::Matrix4f lightSpaceEigen = glmToEigen(m_lightSpaceMatrix);
4325
shader.setUniform("lightSpaceMatrix", lightSpaceEigen);
4426

4527
// Prepare the shadow map framebuffer

0 commit comments

Comments
 (0)