Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
// SculptForge - open source digital sculpting
// SPDX-License-Identifier: GPL-3.0-or-later
//
// Two-finger navigation on a touch screen or a trackpad (phoenix, Discord 11-05): which fingers are down and how
// a pair of them moved since the last event, as a pan, a pinch and a twist. Independent of SDL so it can be unit
// tested; the app side (finger and pinch events to the camera, one finger still sculpting) is src/app/Touch.cpp.
#pragma once
#include <glm/glm.hpp>
#include <cstdint>
#include <vector>
namespace sf {
// One move of a pair of fingers, in the coordinates the fingers were given in.
struct TwoFingerStep {
glm::vec2 pan{0.0f}; // how far the point between the two fingers moved
float scale = 1.0f; // new distance between them / old distance (> 1: spread apart, zoom in)
float angle = 0.0f; // radians the line between them turned, -pi .. pi (> 0: clockwise with y down)
};
class TouchGesture {
public:
static constexpr size_t kMaxFingers = 10;
// A finger landed (an id already down moves there instead).
void down(uint64_t id, glm::vec2 p);
// A finger moved. True when two or more are down and the first two (in landing order) moved as a pair: `step`
// says how. Unknown ids and non-finite positions are ignored.
bool move(uint64_t id, glm::vec2 p, TwoFingerStep& step);
void up(uint64_t id);
void clear();
int fingers() const { return int(fingers_.size()); }
// Two or more fingers have been down at once since the first one landed (until all are lifted): the touch is a
// gesture, not a stroke.
bool gesture() const { return gesture_; }
private:
struct Finger {
uint64_t id;
glm::vec2 p;
};
std::vector<Finger> fingers_;
bool gesture_ = false;
};
// Camera::zoom steps (x0.88 of the distance each) for a pinch that spread the fingers by `scale`: the model grows
// on screen by about the same factor. 0 for a scale that isn't finite and positive.
float pinchZoomSteps(float scale);
} // namespace sf