Skip to content

Commit 9d99177

Browse files
committed
🎨 Improve camera rotation render
1 parent 0f4e381 commit 9d99177

File tree

7 files changed

+29955
-30012
lines changed

7 files changed

+29955
-30012
lines changed

‎include/graphics/material.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Material {
3131

3232
void setTexture(MaterialTextureType type, const std::string &texturePath, const GLint wrapMode = GL_REPEAT,
3333
const GLint minFilter = GL_LINEAR_MIPMAP_LINEAR, const GLint magFilter = GL_LINEAR) {
34-
textures[type] = std::make_shared<Texture>(texturePath);
34+
textures[type] = std::make_shared<Texture>(texturePath, wrapMode, minFilter, magFilter);
3535
}
3636

3737
void setPBRTexture(const std::string &pbrTextureDir, const GLint wrapMode = GL_REPEAT,

‎include/graphics/mtlLoader.hpp

-70
This file was deleted.

‎include/graphics/renderManager.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class RenderManager {
5151

5252
auto cameraMaterial = std::make_shared<Material>(glm::vec3(1.0f), glm::vec3(0.6f), glm::vec3(0.5f), 32.0f);
5353
cameraMaterial->setShader(defaultShader);
54-
cameraMaterial->setTexture(MaterialTextureType::Diffuse, "resources/textures/camera.jpg");
54+
cameraMaterial->setTexture(MaterialTextureType::Diffuse, "resources/textures/camera.jpg"); // -z and y
5555
MaterialManager::getInstance().saveMaterial(cameraMaterial, "camera");
5656
}
5757

‎include/objects/camera.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class Camera final : public GameObject, public InputObserver {
1818
const float pitch = 0.0f) : front(glm::vec4(0.0f, 0.0f, -1.0f, 0.0f)), isFreeCam(true) {
1919
this->yaw = glm::radians(yaw);
2020
this->pitch = glm::radians(pitch);
21-
transform = std::make_shared<Transform>(position, glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(90.0f, 0.0f, 0.0f));
21+
22+
transform = std::make_shared<Transform>(position, glm::vec3(0.5f, 0.5f, 0.5f), glm::vec3(pitch, yaw, 0.0f));
2223
addComponent(transform);
2324

2425
addComponent(std::make_shared<Renderer>(MeshManager::getInstance().getMesh("resources/models/camera.obj"),
@@ -104,6 +105,7 @@ class Camera final : public GameObject, public InputObserver {
104105
const glm::quat yawQuat = glm::angleAxis(yaw, glm::vec3(0, 1, 0));
105106

106107
const glm::quat orientation = yawQuat * pitchQuat;
108+
this->transform->setRotation(orientation);
107109

108110
constexpr glm::vec4 defaultFront(0.0f, 0.0f, -1.0f, 0.0f);
109111
const glm::vec4 front = orientation * defaultFront;

‎include/transform.hpp

+12
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,22 @@ class Transform final : public Component {
2323
saveState();
2424
}
2525

26+
Transform(const glm::vec3 &position, const glm::quat &quat) :
27+
position(position, 1.0f), scale(1.0f), rotation(quat) {
28+
saveState();
29+
}
30+
2631
Transform(const glm::vec3 &position, const glm::vec3 &scale, const glm::vec3 &eulerRotation) :
2732
position(position, 1.0f), scale(scale) {
2833
setRotation(eulerRotation);
2934
saveState();
3035
}
3136

37+
Transform(const glm::vec3 &position, const glm::vec3 &scale, const glm::quat &quat) :
38+
position(position, 1.0f), scale(scale), rotation(quat) {
39+
saveState();
40+
}
41+
3242
void saveState() {
3343
previousPosition = position;
3444
previousScale = scale;
@@ -47,6 +57,8 @@ class Transform final : public Component {
4757

4858
void setRotation(const glm::vec3 &eulerRotation) { rotation = glm::quat(glm::radians(eulerRotation)); }
4959

60+
void setRotation(const glm::quat &rotation) { this->rotation = rotation; }
61+
5062
[[nodiscard]] glm::mat4 getModelMatrix() const {
5163
glm::mat4 model = math::translateMatrix(position.x, position.y, position.z);
5264
model *= glm::toMat4(rotation);

0 commit comments

Comments
 (0)