mirror of
https://github.com/lubosz/overte.git
synced 2025-08-12 13:36:08 +02:00
fixing findRayIntersection bugs
This commit is contained in:
parent
bfcf4f7865
commit
7130b5aa7f
6 changed files with 59 additions and 16 deletions
|
@ -605,7 +605,6 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o
|
||||||
voxelBox += result3 + Vectors::HALF;
|
voxelBox += result3 + Vectors::HALF;
|
||||||
|
|
||||||
float voxelDistance;
|
float voxelDistance;
|
||||||
|
|
||||||
bool hit = voxelBox.findRayIntersection(glm::vec3(originInVoxel), glm::vec3(directionInVoxel),
|
bool hit = voxelBox.findRayIntersection(glm::vec3(originInVoxel), glm::vec3(directionInVoxel),
|
||||||
voxelDistance, face, surfaceNormal);
|
voxelDistance, face, surfaceNormal);
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ EntityItemID EntityTreeElement::findRayIntersection(const glm::vec3& origin, con
|
||||||
QVariantMap localExtraInfo;
|
QVariantMap localExtraInfo;
|
||||||
float distanceToElementDetails = distance;
|
float distanceToElementDetails = distance;
|
||||||
EntityItemID entityID = findDetailedRayIntersection(origin, direction, element, distanceToElementDetails,
|
EntityItemID entityID = findDetailedRayIntersection(origin, direction, element, distanceToElementDetails,
|
||||||
face, localSurfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, collidableOnly,
|
localFace, localSurfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, collidableOnly,
|
||||||
localExtraInfo, precisionPicking);
|
localExtraInfo, precisionPicking);
|
||||||
if (!entityID.isNull() && distanceToElementDetails < distance) {
|
if (!entityID.isNull() && distanceToElementDetails < distance) {
|
||||||
distance = distanceToElementDetails;
|
distance = distanceToElementDetails;
|
||||||
|
@ -251,6 +251,7 @@ EntityItemID EntityTreeElement::findDetailedRayIntersection(const glm::vec3& ori
|
||||||
distance = localDistance;
|
distance = localDistance;
|
||||||
face = localFace;
|
face = localFace;
|
||||||
surfaceNormal = glm::vec3(rotation * glm::vec4(localSurfaceNormal, 0.0f));
|
surfaceNormal = glm::vec3(rotation * glm::vec4(localSurfaceNormal, 0.0f));
|
||||||
|
extraInfo = QVariantMap();
|
||||||
entityID = entity->getEntityItemID();
|
entityID = entity->getEntityItemID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -316,7 +317,7 @@ EntityItemID EntityTreeElement::findParabolaIntersection(const glm::vec3& origin
|
||||||
QVariantMap localExtraInfo;
|
QVariantMap localExtraInfo;
|
||||||
float distanceToElementDetails = parabolicDistance;
|
float distanceToElementDetails = parabolicDistance;
|
||||||
EntityItemID entityID = findDetailedParabolaIntersection(origin, velocity, acceleration, element, distanceToElementDetails,
|
EntityItemID entityID = findDetailedParabolaIntersection(origin, velocity, acceleration, element, distanceToElementDetails,
|
||||||
face, localSurfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, collidableOnly,
|
localFace, localSurfaceNormal, entityIdsToInclude, entityIdsToDiscard, visibleOnly, collidableOnly,
|
||||||
localExtraInfo, precisionPicking);
|
localExtraInfo, precisionPicking);
|
||||||
if (!entityID.isNull() && distanceToElementDetails < parabolicDistance) {
|
if (!entityID.isNull() && distanceToElementDetails < parabolicDistance) {
|
||||||
parabolicDistance = distanceToElementDetails;
|
parabolicDistance = distanceToElementDetails;
|
||||||
|
@ -405,6 +406,7 @@ EntityItemID EntityTreeElement::findDetailedParabolaIntersection(const glm::vec3
|
||||||
parabolicDistance = localDistance;
|
parabolicDistance = localDistance;
|
||||||
face = localFace;
|
face = localFace;
|
||||||
surfaceNormal = glm::vec3(rotation * glm::vec4(localSurfaceNormal, 0.0f));
|
surfaceNormal = glm::vec3(rotation * glm::vec4(localSurfaceNormal, 0.0f));
|
||||||
|
extraInfo = QVariantMap();
|
||||||
entityID = entity->getEntityItemID();
|
entityID = entity->getEntityItemID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,25 +127,44 @@ void TextEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool TextEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
OctreeElementPointer& element, float& distance,
|
OctreeElementPointer& element, float& distance,
|
||||||
BoxFace& face, glm::vec3& surfaceNormal,
|
BoxFace& face, glm::vec3& surfaceNormal,
|
||||||
QVariantMap& extraInfo, bool precisionPicking) const {
|
QVariantMap& extraInfo, bool precisionPicking) const {
|
||||||
glm::vec3 dimensions = getScaledDimensions();
|
glm::vec3 dimensions = getScaledDimensions();
|
||||||
glm::vec2 xyDimensions(dimensions.x, dimensions.y);
|
glm::vec2 xyDimensions(dimensions.x, dimensions.y);
|
||||||
glm::quat rotation = getWorldOrientation();
|
glm::quat rotation = getWorldOrientation();
|
||||||
glm::vec3 position = getWorldPosition() + rotation *
|
glm::vec3 position = getWorldPosition() + rotation * (dimensions * (ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint()));
|
||||||
(dimensions * (ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint()));
|
|
||||||
|
|
||||||
// FIXME - should set face and surfaceNormal
|
if (findRayRectangleIntersection(origin, direction, rotation, position, xyDimensions, distance)) {
|
||||||
return findRayRectangleIntersection(origin, direction, rotation, position, xyDimensions, distance);
|
glm::vec3 forward = rotation * Vectors::FRONT;
|
||||||
|
if (glm::dot(forward, direction) > 0.0f) {
|
||||||
|
face = MAX_Z_FACE;
|
||||||
|
surfaceNormal = rotation * -Vectors::FRONT;
|
||||||
|
} else {
|
||||||
|
face = MIN_Z_FACE;
|
||||||
|
surfaceNormal = rotation * Vectors::FRONT;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, const glm::vec3& velocity, const glm::vec3& acceleration,
|
bool TextEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, const glm::vec3& velocity, const glm::vec3& acceleration,
|
||||||
OctreeElementPointer& element, float& parabolicDistance,
|
OctreeElementPointer& element, float& parabolicDistance,
|
||||||
BoxFace& face, glm::vec3& surfaceNormal,
|
BoxFace& face, glm::vec3& surfaceNormal,
|
||||||
QVariantMap& extraInfo, bool precisionPicking) const {
|
QVariantMap& extraInfo, bool precisionPicking) const {
|
||||||
// TODO
|
glm::vec3 dimensions = getScaledDimensions();
|
||||||
return false;
|
glm::vec2 xyDimensions(dimensions.x, dimensions.y);
|
||||||
|
glm::quat rotation = getWorldOrientation();
|
||||||
|
glm::vec3 position = getWorldPosition() + rotation * (dimensions * (ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint()));
|
||||||
|
|
||||||
|
if (findParabolaRectangleIntersection(origin, velocity, acceleration, rotation, position, xyDimensions, parabolicDistance)) {
|
||||||
|
// get face and surfaceNormal
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEntityItem::setText(const QString& value) {
|
void TextEntityItem::setText(const QString& value) {
|
||||||
|
|
|
@ -113,8 +113,14 @@ bool WebEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const g
|
||||||
glm::vec3 position = getWorldPosition() + rotation * (dimensions * (ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint()));
|
glm::vec3 position = getWorldPosition() + rotation * (dimensions * (ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint()));
|
||||||
|
|
||||||
if (findRayRectangleIntersection(origin, direction, rotation, position, xyDimensions, distance)) {
|
if (findRayRectangleIntersection(origin, direction, rotation, position, xyDimensions, distance)) {
|
||||||
surfaceNormal = rotation * Vectors::UNIT_Z;
|
glm::vec3 forward = rotation * Vectors::FRONT;
|
||||||
face = glm::dot(surfaceNormal, direction) > 0 ? MIN_Z_FACE : MAX_Z_FACE;
|
if (glm::dot(forward, direction) > 0.0f) {
|
||||||
|
face = MAX_Z_FACE;
|
||||||
|
surfaceNormal = rotation * -Vectors::FRONT;
|
||||||
|
} else {
|
||||||
|
face = MIN_Z_FACE;
|
||||||
|
surfaceNormal = rotation * Vectors::FRONT;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -125,8 +131,17 @@ bool WebEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, co
|
||||||
OctreeElementPointer& element, float& parabolicDistance,
|
OctreeElementPointer& element, float& parabolicDistance,
|
||||||
BoxFace& face, glm::vec3& surfaceNormal,
|
BoxFace& face, glm::vec3& surfaceNormal,
|
||||||
QVariantMap& extraInfo, bool precisionPicking) const {
|
QVariantMap& extraInfo, bool precisionPicking) const {
|
||||||
// TODO
|
glm::vec3 dimensions = getScaledDimensions();
|
||||||
return false;
|
glm::vec2 xyDimensions(dimensions.x, dimensions.y);
|
||||||
|
glm::quat rotation = getWorldOrientation();
|
||||||
|
glm::vec3 position = getWorldPosition() + rotation * (dimensions * (ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint()));
|
||||||
|
|
||||||
|
if (findParabolaRectangleIntersection(origin, velocity, acceleration, rotation, position, xyDimensions, parabolicDistance)) {
|
||||||
|
// get face and surfaceNormal
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebEntityItem::setSourceUrl(const QString& value) {
|
void WebEntityItem::setSourceUrl(const QString& value) {
|
||||||
|
|
|
@ -711,6 +711,11 @@ bool findRayRectangleIntersection(const glm::vec3& origin, const glm::vec3& dire
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool findParabolaRectangleIntersection(const glm::vec3& origin, const glm::vec3& velocity, const glm::vec3& acceleration,
|
||||||
|
const glm::quat& rotation, const glm::vec3& position, const glm::vec2& dimensions, float& parabolicDistance) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void swingTwistDecomposition(const glm::quat& rotation,
|
void swingTwistDecomposition(const glm::quat& rotation,
|
||||||
const glm::vec3& direction,
|
const glm::vec3& direction,
|
||||||
glm::quat& swing,
|
glm::quat& swing,
|
||||||
|
|
|
@ -88,6 +88,9 @@ bool findRayRectangleIntersection(const glm::vec3& origin, const glm::vec3& dire
|
||||||
bool findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
bool findRayTriangleIntersection(const glm::vec3& origin, const glm::vec3& direction,
|
||||||
const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance, bool allowBackface = false);
|
const glm::vec3& v0, const glm::vec3& v1, const glm::vec3& v2, float& distance, bool allowBackface = false);
|
||||||
|
|
||||||
|
bool findParabolaRectangleIntersection(const glm::vec3& origin, const glm::vec3& velocity, const glm::vec3& acceleration, const glm::quat& rotation,
|
||||||
|
const glm::vec3& position, const glm::vec2& dimensions, float& parabolicDistance);
|
||||||
|
|
||||||
/// \brief decomposes rotation into its components such that: rotation = swing * twist
|
/// \brief decomposes rotation into its components such that: rotation = swing * twist
|
||||||
/// \param rotation[in] rotation to decompose
|
/// \param rotation[in] rotation to decompose
|
||||||
/// \param direction[in] normalized axis about which the twist happens (typically original direction before rotation applied)
|
/// \param direction[in] normalized axis about which the twist happens (typically original direction before rotation applied)
|
||||||
|
|
Loading…
Reference in a new issue