mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-26 03:55:08 +02:00
Add normalOnPick to CollisionPickResult
This commit is contained in:
parent
3b7dac9058
commit
87b5605d69
5 changed files with 17 additions and 5 deletions
|
@ -51,6 +51,7 @@ void buildObjectIntersectionsMap(IntersectionType intersectionType, const std::v
|
||||||
QVariantMap collisionPointPair;
|
QVariantMap collisionPointPair;
|
||||||
collisionPointPair["pointOnPick"] = vec3toVariant(objectIntersection.testCollisionPoint);
|
collisionPointPair["pointOnPick"] = vec3toVariant(objectIntersection.testCollisionPoint);
|
||||||
collisionPointPair["pointOnObject"] = vec3toVariant(objectIntersection.foundCollisionPoint);
|
collisionPointPair["pointOnObject"] = vec3toVariant(objectIntersection.foundCollisionPoint);
|
||||||
|
collisionPointPair["normalOnPick"] = vec3toVariant(objectIntersection.collisionNormal);
|
||||||
|
|
||||||
collisionPointPairs[objectIntersection.foundID].append(collisionPointPair);
|
collisionPointPairs[objectIntersection.foundID].append(collisionPointPair);
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,9 @@ protected:
|
||||||
CollisionRegion _mathPick;
|
CollisionRegion _mathPick;
|
||||||
PhysicsEnginePointer _physicsEngine;
|
PhysicsEnginePointer _physicsEngine;
|
||||||
QSharedPointer<GeometryResource> _cachedResource;
|
QSharedPointer<GeometryResource> _cachedResource;
|
||||||
|
|
||||||
|
// Options for what information to get from collision results
|
||||||
|
bool _includeNormals;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_CollisionPick_h
|
#endif // hifi_CollisionPick_h
|
|
@ -167,6 +167,7 @@ public:
|
||||||
* @typedef {object} CollisionContact
|
* @typedef {object} CollisionContact
|
||||||
* @property {Vec3} pointOnPick A point representing a penetration of the object's surface into the volume of the pick, in world space.
|
* @property {Vec3} pointOnPick A point representing a penetration of the object's surface into the volume of the pick, in world space.
|
||||||
* @property {Vec3} pointOnObject A point representing a penetration of the pick's surface into the volume of the found object, in world space.
|
* @property {Vec3} pointOnObject A point representing a penetration of the pick's surface into the volume of the found object, in world space.
|
||||||
|
* @property {Vec3} normalOnPick The normalized vector pointing away from the pick, representing the direction of collision.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
|
|
|
@ -935,19 +935,22 @@ struct AllContactsCallback : public btCollisionWorld::ContactResultCallback {
|
||||||
const btCollisionObject* otherBody;
|
const btCollisionObject* otherBody;
|
||||||
btVector3 penetrationPoint;
|
btVector3 penetrationPoint;
|
||||||
btVector3 otherPenetrationPoint;
|
btVector3 otherPenetrationPoint;
|
||||||
|
btVector3 normal;
|
||||||
if (colObj0->m_collisionObject == &collisionObject) {
|
if (colObj0->m_collisionObject == &collisionObject) {
|
||||||
otherBody = colObj1->m_collisionObject;
|
otherBody = colObj1->m_collisionObject;
|
||||||
penetrationPoint = getWorldPoint(cp.m_localPointB, colObj1->getWorldTransform());
|
penetrationPoint = getWorldPoint(cp.m_localPointB, colObj1->getWorldTransform());
|
||||||
otherPenetrationPoint = getWorldPoint(cp.m_localPointA, colObj0->getWorldTransform());
|
otherPenetrationPoint = getWorldPoint(cp.m_localPointA, colObj0->getWorldTransform());
|
||||||
|
normal = -cp.m_normalWorldOnB;
|
||||||
} else {
|
} else {
|
||||||
otherBody = colObj0->m_collisionObject;
|
otherBody = colObj0->m_collisionObject;
|
||||||
penetrationPoint = getWorldPoint(cp.m_localPointA, colObj0->getWorldTransform());
|
penetrationPoint = getWorldPoint(cp.m_localPointA, colObj0->getWorldTransform());
|
||||||
otherPenetrationPoint = getWorldPoint(cp.m_localPointB, colObj1->getWorldTransform());
|
otherPenetrationPoint = getWorldPoint(cp.m_localPointB, colObj1->getWorldTransform());
|
||||||
|
normal = cp.m_normalWorldOnB;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Give MyAvatar a motion state so we don't have to do this
|
// TODO: Give MyAvatar a motion state so we don't have to do this
|
||||||
if ((m_collisionFilterMask & BULLET_COLLISION_GROUP_MY_AVATAR) && myAvatarCollisionObject && myAvatarCollisionObject == otherBody) {
|
if ((m_collisionFilterMask & BULLET_COLLISION_GROUP_MY_AVATAR) && myAvatarCollisionObject && myAvatarCollisionObject == otherBody) {
|
||||||
contacts.emplace_back(Physics::getSessionUUID(), bulletToGLM(penetrationPoint), bulletToGLM(otherPenetrationPoint));
|
contacts.emplace_back(Physics::getSessionUUID(), bulletToGLM(penetrationPoint), bulletToGLM(otherPenetrationPoint), bulletToGLM(normal));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -963,7 +966,7 @@ struct AllContactsCallback : public btCollisionWorld::ContactResultCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is the correct object type. Add it to the list.
|
// This is the correct object type. Add it to the list.
|
||||||
contacts.emplace_back(candidate->getObjectID(), bulletToGLM(penetrationPoint), bulletToGLM(otherPenetrationPoint));
|
contacts.emplace_back(candidate->getObjectID(), bulletToGLM(penetrationPoint), bulletToGLM(otherPenetrationPoint), bulletToGLM(normal));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,13 +49,15 @@ struct ContactTestResult {
|
||||||
ContactTestResult(const ContactTestResult& contactTestResult) :
|
ContactTestResult(const ContactTestResult& contactTestResult) :
|
||||||
foundID(contactTestResult.foundID),
|
foundID(contactTestResult.foundID),
|
||||||
testCollisionPoint(contactTestResult.testCollisionPoint),
|
testCollisionPoint(contactTestResult.testCollisionPoint),
|
||||||
foundCollisionPoint(contactTestResult.foundCollisionPoint) {
|
foundCollisionPoint(contactTestResult.foundCollisionPoint),
|
||||||
|
collisionNormal(contactTestResult.collisionNormal) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ContactTestResult(QUuid foundID, glm::vec3 testCollisionPoint, glm::vec3 otherCollisionPoint) :
|
ContactTestResult(const QUuid& foundID, const glm::vec3& testCollisionPoint, const glm::vec3& otherCollisionPoint, const glm::vec3& collisionNormal) :
|
||||||
foundID(foundID),
|
foundID(foundID),
|
||||||
testCollisionPoint(testCollisionPoint),
|
testCollisionPoint(testCollisionPoint),
|
||||||
foundCollisionPoint(otherCollisionPoint) {
|
foundCollisionPoint(otherCollisionPoint),
|
||||||
|
collisionNormal(collisionNormal) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid foundID;
|
QUuid foundID;
|
||||||
|
@ -63,6 +65,8 @@ struct ContactTestResult {
|
||||||
glm::vec3 testCollisionPoint;
|
glm::vec3 testCollisionPoint;
|
||||||
// The deepest point of an intersection within the volume of the found object, in world space.
|
// The deepest point of an intersection within the volume of the found object, in world space.
|
||||||
glm::vec3 foundCollisionPoint;
|
glm::vec3 foundCollisionPoint;
|
||||||
|
// The normal vector of this intersection
|
||||||
|
glm::vec3 collisionNormal;
|
||||||
};
|
};
|
||||||
|
|
||||||
using ContactMap = std::map<ContactKey, ContactInfo>;
|
using ContactMap = std::map<ContactKey, ContactInfo>;
|
||||||
|
|
Loading…
Reference in a new issue