Fix angle calculation
parent
74bbae57e4
commit
e725bdba8c
|
@ -41,6 +41,7 @@ MousePicker::~MousePicker()
|
|||
bool MousePicker::calculateMouseModelPosition(QVector3D &mouseModelPosition)
|
||||
{
|
||||
bool foundPosition = false;
|
||||
auto ray = (m_mouseRayNear - m_mouseRayFar).normalized();
|
||||
float minDistance2 = std::numeric_limits<float>::max();
|
||||
for (size_t i = 0; i < m_outcome.triangles.size(); ++i) {
|
||||
const auto &triangleIndices = m_outcome.triangles[i];
|
||||
|
@ -50,6 +51,8 @@ bool MousePicker::calculateMouseModelPosition(QVector3D &mouseModelPosition)
|
|||
m_outcome.vertices[triangleIndices[2]],
|
||||
};
|
||||
const auto &triangleNormal = m_outcome.triangleNormals[i];
|
||||
if (QVector3D::dotProduct(triangleNormal, ray) <= 0)
|
||||
continue;
|
||||
QVector3D intersection;
|
||||
if (intersectSegmentAndTriangle(m_mouseRayNear, m_mouseRayFar,
|
||||
triangle,
|
||||
|
@ -63,7 +66,7 @@ bool MousePicker::calculateMouseModelPosition(QVector3D &mouseModelPosition)
|
|||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return foundPosition;
|
||||
}
|
||||
|
||||
void MousePicker::pick()
|
||||
|
@ -80,21 +83,24 @@ void MousePicker::pick()
|
|||
for (const auto &node: map.paintNodes) {
|
||||
if (!m_mousePickMaskNodeIds.empty() && m_mousePickMaskNodeIds.find(node.originNodeId) == m_mousePickMaskNodeIds.end())
|
||||
continue;
|
||||
float sumOfDistance = 0;
|
||||
size_t intersectedNum = 0;
|
||||
QVector3D sumOfDirection;
|
||||
QVector3D referenceDirection = (m_targetPosition - node.origin).normalized();
|
||||
float sumOfRadius = 0;
|
||||
for (const auto &vertexPosition: node.vertices) {
|
||||
if (QVector3D::dotProduct(referenceDirection, (vertexPosition - node.origin).normalized()) > 0 &&
|
||||
// >0.866 = <30 degrees
|
||||
auto direction = (vertexPosition - node.origin).normalized();
|
||||
if (QVector3D::dotProduct(referenceDirection, direction) > 0.866 &&
|
||||
(vertexPosition - m_targetPosition).lengthSquared() <= distance2) {
|
||||
sumOfDistance += vertexPosition.distanceToPoint(m_targetPosition);
|
||||
sumOfDirection += (vertexPosition - node.origin).normalized();
|
||||
float distance = vertexPosition.distanceToPoint(m_targetPosition);
|
||||
float radius = (m_radius - distance) / node.radius;
|
||||
sumOfRadius += radius;
|
||||
sumOfDirection += direction * radius;
|
||||
++intersectedNum;
|
||||
}
|
||||
}
|
||||
if (intersectedNum > 0) {
|
||||
float averageDistance = sumOfDistance / intersectedNum;
|
||||
float paintRadius = (m_radius - averageDistance) / node.radius;
|
||||
float paintRadius = sumOfRadius / intersectedNum;
|
||||
QVector3D paintDirection = sumOfDirection.normalized();
|
||||
float degrees = angleInRangle360BetweenTwoVectors(node.baseNormal, paintDirection, node.direction);
|
||||
float offset = (float)node.order / map.paintNodes.size();
|
||||
|
@ -133,10 +139,10 @@ void MousePicker::paintToImage(const QUuid &partId, float x, float y, float radi
|
|||
{
|
||||
QRadialGradient gradient(destX, destY, destRadius / 2);
|
||||
if (inverted) {
|
||||
gradient.setColorAt(0, QColor(0, 0, 0, 2));
|
||||
gradient.setColorAt(0, QColor(0, 0, 0, 3));
|
||||
gradient.setColorAt(1, Qt::transparent);
|
||||
} else {
|
||||
gradient.setColorAt(0, QColor(255, 255, 255, 2));
|
||||
gradient.setColorAt(0, QColor(255, 255, 255, 3));
|
||||
gradient.setColorAt(1, Qt::transparent);
|
||||
}
|
||||
QBrush brush(gradient);
|
||||
|
|
|
@ -43,7 +43,7 @@ float angleInRangle360BetweenTwoVectors(QVector3D a, QVector3D b, QVector3D plan
|
|||
float degrees = acos(QVector3D::dotProduct(a, b)) * 180.0 / M_PI;
|
||||
QVector3D direct = QVector3D::crossProduct(a, b);
|
||||
if (QVector3D::dotProduct(direct, planeNormal) < 0)
|
||||
return 180 + degrees;
|
||||
return 360 - degrees;
|
||||
return degrees;
|
||||
}
|
||||
|
||||
|
|
|
@ -412,6 +412,7 @@ bool Builder::build()
|
|||
|
||||
unifyBaseNormals();
|
||||
localAverageBaseNormals();
|
||||
unifyBaseNormals();
|
||||
|
||||
for (const auto &nodeIndex: m_sortedNodeIndices) {
|
||||
if (!generateCutsForNode(nodeIndex))
|
||||
|
|
|
@ -38,7 +38,7 @@ float nodemesh::degreeBetweenIn360(const QVector3D &a, const QVector3D &b, const
|
|||
auto angle = radianToDegree(angleBetween(a, b));
|
||||
auto c = QVector3D::crossProduct(a, b);
|
||||
if (QVector3D::dotProduct(c, direct) < 0) {
|
||||
angle += 180;
|
||||
angle = 360 - angle;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ bool ChartPacker::tryPack(float textureSize)
|
|||
std::vector<maxRectsSize> rects;
|
||||
int width = textureSize * m_floatToIntFactor;
|
||||
int height = width;
|
||||
if (m_tryNum > 50) {
|
||||
//qDebug() << "Try the " << m_tryNum << "nth times pack with factor:" << m_textureSizeFactor << " size:" << width << "x" << height;
|
||||
}
|
||||
//if (m_tryNum > 50) {
|
||||
// qDebug() << "Try the " << m_tryNum << "nth times pack with factor:" << m_textureSizeFactor << " size:" << width << "x" << height;
|
||||
//}
|
||||
float paddingSize = m_paddingSize * width;
|
||||
float paddingSize2 = paddingSize + paddingSize;
|
||||
for (const auto &chartSize: m_chartSizes) {
|
||||
|
|
|
@ -21,11 +21,11 @@ private:
|
|||
std::vector<std::pair<float, float>> m_chartSizes;
|
||||
std::vector<std::tuple<float, float, float, float, bool>> m_result;
|
||||
float m_initialAreaGuessFactor = 1.1;
|
||||
float m_textureSizeGrowFactor = 0.01;
|
||||
float m_textureSizeGrowFactor = 0.05;
|
||||
float m_floatToIntFactor = 10000;
|
||||
size_t m_tryNum = 0;
|
||||
float m_textureSizeFactor = 1.0;
|
||||
float m_paddingSize = 0.001;
|
||||
float m_paddingSize = 0.002;
|
||||
size_t m_maxTryNum = 100;
|
||||
};
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ static float angle360(const Eigen::Vector3d &a, const Eigen::Vector3d &b, const
|
|||
auto angle = atan2((a.cross(b)).norm(), a.dot(b)) * 180.0 / 3.1415926;
|
||||
auto c = a.cross(b);
|
||||
if (c.dot(direct) < 0) {
|
||||
angle += 180;
|
||||
angle = 360 - angle;
|
||||
}
|
||||
return angle;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue