mirror of
https://github.com/overte-org/overte.git
synced 2025-08-12 23:40:00 +02:00
RenderableEntityItem uses collision hull in contains
This commit is contained in:
parent
8db9f80779
commit
955723acf1
4 changed files with 43 additions and 0 deletions
|
@ -415,3 +415,35 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RenderableModelEntityItem::contains(const glm::vec3& point) const {
|
||||||
|
bool result = EntityItem::contains(point);
|
||||||
|
|
||||||
|
if (result && _model && _model->getCollisionGeometry()) {
|
||||||
|
const QSharedPointer<NetworkGeometry> collisionNetworkGeometry = _model->getCollisionGeometry();
|
||||||
|
const FBXGeometry& collisionGeometry = collisionNetworkGeometry->getFBXGeometry();
|
||||||
|
|
||||||
|
auto checkEachPrimitive = [=](FBXMesh& mesh, QVector<int> indices, int primitiveSize) -> bool {
|
||||||
|
for (unsigned int j = 0; j < indices.size(); j += primitiveSize) {
|
||||||
|
if (!isPointBehindTrianglesPlane(point,
|
||||||
|
mesh.vertices[indices[j]],
|
||||||
|
mesh.vertices[indices[j + 1]],
|
||||||
|
mesh.vertices[indices[j + 2]])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto mesh : collisionGeometry.meshes) {
|
||||||
|
for (auto part : mesh.parts) {
|
||||||
|
// run through all the triangles and quads
|
||||||
|
if (!checkEachPrimitive(mesh, part.triangleIndices, 3) ||
|
||||||
|
!checkEachPrimitive(mesh, part.quadIndices, 4)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
@ -57,6 +57,8 @@ public:
|
||||||
bool isReadyToComputeShape();
|
bool isReadyToComputeShape();
|
||||||
void computeShapeInfo(ShapeInfo& info);
|
void computeShapeInfo(ShapeInfo& info);
|
||||||
|
|
||||||
|
virtual bool contains(const glm::vec3& point) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void remapTextures();
|
void remapTextures();
|
||||||
|
|
||||||
|
|
|
@ -203,6 +203,13 @@ glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2) {
|
||||||
return glm::angleAxis(angle, axis);
|
return glm::angleAxis(angle, axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isPointBehindTrianglesPlane(glm::vec3 point, glm::vec3 p0, glm::vec3 p1, glm::vec3 p2) {
|
||||||
|
glm::vec3 v1 = p0 - p1, v2 = p2 - p1; // Non-collinear vectors contained in the plane
|
||||||
|
glm::vec3 n = glm::cross(v1, v2); // Plane's normal vector, pointing out of the triangle
|
||||||
|
float d = -glm::dot(n, p0); // Compute plane's equation constant
|
||||||
|
return (glm::dot(n, point) + d) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
glm::vec3 extractTranslation(const glm::mat4& matrix) {
|
glm::vec3 extractTranslation(const glm::mat4& matrix) {
|
||||||
return glm::vec3(matrix[3][0], matrix[3][1], matrix[3][2]);
|
return glm::vec3(matrix[3][0], matrix[3][1], matrix[3][2]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,8 @@ float angleBetween(const glm::vec3& v1, const glm::vec3& v2);
|
||||||
|
|
||||||
glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2);
|
glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2);
|
||||||
|
|
||||||
|
bool isPointBehindTrianglesPlane(glm::vec3 point, glm::vec3 p0, glm::vec3 p1, glm::vec3 p2);
|
||||||
|
|
||||||
glm::vec3 extractTranslation(const glm::mat4& matrix);
|
glm::vec3 extractTranslation(const glm::mat4& matrix);
|
||||||
|
|
||||||
void setTranslation(glm::mat4& matrix, const glm::vec3& translation);
|
void setTranslation(glm::mat4& matrix, const glm::vec3& translation);
|
||||||
|
|
Loading…
Reference in a new issue