ADD: planet camera fix
This commit is contained in:
@@ -45,6 +45,9 @@ struct FreeCameraSettings
|
||||
|
||||
struct OrbitCameraSettings
|
||||
{
|
||||
static constexpr double kMinDistance = 0.2;
|
||||
static constexpr double kMaxDistance = 1.0e12;
|
||||
|
||||
CameraTarget target{};
|
||||
double distance{10.0};
|
||||
float yaw{0.0f}; // radians
|
||||
|
||||
@@ -76,17 +76,18 @@ void FreeCameraMode::process_input(SceneManager & /*scene*/,
|
||||
float dx = e.mouse_delta.x * _settings.look_sensitivity;
|
||||
float dy = e.mouse_delta.y * _settings.look_sensitivity;
|
||||
|
||||
// Mouse right (xrel > 0) turns view right with -Z-forward: yaw around +Y.
|
||||
glm::quat yaw_rotation = glm::angleAxis(dx, glm::vec3{0.f, 1.f, 0.f});
|
||||
// Mouse right (xrel > 0) turns view right with -Z-forward: yaw around the
|
||||
// camera's local +Y (up) axis, so yaw remains intuitive when rolled.
|
||||
glm::vec3 up = glm::rotate(camera.orientation, glm::vec3{0.f, 1.f, 0.f});
|
||||
glm::quat yaw_rotation = glm::angleAxis(dx, glm::normalize(up));
|
||||
camera.orientation = glm::normalize(yaw_rotation * camera.orientation);
|
||||
|
||||
// Mouse up (yrel < 0) looks up with -Z-forward: negative dy.
|
||||
float pitch_delta = -dy;
|
||||
// Pitch around the camera's local X (right) axis in world space.
|
||||
// Pitch around the camera's local +X (right) axis (after yaw is applied).
|
||||
glm::vec3 right = glm::rotate(camera.orientation, glm::vec3{1.f, 0.f, 0.f});
|
||||
glm::quat pitch_rotation = glm::angleAxis(pitch_delta, glm::vec3(right));
|
||||
|
||||
// Apply yaw, then pitch, to the current orientation.
|
||||
camera.orientation = glm::normalize(pitch_rotation * yaw_rotation * camera.orientation);
|
||||
glm::quat pitch_rotation = glm::angleAxis(pitch_delta, glm::normalize(right));
|
||||
camera.orientation = glm::normalize(pitch_rotation * camera.orientation);
|
||||
}
|
||||
else if (e.type == InputEvent::Type::MouseWheel)
|
||||
{
|
||||
|
||||
@@ -102,7 +102,9 @@ void OrbitCameraMode::process_input(SceneManager & /*scene*/,
|
||||
else
|
||||
{
|
||||
const double factor = std::pow(1.15, -static_cast<double>(steps));
|
||||
_settings.distance = std::clamp(_settings.distance * factor, 0.2, 100000.0);
|
||||
_settings.distance = std::clamp(_settings.distance * factor,
|
||||
OrbitCameraSettings::kMinDistance,
|
||||
OrbitCameraSettings::kMaxDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,7 +139,7 @@ void OrbitCameraMode::update(SceneManager &scene, Camera &camera, float /*dt*/)
|
||||
glm::half_pi<float>() - 0.01f);
|
||||
_settings.yaw = yaw;
|
||||
_settings.pitch = pitch;
|
||||
double dist = std::max(0.2, _settings.distance);
|
||||
double dist = std::max(OrbitCameraSettings::kMinDistance, _settings.distance);
|
||||
|
||||
glm::quat yaw_q = glm::angleAxis(yaw, glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
glm::vec3 right = glm::rotate(yaw_q, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
|
||||
@@ -182,6 +182,19 @@ PlanetSystem::PlanetBody *PlanetSystem::get_body(BodyID id)
|
||||
return &_bodies[i];
|
||||
}
|
||||
|
||||
PlanetSystem::PlanetBody *PlanetSystem::find_body_by_name(std::string_view name)
|
||||
{
|
||||
ensure_bodies_created();
|
||||
for (PlanetBody &b : _bodies)
|
||||
{
|
||||
if (b.name == name)
|
||||
{
|
||||
return &b;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void PlanetSystem::ensure_bodies_created()
|
||||
{
|
||||
if (!_bodies.empty())
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
@@ -61,6 +62,7 @@ public:
|
||||
|
||||
const PlanetBody *get_body(BodyID id) const;
|
||||
PlanetBody *get_body(BodyID id);
|
||||
PlanetBody *find_body_by_name(std::string_view name);
|
||||
const std::vector<PlanetBody> &bodies() const { return _bodies; }
|
||||
|
||||
const planet::PlanetQuadtree::Settings &earth_quadtree_settings() const { return _earth_quadtree_settings; }
|
||||
|
||||
Reference in New Issue
Block a user