Skip to content

Commit

Permalink
rename twist -> roll
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanMOlson committed Nov 12, 2024
1 parent f737b2f commit bf5745a
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
6 changes: 3 additions & 3 deletions bin/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int main(int argc, char* argv[]) {
args::ValueFlag<double> fovValue(argumentParser, "degrees", "FOV", {'f', "fov"});
args::ValueFlag<double> bearingValue(argumentParser, "degrees", "Bearing", {'b', "bearing"});
args::ValueFlag<double> pitchValue(argumentParser, "degrees", "Pitch", {'p', "pitch"});
args::ValueFlag<double> twistValue(argumentParser, "degrees", "Twist", {'T', "twist"});
args::ValueFlag<double> rollValue(argumentParser, "degrees", "Roll", {'T', "roll"});
args::ValueFlag<uint32_t> widthValue(argumentParser, "pixels", "Image width", {'w', "width"});
args::ValueFlag<uint32_t> heightValue(argumentParser, "pixels", "Image height", {'h', "height"});

Expand All @@ -63,7 +63,7 @@ int main(int argc, char* argv[]) {
const double fov = fovValue ? args::get(fovValue) : 37;
const double bearing = bearingValue ? args::get(bearingValue) : 0;
const double pitch = pitchValue ? args::get(pitchValue) : 0;
const double twist = twistValue ? args::get(twistValue) : 0;
const double roll = rollValue ? args::get(rollValue) : 0;
const double pixelRatio = pixelRatioValue ? args::get(pixelRatioValue) : 1;

const uint32_t width = widthValue ? args::get(widthValue) : 512;
Expand Down Expand Up @@ -103,7 +103,7 @@ int main(int argc, char* argv[]) {
}

map.getStyle().loadURL(style);
map.jumpTo(CameraOptions().withCenter(LatLng{lat, lon}).withAlt(alt).withZoom(zoom).withBearing(bearing).withPitch(pitch).withTwist(twist).withFov(fov));
map.jumpTo(CameraOptions().withCenter(LatLng{lat, lon}).withAlt(alt).withZoom(zoom).withBearing(bearing).withPitch(pitch).withRoll(roll).withFov(fov));

if (debug) {
map.setDebug(debug ? mbgl::MapDebugOptions::TileBorders | mbgl::MapDebugOptions::ParseStatus
Expand Down
10 changes: 5 additions & 5 deletions include/mbgl/map/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ struct CameraOptions {
pitch = o;
return *this;
}
CameraOptions& withTwist(const std::optional<double>& o) {
twist = o;
CameraOptions& withRoll(const std::optional<double>& o) {
roll = o;
return *this;
}
CameraOptions& withFov(const std::optional<double>& o) {
Expand Down Expand Up @@ -78,13 +78,13 @@ struct CameraOptions {
two-dimensional map. */
std::optional<double> pitch;

std::optional<double> twist;
std::optional<double> roll;
std::optional<double> fov;
};

constexpr bool operator==(const CameraOptions& a, const CameraOptions& b) {
return a.center == b.center && a.padding == b.padding && a.anchor == b.anchor && a.zoom == b.zoom &&
a.bearing == b.bearing && a.pitch == b.pitch && a.twist == b.twist && a.fov == b.fov && a.altM == b.altM;
a.bearing == b.bearing && a.pitch == b.pitch && a.roll == b.roll && a.fov == b.fov && a.altM == b.altM;
}

constexpr bool operator!=(const CameraOptions& a, const CameraOptions& b) {
Expand Down Expand Up @@ -170,7 +170,7 @@ struct FreeCameraOptions {

/** Helper function for setting the orientation of the camera as a pitch and
a bearing. Both values are in degrees */
void setPitchBearing(double pitch, double bearing, double twist) noexcept;
void setPitchBearing(double pitch, double bearing, double roll) noexcept;
};

} // namespace mbgl
8 changes: 4 additions & 4 deletions src/mbgl/map/transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
double pitch = camera.pitch ? util::deg2rad(*camera.pitch) : getPitch();
double fov = camera.fov ? util::deg2rad(*camera.fov) : getFieldOfView();
double alt_m = camera.altM.value_or(100000);
double twist = camera.twist ? util::deg2rad(*camera.twist) : getTwist();
double roll = camera.roll ? util::deg2rad(*camera.roll) : getRoll();

if (std::isnan(zoom) || std::isnan(bearing) || std::isnan(pitch)) {
if (animation.transitionFinishFn) {
Expand Down Expand Up @@ -169,7 +169,7 @@ void Transform::easeTo(const CameraOptions& camera, const AnimationOptions& anim
}
state.setFieldOfView(fov);
state.setAltM(alt_m);
state.setTwist(twist);
state.setRoll(roll);
},
duration);
}
Expand Down Expand Up @@ -436,8 +436,8 @@ double Transform::getPitch() const {
return state.getPitch();
}

double Transform::getTwist() const {
return state.getTwist();
double Transform::getRoll() const {
return state.getRoll();
}

double Transform::getFieldOfView() const {
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/map/transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Transform : private util::noncopyable {
// Pitch

double getPitch() const;
double getTwist() const;
double getRoll() const;
double getFieldOfView() const;

// North Orientation
Expand Down
24 changes: 12 additions & 12 deletions src/mbgl/map/transform_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ void TransformState::setProperties(const TransformStateProperties& properties) {
if (properties.pitch) {
setPitch(*properties.pitch);
}
if (properties.twist) {
setTwist(*properties.twist);
if (properties.roll) {
setRoll(*properties.roll);
}
if (properties.xSkew) {
setXSkew(*properties.xSkew);
Expand Down Expand Up @@ -214,7 +214,7 @@ void TransformState::updateCameraState() const {
const double dy = 0.5 * worldSize - y;

// Set camera orientation and move it to a proper distance from the map
camera.setOrientation(pitch, getBearing(), getTwist());
camera.setOrientation(pitch, getBearing(), getRoll());

vec3 cameraPosition = {{dx, dy, z}};

Expand All @@ -237,8 +237,8 @@ void TransformState::updateStateFromCamera() {
// Compute bearing and pitch
double newBearing;
double newPitch;
double newTwist;
camera.getOrientation(newPitch, newBearing, newTwist);
double newRoll;
camera.getOrientation(newPitch, newBearing, newRoll);
newPitch = util::clamp(newPitch, minPitch, maxPitch);

// Compute zoom level from the camera altitude
Expand All @@ -253,7 +253,7 @@ void TransformState::updateStateFromCamera() {
setLatLngZoom(latLngFromMercator(mercatorPoint), scaleZoom(newScale));
setBearing(newBearing);
setPitch(newPitch);
setTwist(newTwist);
setRoll(newRoll);
}

FreeCameraOptions TransformState::getFreeCameraOptions() const {
Expand Down Expand Up @@ -437,7 +437,7 @@ CameraOptions TransformState::getCameraOptions(const std::optional<EdgeInsets>&
.withZoom(getZoom())
.withBearing(util::rad2deg(-bearing))
.withPitch(util::rad2deg(pitch))
.withTwist(util::rad2deg(twist))
.withRoll(util::rad2deg(roll))
.withFov(util::rad2deg(fov));
}

Expand Down Expand Up @@ -621,13 +621,13 @@ void TransformState::setFieldOfView(double val) {
}
}

double TransformState::getTwist() const {
return twist;
double TransformState::getRoll() const {
return roll;
}

void TransformState::setTwist(double val) {
if (twist != val) {
twist = val;
void TransformState::setRoll(double val) {
if (roll != val) {
roll = val;
requestMatricesUpdate = true;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/mbgl/map/transform_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ struct TransformStateProperties {
pitch = val;
return *this;
}
TransformStateProperties& withTwist(const std::optional<double>& val) {
twist = val;
TransformStateProperties& withRoll(const std::optional<double>& val) {
roll = val;
return *this;
}
TransformStateProperties& withXSkew(const std::optional<double>& val) {
Expand Down Expand Up @@ -105,7 +105,7 @@ struct TransformStateProperties {
std::optional<double> scale;
std::optional<double> bearing;
std::optional<double> pitch;
std::optional<double> twist;
std::optional<double> roll;
std::optional<double> xSkew;
std::optional<double> ySkew;
std::optional<bool> axonometric;
Expand Down Expand Up @@ -195,8 +195,8 @@ class TransformState {
float getCameraToCenterDistance() const;
double getPitch() const;
void setPitch(double);
double getTwist() const;
void setTwist(double);
double getRoll() const;
void setRoll(double);

double getXSkew() const;
void setXSkew(double);
Expand Down Expand Up @@ -302,7 +302,7 @@ class TransformState {
// with: `fov = 2 * arctan((height / 2) / (height * 1.5))`
double fov = 0.6435011087932844;
double pitch = 0.0;
double twist = 0.0;
double roll = 0.0;
double xSkew = 0.0;
double ySkew = 1.0;
bool axonometric = false;
Expand Down
22 changes: 11 additions & 11 deletions src/mbgl/util/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ static vec3 toMercator(const LatLng& location, double altitudeMeters) noexcept {
altitudeMeters * pixelsPerMeter / worldSize}};
}

static Quaternion orientationFromPitchBearing(double pitch, double bearing, double twist) noexcept {
static Quaternion orientationFromPitchBearing(double pitch, double bearing, double roll) noexcept {
// Both angles have to be negated to achieve CW rotation around the axis of rotation
Quaternion rotBearing = Quaternion::fromAxisAngle({{0.0, 0.0, 1.0}}, -bearing);
Quaternion rotPitch = Quaternion::fromAxisAngle({{1.0, 0.0, 0.0}}, -pitch);
Quaternion rotTwist = Quaternion::fromAxisAngle({{0.0, 0.0, 1.0}}, -twist);
Quaternion rotRoll = Quaternion::fromAxisAngle({{0.0, 0.0, 1.0}}, -roll);

return rotBearing.multiply(rotPitch).multiply(rotTwist);
return rotBearing.multiply(rotPitch).multiply(rotRoll);
}

static void updateTransform(mat4& transform, const Quaternion& orientation) noexcept {
Expand Down Expand Up @@ -168,17 +168,17 @@ vec3 Camera::up() const noexcept {
return {{-column[0], -column[1], -column[2]}};
}

void Camera::getOrientation(double& pitch, double& bearing, double& twist) const noexcept {
void Camera::getOrientation(double& pitch, double& bearing, double& roll) const noexcept {
const vec3 f = forward();
const vec3 r = right();

bearing = std::atan2(-r[1], r[0]);
pitch = std::atan2(std::sqrt(f[0] * f[0] + f[1] * f[1]), -f[2]);
twist = 0; //TODO
roll = 0; //TODO
}

void Camera::setOrientation(double pitch, double bearing, double twist) noexcept {
orientation = orientationFromPitchBearing(pitch, bearing, twist);
void Camera::setOrientation(double pitch, double bearing, double roll) noexcept {
orientation = orientationFromPitchBearing(pitch, bearing, roll);
updateTransform(transform, orientation);
}

Expand All @@ -196,9 +196,9 @@ std::optional<Quaternion> Camera::orientationFromFrame(const vec3& forward, cons

const double bearing = std::atan2(-right[1], right[0]);
const double pitch = std::atan2(std::sqrt(forward[0] * forward[0] + forward[1] * forward[1]), -forward[2]);
const double twist = 0; //TODO
const double roll = 0; //TODO

return util::orientationFromPitchBearing(pitch, bearing, twist);
return util::orientationFromPitchBearing(pitch, bearing, roll);
}
} // namespace util

Expand Down Expand Up @@ -241,9 +241,9 @@ void FreeCameraOptions::lookAtPoint(const LatLng& location, const std::optional<
orientation = util::Camera::orientationFromFrame(forward, up)->m;
}

void FreeCameraOptions::setPitchBearing(double pitch, double bearing, double twist) noexcept {
void FreeCameraOptions::setPitchBearing(double pitch, double bearing, double roll) noexcept {
orientation =
util::orientationFromPitchBearing(util::deg2rad(pitch), util::deg2rad(bearing), util::deg2rad(twist)).m;
util::orientationFromPitchBearing(util::deg2rad(pitch), util::deg2rad(bearing), util::deg2rad(roll)).m;
}

} // namespace mbgl
4 changes: 2 additions & 2 deletions src/mbgl/util/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class Camera {
vec3 up() const noexcept;

const Quaternion& getOrientation() const noexcept { return orientation; }
void getOrientation(double& pitch, double& bearing, double& twist) const noexcept;
void setOrientation(double pitch, double bearing, double twist) noexcept;
void getOrientation(double& pitch, double& bearing, double& roll) const noexcept;
void setOrientation(double pitch, double bearing, double roll) noexcept;
void setOrientation(const Quaternion& orientation_) noexcept;
void setPosition(const vec3& position) noexcept;

Expand Down

0 comments on commit bf5745a

Please sign in to comment.