Working on camera positioning

This commit is contained in:
Vladislav Khorev 2026-06-15 12:06:03 +03:00
parent 020f31e1e4
commit 9f4d60036d
3 changed files with 17 additions and 17 deletions

View File

@ -15,7 +15,7 @@ namespace ZL {
using std::max; using std::max;
#endif #endif
constexpr float DEFAULT_ZOOM = 6.f; constexpr float DEFAULT_ZOOM = 8.f;
class Environment { class Environment {
public: public:

View File

@ -22,17 +22,8 @@
namespace ZL namespace ZL
{ {
/* static const float zoomMin = 6.0f;
void set_Texture(Character& npc, const TextureDataStruct& texture) static const float zoomMax = 20.0f;
{
auto tt = std::make_shared<Texture>(texture);
npc.setTexture(tt);
}
void set_Texture(Character& npc, const std::string& meshName, const TextureDataStruct& texture)
{
auto tt = std::make_shared<Texture>(texture);
npc.setTexture(meshName, tt);
}*/
#ifdef EMSCRIPTEN #ifdef EMSCRIPTEN
const char* CONST_ZIP_FILE = "resources.zip"; const char* CONST_ZIP_FILE = "resources.zip";
@ -945,8 +936,11 @@ namespace ZL
else if (event.wheel.y < 0) { else if (event.wheel.y < 0) {
Environment::zoom += zoomstep; Environment::zoom += zoomstep;
} }
if (Environment::zoom < zoomstep) { if (Environment::zoom < zoomMin) {
Environment::zoom = zoomstep; Environment::zoom = zoomMin;
}
if (Environment::zoom > zoomMax) {
Environment::zoom = zoomMax;
} }
std::cout << "Current zoom: " << Environment::zoom << std::endl; std::cout << "Current zoom: " << Environment::zoom << std::endl;
// Tutorial step3 → step4: any mouse-wheel scroll counts as "zoom gesture". // Tutorial step3 → step4: any mouse-wheel scroll counts as "zoom gesture".
@ -1225,8 +1219,9 @@ namespace ZL
float newZoom = pinchStartZoom * (pinchStartDistance / dist); float newZoom = pinchStartZoom * (pinchStartDistance / dist);
// Match the wheel-zoom lower bound so both gestures clamp the same way. // Match the wheel-zoom lower bound so both gestures clamp the same way.
static const float zoomMin = 2.0f;
if (newZoom < zoomMin) newZoom = zoomMin; if (newZoom < zoomMin) newZoom = zoomMin;
if (newZoom > zoomMax) newZoom = zoomMax;
Environment::zoom = newZoom; Environment::zoom = newZoom;
// Tutorial step3 → step4: detect a significant pinch-zoom (≥ 2 zoom units). // Tutorial step3 → step4: detect a significant pinch-zoom (≥ 2 zoom units).

View File

@ -615,6 +615,7 @@ namespace ZL
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix()); renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix());
const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero(); const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero();
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() }); renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
renderer.TranslateMatrix({ 0, -1.f, 0 });
//glBindTexture(GL_TEXTURE_2D, roomTexture->getTexID()); //glBindTexture(GL_TEXTURE_2D, roomTexture->getTexID());
//renderer.DrawVertexRenderStruct(roomMesh); //renderer.DrawVertexRenderStruct(roomMesh);
@ -785,6 +786,8 @@ namespace ZL
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix()); renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix());
const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero(); const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero();
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() }); renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
renderer.TranslateMatrix({ 0, -1.f, 0 });
// Capture the camera view matrix and compute uLightFromCamera // Capture the camera view matrix and compute uLightFromCamera
cameraViewMatrix = renderer.GetCurrentModelViewMatrix(); cameraViewMatrix = renderer.GetCurrentModelViewMatrix();
@ -894,6 +897,7 @@ namespace ZL
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix()); renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix());
const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero(); const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero();
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() }); renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
renderer.TranslateMatrix({ 0, -1.f, 0 });
renderer.RenderUniform1f("uAlpha", 1.0f); renderer.RenderUniform1f("uAlpha", 1.0f);
for (auto& [name, gameObj] : gameObjects) { for (auto& [name, gameObj] : gameObjects) {
@ -1067,6 +1071,7 @@ namespace ZL
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix()); renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix());
const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero(); const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero();
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() }); renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
renderer.TranslateMatrix({ 0, -1.f, 0 });
cameraViewMatrix = renderer.GetCurrentModelViewMatrix(); cameraViewMatrix = renderer.GetCurrentModelViewMatrix();
@ -1563,7 +1568,7 @@ namespace ZL
Eigen::Vector3f camForward(sinAzim * cosIncl, -sinIncl, -cosAzim * cosIncl); Eigen::Vector3f camForward(sinAzim * cosIncl, -sinIncl, -cosAzim * cosIncl);
Eigen::Vector3f camUp(sinAzim * sinIncl, cosIncl, -cosAzim * sinIncl); Eigen::Vector3f camUp(sinAzim * sinIncl, cosIncl, -cosAzim * sinIncl);
const Eigen::Vector3f& playerPos = player ? player->position : Eigen::Vector3f::Zero(); const Eigen::Vector3f& playerPos = player ? player->position : Eigen::Vector3f::Zero();
Eigen::Vector3f camPos = playerPos + Eigen::Vector3f(-sinAzim * cosIncl, sinIncl, cosAzim * cosIncl) * Environment::zoom; Eigen::Vector3f camPos = playerPos + Eigen::Vector3f(-sinAzim * cosIncl, sinIncl, cosAzim * cosIncl) * Environment::zoom + Eigen::Vector3f(0,1,0);
Eigen::Vector3f rayDir = (camForward + camRight * (ndcX * aspect * tanHalfFov) + camUp * (ndcY * tanHalfFov)).normalized(); Eigen::Vector3f rayDir = (camForward + camRight * (ndcX * aspect * tanHalfFov) + camUp * (ndcY * tanHalfFov)).normalized();