2021-11-18 14:58:01 +00:00
|
|
|
#ifndef DUST3D_APPLICATION_CCD_IK_SOLVER_H_
|
|
|
|
#define DUST3D_APPLICATION_CCD_IK_SOLVER_H_
|
|
|
|
|
2018-05-24 01:44:40 +00:00
|
|
|
#include <QQuaternion>
|
2022-10-18 09:35:04 +00:00
|
|
|
#include <QVector3D>
|
|
|
|
#include <vector>
|
2018-05-24 01:44:40 +00:00
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
struct CcdIkNode {
|
2018-05-24 01:44:40 +00:00
|
|
|
QVector3D position;
|
2020-11-09 10:46:06 +00:00
|
|
|
QVector3D axis;
|
|
|
|
double minLimitDegrees;
|
|
|
|
double maxLimitDegrees;
|
2018-05-24 01:44:40 +00:00
|
|
|
};
|
|
|
|
|
2022-10-18 09:35:04 +00:00
|
|
|
class CcdIkSolver {
|
2018-05-24 01:44:40 +00:00
|
|
|
public:
|
2020-11-09 10:46:06 +00:00
|
|
|
CcdIkSolver();
|
2018-05-24 01:44:40 +00:00
|
|
|
void setMaxRound(int maxRound);
|
|
|
|
void setDistanceThreshod(float threshold);
|
2022-10-18 09:35:04 +00:00
|
|
|
int addNodeInOrder(const QVector3D& position);
|
|
|
|
void solveTo(const QVector3D& position);
|
|
|
|
const QVector3D& getNodeSolvedPosition(int index);
|
2020-11-09 10:46:06 +00:00
|
|
|
int getNodeCount();
|
|
|
|
void setNodeHingeConstraint(int nodeIndex,
|
2022-10-18 09:35:04 +00:00
|
|
|
const QVector3D& axis, double minLimitDegrees, double maxLimitDegrees);
|
2020-11-09 10:46:06 +00:00
|
|
|
void setSolveFrom(int fromNodeIndex);
|
2022-10-18 09:35:04 +00:00
|
|
|
|
2018-05-24 01:44:40 +00:00
|
|
|
private:
|
2021-11-18 14:58:01 +00:00
|
|
|
float angleInRangle360BetweenTwoVectors(QVector3D a, QVector3D b, QVector3D planeNormal);
|
2018-05-24 01:44:40 +00:00
|
|
|
void iterate();
|
2021-11-18 14:58:01 +00:00
|
|
|
|
2020-11-09 10:46:06 +00:00
|
|
|
std::vector<CcdIkNode> m_nodes;
|
2018-05-24 01:44:40 +00:00
|
|
|
QVector3D m_destination;
|
2020-11-09 10:46:06 +00:00
|
|
|
int m_maxRound = 4;
|
|
|
|
float m_distanceThreshold2 = 0.001 * 0.001;
|
|
|
|
float m_distanceCeaseThreshold2 = 0.001 * 0.001;
|
|
|
|
int m_fromNodeIndex = 0;
|
2018-05-24 01:44:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|