mirror of
https://github.com/lubosz/overte.git
synced 2025-04-27 00:35:37 +02:00
parabola vs. web and text
This commit is contained in:
parent
7130b5aa7f
commit
bbe9a0005d
6 changed files with 63 additions and 12 deletions
libraries
entities/src
shared/src
|
@ -160,7 +160,17 @@ bool TextEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, c
|
|||
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
|
||||
glm::quat inverseRot = glm::inverse(rotation);
|
||||
glm::vec3 localVelocity = inverseRot * velocity;
|
||||
glm::vec3 localAcceleration = inverseRot * acceleration;
|
||||
float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance;
|
||||
if (localIntersectionVelocityZ > 0.0f) {
|
||||
face = MIN_Z_FACE;
|
||||
surfaceNormal = rotation * Vectors::FRONT;
|
||||
} else {
|
||||
face = MAX_Z_FACE;
|
||||
surfaceNormal = rotation * -Vectors::FRONT;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -137,7 +137,17 @@ bool WebEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, co
|
|||
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
|
||||
glm::quat inverseRot = glm::inverse(rotation);
|
||||
glm::vec3 localVelocity = inverseRot * velocity;
|
||||
glm::vec3 localAcceleration = inverseRot * acceleration;
|
||||
float localIntersectionVelocityZ = localVelocity.z + localAcceleration.z * parabolicDistance;
|
||||
if (localIntersectionVelocityZ > 0.0f) {
|
||||
face = MIN_Z_FACE;
|
||||
surfaceNormal = rotation * Vectors::FRONT;
|
||||
} else {
|
||||
face = MAX_Z_FACE;
|
||||
surfaceNormal = rotation * -Vectors::FRONT;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -109,11 +109,6 @@ glm::vec3 AABox::getNearestVertex(const glm::vec3& normal) const {
|
|||
return result;
|
||||
}
|
||||
|
||||
// determines whether a value is within the extents
|
||||
static bool isWithin(float value, float corner, float size) {
|
||||
return value >= corner && value <= corner + size;
|
||||
}
|
||||
|
||||
bool AABox::contains(const Triangle& triangle) const {
|
||||
return contains(triangle.v0) && contains(triangle.v1) && contains(triangle.v2);
|
||||
}
|
||||
|
@ -308,6 +303,7 @@ bool AABox::findParabolaIntersection(const glm::vec3& origin, const glm::vec3& v
|
|||
// Solve the intersection for each face of the cube. As we go, keep track of the smallest, positive, real distance
|
||||
// that is within the bounds of the other two dimensions
|
||||
for (int i = 0; i < 3; i++) {
|
||||
// TODO: handle case where a is 0
|
||||
a = 0.5f * acceleration[i];
|
||||
b = velocity[i];
|
||||
if (origin[i] < _corner[i]) {
|
||||
|
|
|
@ -110,11 +110,6 @@ glm::vec3 AACube::getNearestVertex(const glm::vec3& normal) const {
|
|||
return result;
|
||||
}
|
||||
|
||||
// determines whether a value is within the extents
|
||||
static bool isWithin(float value, float corner, float size) {
|
||||
return value >= corner && value <= corner + size;
|
||||
}
|
||||
|
||||
bool AACube::contains(const glm::vec3& point) const {
|
||||
return isWithin(point.x, _corner.x, _scale) &&
|
||||
isWithin(point.y, _corner.y, _scale) &&
|
||||
|
@ -304,6 +299,7 @@ bool AACube::findParabolaIntersection(const glm::vec3& origin, const glm::vec3&
|
|||
// Solve the intersection for each face of the cube. As we go, keep track of the smallest, positive, real distance
|
||||
// that is within the bounds of the other two dimensions
|
||||
for (int i = 0; i < 3; i++) {
|
||||
// TODO: handle case where a is 0
|
||||
a = 0.5f * acceleration[i];
|
||||
b = velocity[i];
|
||||
if (origin[i] < _corner[i]) {
|
||||
|
|
|
@ -711,8 +711,42 @@ bool findRayRectangleIntersection(const glm::vec3& origin, const glm::vec3& dire
|
|||
return false;
|
||||
}
|
||||
|
||||
// determines whether a value is within the extents
|
||||
bool isWithin(float value, float corner, float size) {
|
||||
return value >= corner && value <= corner + size;
|
||||
}
|
||||
|
||||
void checkPossibleParabolicIntersectionWithZPlane(float t, float& minDistance,
|
||||
const glm::vec3& origin, const glm::vec3& velocity, const glm::vec3& acceleration, const glm::vec2& corner, const glm::vec2& scale) {
|
||||
if (t < minDistance && t > 0.0f &&
|
||||
isWithin(origin.x + velocity.x * t + 0.5f * acceleration.x * t * t, corner.x, scale.x) &&
|
||||
isWithin(origin.y + velocity.y * t + 0.5f * acceleration.y * t * t, corner.y, scale.y)) {
|
||||
minDistance = t;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
glm::quat inverseRot = glm::inverse(rotation);
|
||||
glm::vec3 localOrigin = inverseRot * (origin - position);
|
||||
glm::vec3 localVelocity = inverseRot * velocity;
|
||||
glm::vec3 localAcceleration = inverseRot * acceleration;
|
||||
|
||||
glm::vec2 localCorner = -0.5f * dimensions;
|
||||
|
||||
float minDistance = FLT_MAX;
|
||||
float a = 0.5f * localAcceleration.z;
|
||||
float b = localVelocity.z;
|
||||
float c = localOrigin.z;
|
||||
std::pair<float, float> possibleDistances = { FLT_MAX, FLT_MAX };
|
||||
if (computeRealQuadraticRoots(a, b, c, possibleDistances)) {
|
||||
checkPossibleParabolicIntersectionWithZPlane(possibleDistances.first, minDistance, localOrigin, localVelocity, localAcceleration, localCorner, dimensions);
|
||||
checkPossibleParabolicIntersectionWithZPlane(possibleDistances.second, minDistance, localOrigin, localVelocity, localAcceleration, localCorner, dimensions);
|
||||
}
|
||||
if (minDistance < FLT_MAX) {
|
||||
parabolicDistance = minDistance;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -183,4 +183,9 @@ void generateBoundryLinesForDop14(const std::vector<float>& dots, const glm::vec
|
|||
|
||||
bool computeRealQuadraticRoots(float a, float b, float c, std::pair<float, float>& roots);
|
||||
|
||||
bool isWithin(float value, float corner, float size);
|
||||
|
||||
void checkPossibleParabolicIntersectionWithZPlane(float t, float& minDistance,
|
||||
const glm::vec3& origin, const glm::vec3& velocity, const glm::vec3& acceleration, const glm::vec2& corner, const glm::vec2& scale);
|
||||
|
||||
#endif // hifi_GeometryUtil_h
|
||||
|
|
Loading…
Reference in a new issue