Skip to content

Commit

Permalink
add scale to camera
Browse files Browse the repository at this point in the history
  • Loading branch information
yknishidate committed Sep 8, 2024
1 parent e0a56ff commit 468cbdc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/reactive/Scene/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class Camera {
}
}

void setScale(float _scale) { scale = _scale; }

protected:
Type type = Type::Orbital;

Expand All @@ -95,6 +97,7 @@ class Camera {
float zNear = 0.1f;
float zFar = 1000.0f;
float fovY = glm::radians(45.0f);
float scale = 1.0f;

std::variant<FirstPersonParams, OrbitalParams> params = OrbitalParams{};
};
Expand Down
8 changes: 5 additions & 3 deletions src/Scene/Camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ auto Camera::getView() const -> glm::mat4 {
}

auto Camera::getProj() const -> glm::mat4 {
return glm::perspective(fovY, aspect, zNear, zFar);
return glm::perspective(fovY, aspect, zNear * scale, zFar * scale);
}

auto Camera::getInvView() const -> glm::mat4 {
Expand All @@ -83,12 +83,14 @@ auto Camera::getInvProj() const -> glm::mat4 {
auto Camera::getPosition() const -> glm::vec3 {
if (type == Type::FirstPerson) {
auto& _params = std::get<FirstPersonParams>(params);
return _params.position;
return _params.position * scale;
} else {
auto& _params = std::get<OrbitalParams>(params);
glm::mat4 rotX = glm::rotate(eulerRotation.x, glm::vec3(1, 0, 0));
glm::mat4 rotY = glm::rotate(eulerRotation.y, glm::vec3(0, 1, 0));
return _params.target + glm::vec3{rotY * rotX * glm::vec4{0, 0, _params.distance, 1}};
glm::vec3 position =
_params.target + glm::vec3{rotY * rotX * glm::vec4{0, 0, _params.distance, 1}};
return position * scale;
}
}

Expand Down

0 comments on commit 468cbdc

Please sign in to comment.