mirror of
https://github.com/overte-org/overte.git
synced 2025-04-09 02:33:19 +02:00
Review fixes
This commit is contained in:
parent
1b75f569b3
commit
fced9e2814
3 changed files with 28 additions and 25 deletions
|
@ -652,13 +652,12 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
|
|||
PROFILE_RANGE(simulation_physics, __FUNCTION__);
|
||||
|
||||
float distance = (float)INT_MAX; // with FLT_MAX bullet rayTest does not return results
|
||||
|
||||
std::vector<MyCharacterController::RayAvatarResult> physicsResults = _myAvatar->getCharacterController()->rayTest(glmToBullet(ray.origin), glmToBullet(ray.direction), distance, QVector<uint>());
|
||||
|
||||
glm::vec3 rayDirection = glm::normalize(ray.direction);
|
||||
std::vector<MyCharacterController::RayAvatarResult> physicsResults = _myAvatar->getCharacterController()->rayTest(glmToBullet(ray.origin), glmToBullet(rayDirection), distance, QVector<uint>());
|
||||
if (physicsResults.size() > 0) {
|
||||
glm::vec3 rayDirectionInv = { ray.direction.x != 0 ? 1.0f / ray.direction.x : INFINITY,
|
||||
ray.direction.y != 0.0f ? 1.0f / ray.direction.y : INFINITY,
|
||||
ray.direction.z != 0.0f ? 1.0f / ray.direction.z : INFINITY };
|
||||
glm::vec3 rayDirectionInv = { rayDirection.x != 0.0f ? 1.0f / rayDirection.x : INFINITY,
|
||||
rayDirection.y != 0.0f ? 1.0f / rayDirection.y : INFINITY,
|
||||
rayDirection.z != 0.0f ? 1.0f / rayDirection.z : INFINITY };
|
||||
|
||||
MyCharacterController::RayAvatarResult rayAvatarResult;
|
||||
AvatarPointer avatar = nullptr;
|
||||
|
@ -697,12 +696,12 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
|
|||
BoxFace face;
|
||||
glm::vec3 surfaceNormal;
|
||||
auto &bbox = mSphere.getBoundingBox();
|
||||
if (bbox.findRayIntersection(ray.origin, ray.direction, rayDirectionInv, boundDistance, face, surfaceNormal)) {
|
||||
if (bbox.findRayIntersection(ray.origin, rayDirection, rayDirectionInv, boundDistance, face, surfaceNormal)) {
|
||||
MyCharacterController::RayAvatarResult boxHit;
|
||||
boxHit._distance = boundDistance;
|
||||
boxHit._intersect = true;
|
||||
boxHit._intersectionNormal = surfaceNormal;
|
||||
boxHit._intersectionPoint = ray.origin + boundDistance * glm::normalize(ray.direction);
|
||||
boxHit._intersectionPoint = ray.origin + boundDistance * rayDirection;
|
||||
boxHit._intersectWithAvatar = avatarID;
|
||||
boxHit._intersectWithJoint = mSphere.getJointIndex();
|
||||
boxHits.push_back(boxHit);
|
||||
|
@ -722,7 +721,7 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
|
|||
}
|
||||
if (pickAgainstMesh) {
|
||||
glm::vec3 localRayOrigin = avatar->worldToJointPoint(ray.origin, rayAvatarResult._intersectWithJoint);
|
||||
glm::vec3 localRayPoint = avatar->worldToJointPoint(ray.origin + ray.direction, rayAvatarResult._intersectWithJoint);
|
||||
glm::vec3 localRayPoint = avatar->worldToJointPoint(ray.origin + rayDirection, rayAvatarResult._intersectWithJoint);
|
||||
|
||||
auto avatarOrientation = avatar->getWorldOrientation();
|
||||
auto avatarPosition = avatar->getWorldPosition();
|
||||
|
@ -737,7 +736,7 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
|
|||
if (avatar->getSkeletonModel()->findRayIntersectionAgainstSubMeshes(defaultFrameRayOrigin, defaultFrameRayDirection, distance, face, surfaceNormal, extraInfo, true, false)) {
|
||||
auto newDistance = glm::length(vec3FromVariant(extraInfo["worldIntersectionPoint"]) - defaultFrameRayOrigin);
|
||||
rayAvatarResult._distance = newDistance;
|
||||
rayAvatarResult._intersectionPoint = ray.origin + newDistance * glm::normalize(ray.direction);
|
||||
rayAvatarResult._intersectionPoint = ray.origin + newDistance * rayDirection;
|
||||
rayAvatarResult._intersectionNormal = surfaceNormal;
|
||||
extraInfo["worldIntersectionPoint"] = vec3toVariant(rayAvatarResult._intersectionPoint);
|
||||
break;
|
||||
|
@ -752,7 +751,7 @@ RayToAvatarIntersectionResult AvatarManager::findRayIntersectionVector(const Pic
|
|||
result.distance = rayAvatarResult._distance;
|
||||
result.surfaceNormal = rayAvatarResult._intersectionNormal;
|
||||
result.jointIndex = rayAvatarResult._intersectWithJoint;
|
||||
result.intersection = ray.origin + rayAvatarResult._distance * glm::normalize(ray.direction);
|
||||
result.intersection = ray.origin + rayAvatarResult._distance * rayDirection;
|
||||
result.extraInfo = extraInfo;
|
||||
result.face = face;
|
||||
}
|
||||
|
|
|
@ -286,6 +286,9 @@ void MultiSphereShape::spheresFromAxes(const std::vector<glm::vec3>& points, con
|
|||
minAverageRadius = glm::min(averageRadius, minAverageRadius);
|
||||
spheres[j]._radius = averageRadius;
|
||||
}
|
||||
if (maxAverageRadius == 0.0f) {
|
||||
maxAverageRadius = 1.0f;
|
||||
}
|
||||
float radiusRatio = maxRadius / maxAverageRadius;
|
||||
// Push the sphere into the bounding box
|
||||
float contractionRatio = 0.8f;
|
||||
|
@ -299,7 +302,7 @@ void MultiSphereShape::spheresFromAxes(const std::vector<glm::vec3>& points, con
|
|||
}
|
||||
spheres[j]._radius = radius;
|
||||
if (distance - radius > 0.0f) {
|
||||
spheres[j]._position = (distance - radius) * glm::normalize(axis);
|
||||
spheres[j]._position = ((distance - radius) / distance) * axis;
|
||||
} else {
|
||||
spheres[j]._position = glm::vec3(0.0f);
|
||||
}
|
||||
|
@ -356,15 +359,15 @@ void MultiSphereShape::calculateDebugLines() {
|
|||
axis.x != 0.0f ? glm::abs(axis.y) / axis.y : 0.0f ,
|
||||
axis.z != 0.0f ? glm::abs(axis.z) / axis.z : 0.0f };
|
||||
bool add = false;
|
||||
if (sign.x == 0) {
|
||||
if (sign.x == 0.0f) {
|
||||
if (sign.y == CORNER_SIGNS[i].y && sign.z == CORNER_SIGNS[i].z) {
|
||||
add = true;
|
||||
}
|
||||
} else if (sign.y == 0) {
|
||||
} else if (sign.y == 0.0f) {
|
||||
if (sign.x == CORNER_SIGNS[i].x && sign.z == CORNER_SIGNS[i].z) {
|
||||
add = true;
|
||||
}
|
||||
} else if (sign.z == 0) {
|
||||
} else if (sign.z == 0.0f) {
|
||||
if (sign.x == CORNER_SIGNS[i].x && sign.y == CORNER_SIGNS[i].y) {
|
||||
add = true;
|
||||
}
|
||||
|
@ -459,14 +462,14 @@ void MultiSphereShape::calculateSphereLines(std::vector<std::pair<glm::vec3, glm
|
|||
} else {
|
||||
uAxis = glm::normalize(glm::cross(glm::vec3(0.0f, 1.0f, 0.0f), mainAxis));
|
||||
vAxis = glm::normalize(glm::cross(mainAxis, uAxis));
|
||||
if ((uAxis.z == 0 && uAxis.x < 0) || (uAxis.x == 0 && uAxis.z < 0)) {
|
||||
if ((uAxis.z == 0.0f && uAxis.x < 0.0f) || (uAxis.x == 0.0f && uAxis.z < 0.0f)) {
|
||||
uAxis = -uAxis;
|
||||
} else if (uAxis.x < 0) {
|
||||
} else if (uAxis.x < 0.0f) {
|
||||
uAxis = -uAxis;
|
||||
}
|
||||
if ((vAxis.z == 0 && vAxis.x < 0) || (vAxis.x == 0 && vAxis.z < 0)) {
|
||||
if ((vAxis.z == 0.0f && vAxis.x < 0.0f) || (vAxis.x == 0.0f && vAxis.z < 0.0f)) {
|
||||
vAxis = -vAxis;
|
||||
} else if (vAxis.x < 0) {
|
||||
} else if (vAxis.x < 0.0f) {
|
||||
vAxis = -vAxis;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -174,17 +174,18 @@ void ThreadSafeDynamicsWorld::saveKinematicState(btScalar timeStep) {
|
|||
}
|
||||
|
||||
void ThreadSafeDynamicsWorld::drawConnectedSpheres(btIDebugDraw* drawer, btScalar radius1, btScalar radius2, const btVector3& position1, const btVector3& position2, const btVector3& color) {
|
||||
int stepDegrees = 30;
|
||||
float stepRadians = PI/6.0f; // 30 degrees
|
||||
btVector3 direction = position2 - position1;
|
||||
btVector3 xAxis = direction.cross(btVector3(0.0f, 1.0f, 0.0f));
|
||||
xAxis = xAxis.length() < EPSILON ? btVector3(1.0f, 0.0f, 0.0f) : xAxis.normalize();
|
||||
btVector3 zAxis = xAxis.cross(btVector3(0.0f, 1.0f, 0.0f));
|
||||
zAxis = (direction.normalize().getY() < EPSILON) ? btVector3(0.0f, 1.0f, 0.0f) : zAxis.normalize();
|
||||
for (int i = 0; i < 360; i += stepDegrees) {
|
||||
float x1 = btSin(btScalar(i)*SIMD_RADS_PER_DEG) * radius1;
|
||||
float z1 = btCos(btScalar(i)*SIMD_RADS_PER_DEG) * radius1;
|
||||
float x2 = btSin(btScalar(i)*SIMD_RADS_PER_DEG) * radius2;
|
||||
float z2 = btCos(btScalar(i)*SIMD_RADS_PER_DEG) * radius2;
|
||||
float fullCircle = 2.0f * PI;
|
||||
for (float i = 0; i < fullCircle; i += stepRadians) {
|
||||
float x1 = btSin(btScalar(i)) * radius1;
|
||||
float z1 = btCos(btScalar(i)) * radius1;
|
||||
float x2 = btSin(btScalar(i)) * radius2;
|
||||
float z2 = btCos(btScalar(i)) * radius2;
|
||||
|
||||
btVector3 addVector1 = xAxis * x1 + zAxis * z1;
|
||||
btVector3 addVector2 = xAxis * x2 + zAxis * z2;
|
||||
|
|
Loading…
Reference in a new issue