Skip to content

Commit

Permalink
ENGINES: Insert loop for ray-casting algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
rjshae authored and DrMcCoy committed Nov 3, 2018
1 parent 5c1025c commit 6a49c7d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/engines/aurora/trigger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,26 @@ bool Trigger::contains(float x, float y) const {
if (!_boundingbox.isIn(x, y))
return false;

glm::vec3 orig(x, y, 1000);
glm::vec3 intersection;

for (size_t i = 2; i < vertexCount; ++i) {
if (glm::intersectRayTriangle(orig,
glm::vec3(0, 0, -1),
_geometry[0],
_geometry[i - 1],
_geometry[i],
intersection) == 1) {
return true;
}
// Initialization
std::vector<glm::vec3>::const_iterator it1, it2;
int count = 0;

// Set first iterator to the last vertex
it1 = _geometry.end();
it1--;

// Cycle through the vertices, counting the number of ray intersections
for (it2 = _geometry.begin(); it2 != _geometry.end(); ++it2) {
// Check for a ray intersection
if (isRayIntersect(x, y, it1->x, it1->y, it2->x, it2->y))
count++;

// Store for the next loop
it1 = it2;
}

return false;
// Ray-casting algorithm
return (count % 2) ? true : false;
}

void Trigger::calculateDistance() {
Expand Down Expand Up @@ -117,4 +122,14 @@ void Trigger::prepare() {
_prepared = true;
}

/*
* Return true if a ray extending from (x, y) to (x, infinity)
* intersects the line segment from (x1, y1) to (x2, y2).
*/
bool Trigger::isRayIntersect(float x, float y,
float x1, float y1,
float x2, float y2) const {
return true; // TODO
}

} // End of namespace Engines
4 changes: 4 additions & 0 deletions src/engines/aurora/trigger.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class Trigger : public Graphics::Renderable {
private:
bool _prepared;
Common::BoundingBox _boundingbox;

bool isRayIntersect(float x, float y,
float x1, float y1,
float x2, float y2) const;
};

} // End of namespace Engines
Expand Down

0 comments on commit 6a49c7d

Please sign in to comment.