Working on camera positioning
This commit is contained in:
parent
020f31e1e4
commit
9f4d60036d
@ -15,7 +15,7 @@ namespace ZL {
|
||||
using std::max;
|
||||
#endif
|
||||
|
||||
constexpr float DEFAULT_ZOOM = 6.f;
|
||||
constexpr float DEFAULT_ZOOM = 8.f;
|
||||
|
||||
class Environment {
|
||||
public:
|
||||
|
||||
23
src/Game.cpp
23
src/Game.cpp
@ -22,17 +22,8 @@
|
||||
|
||||
namespace ZL
|
||||
{
|
||||
/*
|
||||
void set_Texture(Character& npc, const TextureDataStruct& texture)
|
||||
{
|
||||
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);
|
||||
}*/
|
||||
static const float zoomMin = 6.0f;
|
||||
static const float zoomMax = 20.0f;
|
||||
|
||||
#ifdef EMSCRIPTEN
|
||||
const char* CONST_ZIP_FILE = "resources.zip";
|
||||
@ -945,8 +936,11 @@ namespace ZL
|
||||
else if (event.wheel.y < 0) {
|
||||
Environment::zoom += zoomstep;
|
||||
}
|
||||
if (Environment::zoom < zoomstep) {
|
||||
Environment::zoom = zoomstep;
|
||||
if (Environment::zoom < zoomMin) {
|
||||
Environment::zoom = zoomMin;
|
||||
}
|
||||
if (Environment::zoom > zoomMax) {
|
||||
Environment::zoom = zoomMax;
|
||||
}
|
||||
std::cout << "Current zoom: " << Environment::zoom << std::endl;
|
||||
// Tutorial step3 → step4: any mouse-wheel scroll counts as "zoom gesture".
|
||||
@ -1225,8 +1219,9 @@ namespace ZL
|
||||
|
||||
float newZoom = pinchStartZoom * (pinchStartDistance / dist);
|
||||
// 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 > zoomMax) newZoom = zoomMax;
|
||||
Environment::zoom = newZoom;
|
||||
|
||||
// Tutorial step3 → step4: detect a significant pinch-zoom (≥ 2 zoom units).
|
||||
|
||||
@ -615,6 +615,7 @@ namespace ZL
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero();
|
||||
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
|
||||
renderer.TranslateMatrix({ 0, -1.f, 0 });
|
||||
|
||||
//glBindTexture(GL_TEXTURE_2D, roomTexture->getTexID());
|
||||
//renderer.DrawVertexRenderStruct(roomMesh);
|
||||
@ -780,11 +781,13 @@ namespace ZL
|
||||
|
||||
renderer.LoadIdentity();
|
||||
renderer.TranslateMatrix({ 0,0, -1.0f * Environment::zoom });
|
||||
|
||||
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraInclination, Eigen::Vector3f::UnitX())).toRotationMatrix());
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero();
|
||||
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
|
||||
renderer.TranslateMatrix({ 0, -1.f, 0 });
|
||||
|
||||
|
||||
// Capture the camera view matrix and compute uLightFromCamera
|
||||
cameraViewMatrix = renderer.GetCurrentModelViewMatrix();
|
||||
@ -894,6 +897,7 @@ namespace ZL
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero();
|
||||
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
|
||||
renderer.TranslateMatrix({ 0, -1.f, 0 });
|
||||
|
||||
renderer.RenderUniform1f("uAlpha", 1.0f);
|
||||
for (auto& [name, gameObj] : gameObjects) {
|
||||
@ -1067,6 +1071,7 @@ namespace ZL
|
||||
renderer.RotateMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(cameraAzimuth, Eigen::Vector3f::UnitY())).toRotationMatrix());
|
||||
const Eigen::Vector3f& camTarget = player ? player->position : Eigen::Vector3f::Zero();
|
||||
renderer.TranslateMatrix({ -camTarget.x(), -camTarget.y(), -camTarget.z() });
|
||||
renderer.TranslateMatrix({ 0, -1.f, 0 });
|
||||
|
||||
cameraViewMatrix = renderer.GetCurrentModelViewMatrix();
|
||||
|
||||
@ -1563,7 +1568,7 @@ namespace ZL
|
||||
Eigen::Vector3f camForward(sinAzim * cosIncl, -sinIncl, -cosAzim * cosIncl);
|
||||
Eigen::Vector3f camUp(sinAzim * sinIncl, cosIncl, -cosAzim * sinIncl);
|
||||
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();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user