add corner fill
This commit is contained in:
@@ -27,16 +27,6 @@ void BlobRect::updatePolish() {
|
||||
emit rawDeformMatrixChanged();
|
||||
updateCenteredDeformMatrix();
|
||||
m_physicsActive = false;
|
||||
|
||||
if (m_group) {
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this]() {
|
||||
if (m_group)
|
||||
m_group->markDirty();
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
} else {
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
@@ -105,17 +95,15 @@ void BlobRect::updatePhysics() {
|
||||
|
||||
const float kStiffness = static_cast<float>(m_stiffness);
|
||||
const float kDamping = static_cast<float>(m_damping);
|
||||
const float invDamp = 1.0f / (1.0f + kDamping * dt);
|
||||
|
||||
const float accel00 = -kStiffness * (m_dm00 - target00) - kDamping * m_dmVel00;
|
||||
m_dmVel00 += accel00 * dt;
|
||||
m_dmVel00 = (m_dmVel00 - kStiffness * (m_dm00 - target00) * dt) * invDamp;
|
||||
m_dm00 += m_dmVel00 * dt;
|
||||
|
||||
const float accel01 = -kStiffness * (m_dm01 - target01) - kDamping * m_dmVel01;
|
||||
m_dmVel01 += accel01 * dt;
|
||||
m_dmVel01 = (m_dmVel01 - kStiffness * (m_dm01 - target01) * dt) * invDamp;
|
||||
m_dm01 += m_dmVel01 * dt;
|
||||
|
||||
const float accel11 = -kStiffness * (m_dm11 - target11) - kDamping * m_dmVel11;
|
||||
m_dmVel11 += accel11 * dt;
|
||||
m_dmVel11 = (m_dmVel11 - kStiffness * (m_dm11 - target11) * dt) * invDamp;
|
||||
m_dm11 += m_dmVel11 * dt;
|
||||
|
||||
m_deformMatrix = QMatrix4x4(m_dm00, m_dm01, 0, 0, m_dm01, m_dm11, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
|
||||
@@ -178,11 +166,24 @@ bool BlobRect::isExcluded(const BlobShape* other) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BlobRect::isCornerExcluded(const BlobShape* other) const {
|
||||
for (const auto& ptr : m_excludeCorners) {
|
||||
if (ptr == other)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QQmlListProperty<BlobRect> BlobRect::exclude() {
|
||||
return QQmlListProperty<BlobRect>(
|
||||
this, nullptr, &excludeAppend, &excludeCount, &excludeAt, &excludeClear, &excludeReplace, &excludeRemoveLast);
|
||||
}
|
||||
|
||||
QQmlListProperty<BlobRect> BlobRect::excludeCorners() {
|
||||
return QQmlListProperty<BlobRect>(this, nullptr, &excludeCornersAppend, &excludeCornersCount, &excludeCornersAt,
|
||||
&excludeCornersClear, &excludeCornersReplace, &excludeCornersRemoveLast);
|
||||
}
|
||||
|
||||
void BlobRect::excludeAppend(QQmlListProperty<BlobRect>* prop, BlobRect* rect) {
|
||||
auto* self = static_cast<BlobRect*>(prop->object);
|
||||
self->m_exclude.append(rect);
|
||||
@@ -229,6 +230,52 @@ void BlobRect::excludeRemoveLast(QQmlListProperty<BlobRect>* prop) {
|
||||
emit self->excludeChanged();
|
||||
}
|
||||
|
||||
void BlobRect::excludeCornersAppend(QQmlListProperty<BlobRect>* prop, BlobRect* rect) {
|
||||
auto* self = static_cast<BlobRect*>(prop->object);
|
||||
self->m_excludeCorners.append(rect);
|
||||
if (self->m_group)
|
||||
self->m_group->markDirty();
|
||||
emit self->excludeCornersChanged();
|
||||
}
|
||||
|
||||
qsizetype BlobRect::excludeCornersCount(QQmlListProperty<BlobRect>* prop) {
|
||||
auto* self = static_cast<BlobRect*>(prop->object);
|
||||
return self->m_excludeCorners.size();
|
||||
}
|
||||
|
||||
BlobRect* BlobRect::excludeCornersAt(QQmlListProperty<BlobRect>* prop, qsizetype index) {
|
||||
auto* self = static_cast<BlobRect*>(prop->object);
|
||||
return self->m_excludeCorners.at(index);
|
||||
}
|
||||
|
||||
void BlobRect::excludeCornersClear(QQmlListProperty<BlobRect>* prop) {
|
||||
auto* self = static_cast<BlobRect*>(prop->object);
|
||||
if (self->m_excludeCorners.isEmpty())
|
||||
return;
|
||||
self->m_excludeCorners.clear();
|
||||
if (self->m_group)
|
||||
self->m_group->markDirty();
|
||||
emit self->excludeCornersChanged();
|
||||
}
|
||||
|
||||
void BlobRect::excludeCornersReplace(QQmlListProperty<BlobRect>* prop, qsizetype index, BlobRect* rect) {
|
||||
auto* self = static_cast<BlobRect*>(prop->object);
|
||||
self->m_excludeCorners[index] = rect;
|
||||
if (self->m_group)
|
||||
self->m_group->markDirty();
|
||||
emit self->excludeCornersChanged();
|
||||
}
|
||||
|
||||
void BlobRect::excludeCornersRemoveLast(QQmlListProperty<BlobRect>* prop) {
|
||||
auto* self = static_cast<BlobRect*>(prop->object);
|
||||
if (self->m_excludeCorners.isEmpty())
|
||||
return;
|
||||
self->m_excludeCorners.removeLast();
|
||||
if (self->m_group)
|
||||
self->m_group->markDirty();
|
||||
emit self->excludeCornersChanged();
|
||||
}
|
||||
|
||||
void BlobRect::checkAtRest(float speed) {
|
||||
constexpr float kEpsilon = 0.002f;
|
||||
const bool atRest = std::abs(m_dm00 - 1.0f) < kEpsilon && std::abs(m_dm01) < kEpsilon &&
|
||||
@@ -242,19 +289,9 @@ void BlobRect::checkAtRest(float speed) {
|
||||
m_dmVel00 = 0.0f;
|
||||
m_dmVel01 = 0.0f;
|
||||
m_dmVel11 = 0.0f;
|
||||
m_deformMatrix = QMatrix4x4();
|
||||
m_deformMatrix = QMatrix4x4(); // identity
|
||||
emit rawDeformMatrixChanged();
|
||||
updateCenteredDeformMatrix();
|
||||
m_physicsActive = false;
|
||||
|
||||
if (m_group) {
|
||||
QMetaObject::invokeMethod(
|
||||
this,
|
||||
[this]() {
|
||||
if (m_group)
|
||||
m_group->markDirty();
|
||||
},
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user