camera fixing
This commit is contained in:
@@ -88,12 +88,13 @@ 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);
|
||||
SetCamLook(m_Camera.CamLook);
|
||||
}
|
||||
|
||||
void Renderer::SetCamMovement(const Vec2f& mov) {
|
||||
m_Camera.m_Pitch -= mov.y / 50.0f;
|
||||
m_Camera.m_Yaw += mov.x / 50.0f;
|
||||
SetCamPos(m_Camera.CamPos);
|
||||
SetCamLook(m_Camera.CamLook);
|
||||
}
|
||||
|
||||
void Renderer::SetCamPos(const Vec3f& newPos) {
|
||||
@@ -114,6 +115,22 @@ void Renderer::SetCamPos(const Vec3f& newPos) {
|
||||
m_EntityShader->SetViewMatrix(m_Camera.viewMatrix);
|
||||
}
|
||||
|
||||
void Renderer::SetCamLook(const Vec2f& worldPos) {
|
||||
m_Camera.CamLook = worldPos;
|
||||
|
||||
Vec3f front = {
|
||||
std::cos(m_Camera.m_Yaw) * std::cos(m_Camera.m_Pitch),
|
||||
std::sin(m_Camera.m_Pitch),
|
||||
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});
|
||||
}
|
||||
|
||||
Vec2f Renderer::GetCursorWorldPos(const Vec2f& cursorPos, float windowWidth, float windowHeight) {
|
||||
|
||||
float relativeX = (cursorPos.x / windowWidth * 2) - 1.0f;
|
||||
|
||||
Reference in New Issue
Block a user