mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 16:41:02 +02:00
Merge pull request #2964 from ZappoMan/modelPickingBugs
fix ray picking at distances
This commit is contained in:
commit
6acd60fd55
1 changed files with 11 additions and 24 deletions
|
@ -193,33 +193,20 @@ bool ModelTreeElement::findDetailedRayIntersection(const glm::vec3& origin, cons
|
||||||
// if it's in our AABOX for our rotated extents, then check to see if it's in our non-AABox
|
// if it's in our AABOX for our rotated extents, then check to see if it's in our non-AABox
|
||||||
if (rotatedExtentsBox.findRayIntersection(origin, direction, localDistance, localFace)) {
|
if (rotatedExtentsBox.findRayIntersection(origin, direction, localDistance, localFace)) {
|
||||||
|
|
||||||
// This is experimental code that doesn't quite work, so I'm disabling it by default, but
|
// extents is the model relative, scaled, centered extents of the model
|
||||||
// leaving it in because I need to work on it and fix it to work properly.
|
glm::mat4 rotation = glm::mat4_cast(model.getModelRotation());
|
||||||
bool pickAgainstModelAlignedBox = false;
|
glm::mat4 translation = glm::translate(model.getPosition());
|
||||||
|
glm::mat4 modelToWorldMatrix = translation * rotation;
|
||||||
if (pickAgainstModelAlignedBox) {
|
glm::mat4 worldToModelMatrix = glm::inverse(modelToWorldMatrix);
|
||||||
// extents is the model relative, scaled, centered extents of the model
|
|
||||||
glm::mat4 rotation = glm::mat4_cast(model.getModelRotation());
|
|
||||||
glm::mat4 translation = glm::translate(model.getPosition());
|
|
||||||
glm::mat4 modelToWorldMatrix = translation * rotation;
|
|
||||||
glm::mat4 worldToModelMatrix = glm::inverse(modelToWorldMatrix);
|
|
||||||
|
|
||||||
AABox modelFrameBox(extents.minimum, (extents.maximum - extents.minimum));
|
AABox modelFrameBox(extents.minimum, (extents.maximum - extents.minimum));
|
||||||
|
|
||||||
glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f));
|
glm::vec3 modelFrameOrigin = glm::vec3(worldToModelMatrix * glm::vec4(origin, 1.0f));
|
||||||
glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 1.0f));
|
glm::vec3 modelFrameDirection = glm::vec3(worldToModelMatrix * glm::vec4(direction, 0.0f));
|
||||||
|
|
||||||
// we can use the AABox's ray intersection by mapping our origin and direction into the model frame
|
// we can use the AABox's ray intersection by mapping our origin and direction into the model frame
|
||||||
// and testing intersection there.
|
// and testing intersection there.
|
||||||
if (modelFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, localDistance, localFace)) {
|
if (modelFrameBox.findRayIntersection(modelFrameOrigin, modelFrameDirection, localDistance, localFace)) {
|
||||||
if (localDistance < distance) {
|
|
||||||
distance = localDistance;
|
|
||||||
face = localFace;
|
|
||||||
*intersectedObject = (void*)(&model);
|
|
||||||
somethingIntersected = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (localDistance < distance) {
|
if (localDistance < distance) {
|
||||||
distance = localDistance;
|
distance = localDistance;
|
||||||
face = localFace;
|
face = localFace;
|
||||||
|
|
Loading…
Reference in a new issue