Remaining pick bits.

This commit is contained in:
Andrzej Kapolka 2013-05-03 20:12:46 -07:00
parent f8cbe34e07
commit ff4e21e504
4 changed files with 9 additions and 4 deletions

View file

@ -101,13 +101,13 @@ bool AABox::findRayIntersection(const glm::vec3& origin, const glm::vec3& direct
}
// check each direction
float nt;
if (findIntersection(origin.x, direction.x, _corner.x, _size.x, &nt) &&
if (findIntersection(origin.x, direction.x, _corner.x, _size.x, &nt) && nt >= 0 &&
isWithin(origin.y + nt*direction.y, _corner.y, _size.y) &&
isWithin(origin.z + nt*direction.z, _corner.z, _size.z) ||
findIntersection(origin.y, direction.y, _corner.y, _size.y, &nt) &&
findIntersection(origin.y, direction.y, _corner.y, _size.y, &nt) && nt >= 0 &&
isWithin(origin.x + nt*direction.x, _corner.x, _size.x) &&
isWithin(origin.z + nt*direction.z, _corner.z, _size.z) ||
findIntersection(origin.z, direction.z, _corner.z, _size.z, &nt) &&
findIntersection(origin.z, direction.z, _corner.z, _size.z, &nt) && nt >= 0 &&
isWithin(origin.y + nt*direction.y, _corner.y, _size.y) &&
isWithin(origin.x + nt*direction.x, _corner.x, _size.x)) {
*t = nt;

View file

@ -225,3 +225,7 @@ int ViewFrustum::boxInFrustum(const AABox& box) const {
return(result);
}
void ViewFrustum::computePickRay(float x, float y, glm::vec3* origin, glm::vec3* direction) const {
*origin = _nearTopLeft + x*(_nearTopRight - _nearTopLeft) + y*(_nearBottomLeft - _nearTopLeft);
*direction = glm::normalize(*origin - _position);
}

View file

@ -98,6 +98,7 @@ public:
int sphereInFrustum(const glm::vec3& center, float radius) const;
int boxInFrustum(const AABox& box) const;
void computePickRay(float x, float y, glm::vec3* origin, glm::vec3* direction) const;
};

View file

@ -577,7 +577,7 @@ bool findRayOperation(VoxelNode* node, void* extraData) {
bool VoxelTree::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, VoxelNode** node, float* t)
{
RayArgs args = { origin, direction, node, t };
RayArgs args = { origin / (float)TREE_SCALE, direction, node, t };
recurseTreeWithOperation(findRayOperation, &args);
return args.found;
}