diff --git a/appveyor.yml b/appveyor.yml index c03fc8b3..53a20074 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -121,9 +121,6 @@ after_test: - dust3d.exe :/resources/model-bicycle.ds3 -o bicycle.obj - dust3d.exe :/resources/model-bicycle.ds3 -o bicycle.fbx - dust3d.exe :/resources/model-bicycle.ds3 -o bicycle.glb - - dust3d.exe :/resources/model-bob.ds3 -o bob.obj - - dust3d.exe :/resources/model-bob.ds3 -o bob.fbx - - dust3d.exe :/resources/model-bob.ds3 -o bob.glb - dust3d.exe :/resources/model-dog.ds3 -o dog.obj - dust3d.exe :/resources/model-dog.ds3 -o dog.fbx - dust3d.exe :/resources/model-dog.ds3 -o dog.glb diff --git a/dust3d.pro b/dust3d.pro index 74a9df47..0ff700b9 100644 --- a/dust3d.pro +++ b/dust3d.pro @@ -511,8 +511,8 @@ HEADERS += src/genericspineandpseudophysics.h SOURCES += src/chainsimulator.cpp HEADERS += src/chainsimulator.h -SOURCES += src/vertebratamotion.cpp -HEADERS += src/vertebratamotion.h +SOURCES += src/vertebratamovemotionbuilder.cpp +HEADERS += src/vertebratamovemotionbuilder.h SOURCES += src/simplerendermeshgenerator.cpp HEADERS += src/simplerendermeshgenerator.h @@ -520,8 +520,8 @@ HEADERS += src/simplerendermeshgenerator.h SOURCES += src/motioneditwidget.cpp HEADERS += src/motioneditwidget.h -SOURCES += src/vertebratamotionparameterswidget.cpp -HEADERS += src/vertebratamotionparameterswidget.h +SOURCES += src/vertebratamovemotionparameterswidget.cpp +HEADERS += src/vertebratamovemotionparameterswidget.h SOURCES += src/objectxml.cpp HEADERS += src/objectxml.h @@ -529,6 +529,12 @@ HEADERS += src/objectxml.h SOURCES += src/rigxml.cpp HEADERS += src/rigxml.h +SOURCES += src/ragdoll.cpp +HEADERS += src/ragdoll.h + +SOURCES += src/motionbuilder.cpp +HEADERS += src/motionbuilder.h + SOURCES += src/main.cpp HEADERS += src/version.h diff --git a/src/chainsimulator.cpp b/src/chainsimulator.cpp index 24b65858..bfb70e89 100644 --- a/src/chainsimulator.cpp +++ b/src/chainsimulator.cpp @@ -36,7 +36,7 @@ void ChainSimulator::start() initializeVertexMotions(); prepareChains(); - outputChainsForDebug("debug-chains.obj", m_chains); + //outputChainsForDebug("debug-chains.obj", m_chains); } const ChainSimulator::VertexMotion &ChainSimulator::getVertexMotion(size_t vertexIndex) diff --git a/src/motionbuilder.cpp b/src/motionbuilder.cpp new file mode 100644 index 00000000..66888e97 --- /dev/null +++ b/src/motionbuilder.cpp @@ -0,0 +1 @@ +#include "motionbuilder.h" \ No newline at end of file diff --git a/src/motionbuilder.h b/src/motionbuilder.h new file mode 100644 index 00000000..a258eb0a --- /dev/null +++ b/src/motionbuilder.h @@ -0,0 +1,24 @@ +#ifndef MOTION_BUILDER_H +#define MOTION_BUILDER_H +#include + +class MotionBuilder +{ +public: + struct Node + { + QVector3D position; + double radius; + int boneIndex = -1; + bool isTail = false; + }; + + enum class Side + { + Middle = 0, + Left, + Right, + }; +}; + +#endif diff --git a/src/motioneditwidget.cpp b/src/motioneditwidget.cpp index f4799a36..90484079 100644 --- a/src/motioneditwidget.cpp +++ b/src/motioneditwidget.cpp @@ -13,7 +13,7 @@ #include "motionsgenerator.h" #include "util.h" #include "version.h" -#include "vertebratamotionparameterswidget.h" +#include "vertebratamovemotionparameterswidget.h" MotionEditWidget::~MotionEditWidget() { @@ -94,8 +94,8 @@ MotionEditWidget::MotionEditWidget() void MotionEditWidget::updateParametersArea() { - VertebrataMotionParametersWidget *widget = new VertebrataMotionParametersWidget(m_parameters); - connect(widget, &VertebrataMotionParametersWidget::parametersChanged, this, [=]() { + VertebrataMoveMotionParametersWidget *widget = new VertebrataMoveMotionParametersWidget(m_parameters); + connect(widget, &VertebrataMoveMotionParametersWidget::parametersChanged, this, [=]() { this->m_parameters = widget->getParameters(); emit parametersChanged(); }); diff --git a/src/motioneditwidget.h b/src/motioneditwidget.h index 251bcc1c..b2d9c8b8 100644 --- a/src/motioneditwidget.h +++ b/src/motioneditwidget.h @@ -5,7 +5,6 @@ #include #include #include -#include "vertebratamotion.h" #include "rig.h" #include "object.h" diff --git a/src/motionsgenerator.cpp b/src/motionsgenerator.cpp index e6ab3b52..f532a4b1 100644 --- a/src/motionsgenerator.cpp +++ b/src/motionsgenerator.cpp @@ -4,9 +4,9 @@ #include #include #include "motionsgenerator.h" -#include "vertebratamotion.h" +#include "vertebratamovemotionbuilder.h" #include "blockmesh.h" -#include "vertebratamotionparameterswidget.h" +#include "vertebratamovemotionparameterswidget.h" #include "util.h" MotionsGenerator::MotionsGenerator(RigType rigType, @@ -141,7 +141,7 @@ void MotionsGenerator::generateMotion(const QUuid &motionId) double radiusScale = 0.5; - std::vector spineNodes; + std::vector spineNodes; if (!spineBones.empty()) { const auto &it = spineBones[0]; if (it.second) { @@ -175,14 +175,14 @@ void MotionsGenerator::generateMotion(const QUuid &motionId) } } - VertebrataMotion *vertebrataMotion = new VertebrataMotion; + VertebrataMoveMotionBuilder *vertebrataMoveMotionBuilder = new VertebrataMoveMotionBuilder; - VertebrataMotion::Parameters parameters = - VertebrataMotionParametersWidget::toVertebrataMotionParameters(m_motions[motionId]); + VertebrataMoveMotionBuilder::Parameters parameters = + VertebrataMoveMotionParametersWidget::toVertebrataMoveMotionParameters(m_motions[motionId]); if ("Vertical" == valueOfKeyInMapOrEmpty(m_bones[0].attributes, "spineDirection")) parameters.biped = true; - vertebrataMotion->setParameters(parameters); - vertebrataMotion->setSpineNodes(spineNodes); + vertebrataMoveMotionBuilder->setParameters(parameters); + vertebrataMoveMotionBuilder->setSpineNodes(spineNodes); double groundY = std::numeric_limits::max(); for (const auto &it: spineNodes) { @@ -191,12 +191,12 @@ void MotionsGenerator::generateMotion(const QUuid &motionId) } for (const auto &chain: chains) { - std::vector legNodes; - VertebrataMotion::Side side; + std::vector legNodes; + MotionBuilder::Side side; if (chain.first.startsWith("LeftLimb")) { - side = VertebrataMotion::Side::Left; + side = MotionBuilder::Side::Left; } else if (chain.first.startsWith("RightLimb")) { - side = VertebrataMotion::Side::Right; + side = MotionBuilder::Side::Right; } else { continue; } @@ -221,14 +221,14 @@ void MotionsGenerator::generateMotion(const QUuid &motionId) it, true}); } - vertebrataMotion->setLegNodes(findSpine->second, side, legNodes); + vertebrataMoveMotionBuilder->setLegNodes(findSpine->second, side, legNodes); for (const auto &it: legNodes) { if (it.position.y() - it.radius < groundY) groundY = it.position.y() - it.radius; } } - vertebrataMotion->setGroundY(groundY); - vertebrataMotion->generate(); + vertebrataMoveMotionBuilder->setGroundY(groundY); + vertebrataMoveMotionBuilder->generate(); std::vector> jointNodeTrees; std::vector> previewMeshes; @@ -249,9 +249,9 @@ void MotionsGenerator::generateMotion(const QUuid &motionId) bindTransforms[i] = parentMatrix * translationMatrix; } - const auto &vertebrataMotionFrames = vertebrataMotion->frames(); - for (size_t frameIndex = 0; frameIndex < vertebrataMotionFrames.size(); ++frameIndex) { - const auto &frame = vertebrataMotionFrames[frameIndex]; + const auto &vertebrataMoveMotionBuilderFrames = vertebrataMoveMotionBuilder->frames(); + for (size_t frameIndex = 0; frameIndex < vertebrataMoveMotionBuilderFrames.size(); ++frameIndex) { + const auto &frame = vertebrataMoveMotionBuilderFrames[frameIndex]; std::vector transformedBones = m_bones; for (const auto &node: frame) { if (-1 == node.boneIndex) @@ -356,7 +356,7 @@ void MotionsGenerator::generateMotion(const QUuid &motionId) } if (m_snapshotMeshesEnabled) { - if (frameIndex == vertebrataMotionFrames.size() / 2) { + if (frameIndex == vertebrataMoveMotionBuilderFrames.size() / 2) { delete snapshotMesh; snapshotMesh = new Model(frameVertices, frameFaces, frameCornerNormals); } diff --git a/src/ragdoll.cpp b/src/ragdoll.cpp new file mode 100644 index 00000000..72c16fbe --- /dev/null +++ b/src/ragdoll.cpp @@ -0,0 +1,138 @@ +#include +#include +#include +#include +#include "ragdoll.h" +#include "util.h" + +void Ragdoll::prepareChains() +{ + for (const auto &it: *m_links) { + m_chains.push_back({it.first, it.second, + ((*m_vertices)[it.first] - (*m_vertices)[it.second]).length()}); + } +} + +void Ragdoll::initializeVertexMotions() +{ + for (size_t i = 0; i < m_vertices->size(); ++i) + m_vertexMotions[i].position = m_vertexMotions[i].lastPosition = (*m_vertices)[i]; +} + +void Ragdoll::outputChainsForDebug(const char *filename, const std::vector &springs) +{ + FILE *fp = fopen(filename, "wb"); + for (const auto &it: *m_vertices) { + fprintf(fp, "v %f %f %f\n", it[0], it[1], it[2]); + } + for (const auto &it: springs) { + fprintf(fp, "l %zu %zu\n", it.from + 1, it.to + 1); + } + fclose(fp); +} + +void Ragdoll::start() +{ + initializeVertexMotions(); + prepareChains(); + + //outputChainsForDebug("debug-chains.obj", m_chains); +} + +const Ragdoll::VertexMotion &Ragdoll::getVertexMotion(size_t vertexIndex) +{ + return m_vertexMotions[vertexIndex]; +} + +void Ragdoll::updateVertexForces() +{ + for (auto &it: m_vertexMotions) + it.second.force = QVector3D(); + + QVector3D combinedForce = QVector3D(0.0, -9.80665, 0.0) + m_externalForce; + for (auto &it: m_vertexMotions) { + it.second.force += combinedForce; + } +} + +void Ragdoll::doVerletIntegration(double stepSize) +{ + for (auto &it: m_vertexMotions) { + if (it.second.fixed) + continue; + QVector3D &x = it.second.position; + QVector3D temp = x; + QVector3D &oldX = it.second.lastPosition; + QVector3D a = it.second.force; + x += x - oldX + a * stepSize * stepSize; + oldX = temp; + applyBoundingConstraints(&it.second); + } +} + +void Ragdoll::applyBoundingConstraints(VertexMotion *vertexMotion) +{ + if (vertexMotion->position.y() < m_groundY + vertexMotion->radius) + vertexMotion->position.setY(m_groundY + vertexMotion->radius); +} + +void Ragdoll::applyConstraints() +{ + for (size_t iteration = 0; iteration < m_parameters.iterations; ++iteration) { + for (auto &it: m_chains) { + auto &from = m_vertexMotions[it.from]; + auto &to = m_vertexMotions[it.to]; + auto delta = from.position - to.position; + auto deltaLength = delta.length(); + if (qFuzzyCompare(deltaLength, 0.0f)) + continue; + auto diff = (it.restLength - deltaLength) / deltaLength; + auto offset = delta * 0.5 * diff; + if (!from.fixed) { + from.position += offset; + applyBoundingConstraints(&from); + } + if (!to.fixed) { + to.position += -offset; + applyBoundingConstraints(&to); + } + } + + for (const auto &it: m_jointConstraints) { + auto &from = m_vertexMotions[it.first]; + auto &to = m_vertexMotions[it.second]; + auto &joint = m_vertexMotions[it.joint]; + double degrees = degreesBetweenVectors(from.position - joint.position, + to.position - joint.position); + if (degrees < it.minDegrees) { + QVector3D straightPosition = (from.position + to.position) * 0.5; + joint.position += (it.minDegrees - degrees) * (straightPosition - joint.position) / (180 - degrees); + applyBoundingConstraints(&joint); + } else if (degrees > it.maxDegrees) { + // TODO: + } + } + } +} + +void Ragdoll::updateVertexPosition(size_t vertexIndex, const QVector3D &position) +{ + m_vertexMotions[vertexIndex].position = position; +} + +void Ragdoll::fixVertexPosition(size_t vertexIndex) +{ + m_vertexMotions[vertexIndex].fixed = true; +} + +void Ragdoll::updateVertexRadius(size_t vertexIndex, double radius) +{ + m_vertexMotions[vertexIndex].radius = radius; +} + +void Ragdoll::simulate(double stepSize) +{ + updateVertexForces(); + doVerletIntegration(stepSize); + applyConstraints(); +} diff --git a/src/ragdoll.h b/src/ragdoll.h new file mode 100644 index 00000000..e35ae980 --- /dev/null +++ b/src/ragdoll.h @@ -0,0 +1,91 @@ +#ifndef DUST3D_RAGDOLL_H +#define DUST3D_RAGDOLL_H +#include +#include +#include + +class Ragdoll +{ +public: + struct Parameters + { + size_t iterations = 1; + }; + + struct Chain + { + size_t from; + size_t to; + double restLength; + }; + + struct VertexMotion + { + QVector3D position; + QVector3D lastPosition; + QVector3D force; + bool fixed = false; + double radius = 0.0; + }; + + struct JointConstraint + { + size_t joint; + size_t first; + size_t second; + double minDegrees; + double maxDegrees; + }; + + Ragdoll(const std::vector *vertices, + const std::vector> *links) : + m_vertices(vertices), + m_links(links) + { + } + + void addJointConstraint(size_t joint, + size_t first, + size_t second, + double minDegrees, + double maxDegrees) + { + JointConstraint jointConstraint = { + joint, first, second, minDegrees, maxDegrees + }; + m_jointConstraints.push_back(jointConstraint); + } + + void setExternalForce(const QVector3D &externalForce) + { + m_externalForce = externalForce; + } + + void start(); + void simulate(double stepSize); + const VertexMotion &getVertexMotion(size_t vertexIndex); + void updateVertexPosition(size_t vertexIndex, const QVector3D &position); + void updateVertexRadius(size_t vertexIndex, double radius); + void fixVertexPosition(size_t vertexIndex); + +private: + Parameters m_parameters; + std::vector m_chains; + const std::vector *m_vertices = nullptr; + const std::vector> *m_links = nullptr; + std::vector m_jointConstraints; + std::unordered_map m_vertexMotions; + QVector3D m_externalForce; + double m_groundY = 0.0; + + void initializeVertexMotions(); + void prepareChains(); + void updateVertexForces(); + void applyConstraints(); + void doVerletIntegration(double stepSize); + void applyBoundingConstraints(VertexMotion *vertexMotion); + + void outputChainsForDebug(const char *filename, const std::vector &springs); +}; + +#endif diff --git a/src/vertebratamotionparameterswidget.h b/src/vertebratamotionparameterswidget.h deleted file mode 100644 index 11a376d6..00000000 --- a/src/vertebratamotionparameterswidget.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef DUST3D_VERTEBRATA_MOTION_PARAMETERS_WIDGET_H -#define DUST3D_VERTEBRATA_MOTION_PARAMETERS_WIDGET_H -#include -#include -#include -#include "vertebratamotion.h" - -class VertebrataMotionParametersWidget : public QWidget -{ - Q_OBJECT -signals: - void parametersChanged(); -public: - VertebrataMotionParametersWidget(const std::map ¶meters=std::map()); - - const std::map &getParameters() const - { - return m_parameters; - } - - static std::map fromVertebrataMotionParameters(const VertebrataMotion::Parameters &from); - static VertebrataMotion::Parameters toVertebrataMotionParameters(const std::map ¶meters); -private: - std::map m_parameters; - VertebrataMotion::Parameters m_vertebrataMotionParameters; -}; - -#endif diff --git a/src/vertebratamotion.cpp b/src/vertebratamovemotionbuilder.cpp similarity index 97% rename from src/vertebratamotion.cpp rename to src/vertebratamovemotionbuilder.cpp index 6b97e6b4..d870cd77 100644 --- a/src/vertebratamotion.cpp +++ b/src/vertebratamovemotionbuilder.cpp @@ -1,18 +1,18 @@ -#include "vertebratamotion.h" +#include "vertebratamovemotionbuilder.h" #include "genericspineandpseudophysics.h" #include "hermitecurveinterpolation.h" #include "chainsimulator.h" #include "ccdikresolver.h" #include -void VertebrataMotion::prepareLegHeights() +void VertebrataMoveMotionBuilder::prepareLegHeights() { GenericSpineAndPseudoPhysics physics; physics.calculateFootHeights(m_parameters.hipHeight, m_parameters.stanceTime, m_parameters.swingTime, &m_legHeights, &m_legMoveOffsets); } -void VertebrataMotion::prepareLegs() +void VertebrataMoveMotionBuilder::prepareLegs() { m_legs.clear(); for (size_t spineNodeIndex = 0; @@ -40,7 +40,7 @@ void VertebrataMotion::prepareLegs() } } -void VertebrataMotion::prepareLegHeightIndices() +void VertebrataMoveMotionBuilder::prepareLegHeightIndices() { int balancedStart = 0; for (int side = 0; side < 3; ++side) { @@ -60,7 +60,7 @@ void VertebrataMotion::prepareLegHeightIndices() } } -void VertebrataMotion::calculateSpineJoints() +void VertebrataMoveMotionBuilder::calculateSpineJoints() { HermiteCurveInterpolation spineInterpolation; @@ -112,7 +112,7 @@ void VertebrataMotion::calculateSpineJoints() } } -void VertebrataMotion::calculateLegMoves(size_t heightIndex) +void VertebrataMoveMotionBuilder::calculateLegMoves(size_t heightIndex) { auto calculateLegTargetTop = [&](size_t legIndex) { double sumTop = 0.0; @@ -240,7 +240,7 @@ void VertebrataMotion::calculateLegMoves(size_t heightIndex) } } -void VertebrataMotion::generate() +void VertebrataMoveMotionBuilder::generate() { prepareLegHeights(); prepareLegs(); diff --git a/src/vertebratamotion.h b/src/vertebratamovemotionbuilder.h similarity index 84% rename from src/vertebratamotion.h rename to src/vertebratamovemotionbuilder.h index 2005c337..6719a55d 100644 --- a/src/vertebratamotion.h +++ b/src/vertebratamovemotionbuilder.h @@ -1,11 +1,12 @@ -#ifndef DUST3D_VERTEBRATA_MOTION_H -#define DUST3D_VERTEBRATA_MOTION_H +#ifndef DUST3D_VERTEBRATA_MOVE_MOTION_H +#define DUST3D_VERTEBRATA_MOVE_MOTION_H #include #include #include #include +#include "motionbuilder.h" -class VertebrataMotion +class VertebrataMoveMotionBuilder : public MotionBuilder { public: struct Parameters @@ -23,22 +24,7 @@ public: double tailDragForce = 4.0; bool biped = false; }; - - struct Node - { - QVector3D position; - double radius; - int boneIndex = -1; - bool isTail = false; - }; - - enum class Side - { - Middle = 0, - Left, - Right, - }; - + struct Leg { std::vector> nodes; @@ -49,7 +35,8 @@ public: double move[3] = {0, 0, 0}; }; - VertebrataMotion() + VertebrataMoveMotionBuilder() : + MotionBuilder() { } diff --git a/src/vertebratamotionparameterswidget.cpp b/src/vertebratamovemotionparameterswidget.cpp similarity index 82% rename from src/vertebratamotionparameterswidget.cpp rename to src/vertebratamovemotionparameterswidget.cpp index cac16747..16ab8fd6 100644 --- a/src/vertebratamotionparameterswidget.cpp +++ b/src/vertebratamovemotionparameterswidget.cpp @@ -1,10 +1,10 @@ #include #include #include -#include "vertebratamotionparameterswidget.h" +#include "vertebratamovemotionparameterswidget.h" #include "util.h" -std::map VertebrataMotionParametersWidget::fromVertebrataMotionParameters(const VertebrataMotion::Parameters &from) +std::map VertebrataMoveMotionParametersWidget::fromVertebrataMoveMotionParameters(const VertebrataMoveMotionBuilder::Parameters &from) { std::map parameters; @@ -23,9 +23,9 @@ std::map VertebrataMotionParametersWidget::fromVertebrataMotio return parameters; } -VertebrataMotion::Parameters VertebrataMotionParametersWidget::toVertebrataMotionParameters(const std::map ¶meters) +VertebrataMoveMotionBuilder::Parameters VertebrataMoveMotionParametersWidget::toVertebrataMoveMotionParameters(const std::map ¶meters) { - VertebrataMotion::Parameters vertebrataMotionParameters; + VertebrataMoveMotionBuilder::Parameters vertebrataMotionParameters; if (parameters.end() != parameters.find("stanceTime")) vertebrataMotionParameters.stanceTime = valueOfKeyInMapOrEmpty(parameters, "stanceTime").toDouble(); @@ -53,10 +53,10 @@ VertebrataMotion::Parameters VertebrataMotionParametersWidget::toVertebrataMotio return vertebrataMotionParameters; } -VertebrataMotionParametersWidget::VertebrataMotionParametersWidget(const std::map ¶meters) : +VertebrataMoveMotionParametersWidget::VertebrataMoveMotionParametersWidget(const std::map ¶meters) : m_parameters(parameters) { - m_vertebrataMotionParameters = toVertebrataMotionParameters(m_parameters); + m_vertebrataMotionParameters = toVertebrataMoveMotionParameters(m_parameters); QFormLayout *parametersLayout = new QFormLayout; parametersLayout->setSpacing(0); @@ -67,7 +67,7 @@ VertebrataMotionParametersWidget::VertebrataMotionParametersWidget(const std::ma parametersLayout->addRow(tr("Stance time: "), stanceTimeBox); connect(stanceTimeBox, QOverload::of(&QDoubleSpinBox::valueChanged), [&](double value){ m_vertebrataMotionParameters.stanceTime = value; - m_parameters = fromVertebrataMotionParameters(m_vertebrataMotionParameters); + m_parameters = fromVertebrataMoveMotionParameters(m_vertebrataMotionParameters); emit parametersChanged(); }); @@ -77,7 +77,7 @@ VertebrataMotionParametersWidget::VertebrataMotionParametersWidget(const std::ma parametersLayout->addRow(tr("Swing time: "), swingTimeBox); connect(swingTimeBox, QOverload::of(&QDoubleSpinBox::valueChanged), [&](double value){ m_vertebrataMotionParameters.swingTime = value; - m_parameters = fromVertebrataMotionParameters(m_vertebrataMotionParameters); + m_parameters = fromVertebrataMoveMotionParameters(m_vertebrataMotionParameters); emit parametersChanged(); }); @@ -86,7 +86,7 @@ VertebrataMotionParametersWidget::VertebrataMotionParametersWidget(const std::ma parametersLayout->addRow(tr("Hip height: "), hipHeightBox); connect(hipHeightBox, QOverload::of(&QDoubleSpinBox::valueChanged), [&](double value){ m_vertebrataMotionParameters.hipHeight = value; - m_parameters = fromVertebrataMotionParameters(m_vertebrataMotionParameters); + m_parameters = fromVertebrataMoveMotionParameters(m_vertebrataMotionParameters); emit parametersChanged(); }); @@ -95,7 +95,7 @@ VertebrataMotionParametersWidget::VertebrataMotionParametersWidget(const std::ma parametersLayout->addRow(tr("Arm length: "), armLengthBox); connect(armLengthBox, QOverload::of(&QDoubleSpinBox::valueChanged), [&](double value){ m_vertebrataMotionParameters.armLength = value; - m_parameters = fromVertebrataMotionParameters(m_vertebrataMotionParameters); + m_parameters = fromVertebrataMoveMotionParameters(m_vertebrataMotionParameters); emit parametersChanged(); }); @@ -104,7 +104,7 @@ VertebrataMotionParametersWidget::VertebrataMotionParametersWidget(const std::ma parametersLayout->addRow(tr("Leg side intval: "), legSideIntvalBox); connect(legSideIntvalBox, QOverload::of(&QDoubleSpinBox::valueChanged), [&](double value){ m_vertebrataMotionParameters.legSideIntval = value; - m_parameters = fromVertebrataMotionParameters(m_vertebrataMotionParameters); + m_parameters = fromVertebrataMoveMotionParameters(m_vertebrataMotionParameters); emit parametersChanged(); }); @@ -113,7 +113,7 @@ VertebrataMotionParametersWidget::VertebrataMotionParametersWidget(const std::ma parametersLayout->addRow(tr("Leg balance intval: "), legBalanceIntvalBox); connect(legBalanceIntvalBox, QOverload::of(&QDoubleSpinBox::valueChanged), [&](double value){ m_vertebrataMotionParameters.legBalanceIntval = value; - m_parameters = fromVertebrataMotionParameters(m_vertebrataMotionParameters); + m_parameters = fromVertebrataMoveMotionParameters(m_vertebrataMotionParameters); emit parametersChanged(); }); @@ -122,7 +122,7 @@ VertebrataMotionParametersWidget::VertebrataMotionParametersWidget(const std::ma parametersLayout->addRow(tr("Spine stability: "), spineStabilityBox); connect(spineStabilityBox, QOverload::of(&QDoubleSpinBox::valueChanged), [&](double value){ m_vertebrataMotionParameters.spineStability = value; - m_parameters = fromVertebrataMotionParameters(m_vertebrataMotionParameters); + m_parameters = fromVertebrataMoveMotionParameters(m_vertebrataMotionParameters); emit parametersChanged(); }); @@ -131,7 +131,7 @@ VertebrataMotionParametersWidget::VertebrataMotionParametersWidget(const std::ma parametersLayout->addRow(tr("Cycles: "), cyclesBox); connect(cyclesBox, QOverload::of(&QSpinBox::valueChanged), [&](int value){ m_vertebrataMotionParameters.cycles = value; - m_parameters = fromVertebrataMotionParameters(m_vertebrataMotionParameters); + m_parameters = fromVertebrataMoveMotionParameters(m_vertebrataMotionParameters); emit parametersChanged(); }); @@ -141,7 +141,7 @@ VertebrataMotionParametersWidget::VertebrataMotionParametersWidget(const std::ma parametersLayout->addRow(tr("Ground offset: "), groundOffsetBox); connect(groundOffsetBox, QOverload::of(&QDoubleSpinBox::valueChanged), [&](double value){ m_vertebrataMotionParameters.groundOffset = value; - m_parameters = fromVertebrataMotionParameters(m_vertebrataMotionParameters); + m_parameters = fromVertebrataMoveMotionParameters(m_vertebrataMotionParameters); emit parametersChanged(); }); @@ -152,7 +152,7 @@ VertebrataMotionParametersWidget::VertebrataMotionParametersWidget(const std::ma parametersLayout->addRow(tr("Tail lift force: "), tailLiftForceBox); connect(tailLiftForceBox, QOverload::of(&QDoubleSpinBox::valueChanged), [&](double value){ m_vertebrataMotionParameters.tailLiftForce = value; - m_parameters = fromVertebrataMotionParameters(m_vertebrataMotionParameters); + m_parameters = fromVertebrataMoveMotionParameters(m_vertebrataMotionParameters); emit parametersChanged(); }); @@ -162,7 +162,7 @@ VertebrataMotionParametersWidget::VertebrataMotionParametersWidget(const std::ma parametersLayout->addRow(tr("Tail drag force: "), tailDragForceBox); connect(tailDragForceBox, QOverload::of(&QDoubleSpinBox::valueChanged), [&](double value){ m_vertebrataMotionParameters.tailDragForce = value; - m_parameters = fromVertebrataMotionParameters(m_vertebrataMotionParameters); + m_parameters = fromVertebrataMoveMotionParameters(m_vertebrataMotionParameters); emit parametersChanged(); }); diff --git a/src/vertebratamovemotionparameterswidget.h b/src/vertebratamovemotionparameterswidget.h new file mode 100644 index 00000000..abcbbc3f --- /dev/null +++ b/src/vertebratamovemotionparameterswidget.h @@ -0,0 +1,28 @@ +#ifndef DUST3D_VERTEBRATA_MOVE_MOTION_PARAMETERS_WIDGET_H +#define DUST3D_VERTEBRATA_MOVE_MOTION_PARAMETERS_WIDGET_H +#include +#include +#include +#include "vertebratamovemotionbuilder.h" + +class VertebrataMoveMotionParametersWidget : public QWidget +{ + Q_OBJECT +signals: + void parametersChanged(); +public: + VertebrataMoveMotionParametersWidget(const std::map ¶meters=std::map()); + + const std::map &getParameters() const + { + return m_parameters; + } + + static std::map fromVertebrataMoveMotionParameters(const VertebrataMoveMotionBuilder::Parameters &from); + static VertebrataMoveMotionBuilder::Parameters toVertebrataMoveMotionParameters(const std::map ¶meters); +private: + std::map m_parameters; + VertebrataMoveMotionBuilder::Parameters m_vertebrataMotionParameters; +}; + +#endif