fixed cam distance
This commit is contained in:
@@ -88,6 +88,7 @@ void Renderer::Resize(int width, int height) {
|
||||
|
||||
void Renderer::SetZoom(float zoom) {
|
||||
m_Camera.CamPos.y = std::max(1.0f, m_Camera.CamPos.y - zoom);
|
||||
m_Camera.CamDistance = std::max(1.0f, m_Camera.CamDistance - zoom);
|
||||
SetCamLook(m_Camera.CamLook);
|
||||
}
|
||||
|
||||
@@ -116,6 +117,8 @@ void Renderer::SetCamPos(const Vec3f& newPos) {
|
||||
}
|
||||
|
||||
void Renderer::SetCamLook(const Vec2f& worldPos) {
|
||||
static const float WORLD_HEIGHT = 0;
|
||||
|
||||
m_Camera.CamLook = worldPos;
|
||||
|
||||
Vec3f front = {
|
||||
@@ -124,11 +127,11 @@ void Renderer::SetCamLook(const Vec2f& worldPos) {
|
||||
std::sin(m_Camera.m_Yaw) * std::cos(m_Camera.m_Pitch)
|
||||
};
|
||||
|
||||
static const float WORLD_HEIGHT = 0;
|
||||
|
||||
float lambda = (m_Camera.CamPos.y - WORLD_HEIGHT) / front.y;
|
||||
|
||||
SetCamPos({lambda * front.x + m_Camera.CamLook.x, m_Camera.CamPos.y, lambda * front.z + m_Camera.CamLook.y});
|
||||
SetCamPos({
|
||||
-m_Camera.CamDistance * front.x + m_Camera.CamLook.x,
|
||||
-m_Camera.CamDistance * front.y + WORLD_HEIGHT,
|
||||
-m_Camera.CamDistance * front.z + m_Camera.CamLook.y
|
||||
});
|
||||
}
|
||||
|
||||
Vec2f Renderer::GetCursorWorldPos(const Vec2f& cursorPos, float windowWidth, float windowHeight) {
|
||||
|
||||
Reference in New Issue
Block a user