Skip to content

Commit 8c2262a

Browse files
committed
clean up scroll callback, rotate camera
1 parent 2b2d06b commit 8c2262a

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

Model-Modifier/src/main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,12 @@ int main()
275275
}
276276

277277
// adjust FOV using vertical scroll
278-
camera.m_FOV -= Input::GetScrollY() * 2.0f;
279-
camera.m_FOV < 20.0f ? camera.m_FOV = 20.0f : NULL;
280-
camera.m_FOV > 110.0f ? camera.m_FOV = 110.0f : NULL;
281-
projMatrix = glm::perspective(glm::radians(camera.m_FOV), aspectRatio, 0.1f, 1000.0f);
282-
Input::ResetScroll();
278+
if (Input::GetScrollY() != 0)
279+
{
280+
camera.changeFOV(Input::GetScrollY());
281+
projMatrix = glm::perspective(glm::radians(camera.m_FOV), aspectRatio, 0.1f, 1000.0f);
282+
Input::ResetScroll();
283+
}
283284

284285
////////// clearing per frame //////////
285286
glClearColor(0.80f, 0.90f, 0.96f, 1.00f);

Model-Modifier/src/renderer/Camera.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ void Camera::MoveCamera(glm::vec3 direction, float speed)
2020
void Camera::RotateCamera(float deltaPitch, float deltaYaw, float deltaDist)
2121
{
2222
GetYawPitchDist(); // set these properly first
23-
m_Pitch += deltaPitch;
23+
{ // makes sure the pitch doesn't flip
24+
if (m_Pitch + deltaPitch > 1.5f)
25+
m_Pitch = 1.5f;
26+
else if (m_Pitch + deltaPitch < -1.5f)
27+
m_Pitch = -1.5f;
28+
else
29+
m_Pitch += deltaPitch;
30+
}
2431
m_Yaw += deltaYaw;
2532
m_Dist += deltaDist;
2633

@@ -31,6 +38,13 @@ void Camera::RotateCamera(float deltaPitch, float deltaYaw, float deltaDist)
3138
SetViewMatrix();
3239
}
3340

41+
void Camera::changeFOV(float scrollY)
42+
{
43+
m_FOV -= scrollY * 2.0f;
44+
m_FOV < 20.0f ? m_FOV = 20.0f : NULL;
45+
m_FOV > 110.0f ? m_FOV = 110.0f : NULL;
46+
}
47+
3448
glm::vec3 Camera::GetPosOnSphere()
3549
{
3650
return m_Dist * glm::vec3

Model-Modifier/src/renderer/Camera.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class Camera
2121
float m_FOV;
2222

2323
public:
24-
Camera();
2524
Camera(float pitch, float yaw, float distance);
2625
~Camera();
2726

2827
void MoveCamera(glm::vec3 direction, float speed);
2928
void RotateCamera(float deltaPitch, float deltaYaw, float deltaDist);
29+
void changeFOV(float scrollY);
3030

3131
glm::vec3 GetPosOnSphere();
3232
void GetYawPitchDist();

0 commit comments

Comments
 (0)