25 #include "glm/gtc/type_ptr.hpp" 26 #include "glm/gtx/intersect.hpp" 39 _highlightFaceIndex(-1),
51 glm::vec3 v0, v1, v2, intersection;
52 glm::vec3 orig = glm::vec3(x, y, 1000.0f);
54 for (
size_t i = 0; i < faceCount; ++i) {
60 if (glm::intersectRayTriangle(orig, glm::vec3(0.0f, 0.0f, -1.0f), v0, v1, v2, intersection)) {
62 return (v0 * (1.0f - intersection.x - intersection.y) +
64 v2 * intersection.y).z;
79 glm::vec3 adjDest = glm::vec3(dest.x, dest.y, 1000.0f);
80 glm::vec3 v0, v1, v2, intersection;
81 glm::vec3 dir = glm::normalize(dest - orig);
83 for (
size_t i = 0; i < faceCount; ++i) {
90 if (glm::intersectRayTriangle(adjDest, glm::vec3(0.0f, 0.0f, -1.0f), v0, v1, v2, intersection))
94 if (glm::intersectRayTriangle(orig, dir, v0, v1, v2, intersection)) {
95 glm::vec3 absIntersection(v0 * (1.0f - intersection.x - intersection.y) +
98 if (glm::distance(orig, absIntersection) <= glm::distance(orig, dest))
121 glVertexPointer(3, GL_FLOAT, 0,
_vertices.data());
122 glEnableClientState(GL_VERTEX_ARRAY);
124 glColor4f(1.0f, 0.0f, 0.0f, 0.5f);
127 glColor4f(0.0f, 1.0f, 0.0f, 0.5f);
130 glDisableClientState(GL_VERTEX_ARRAY);
134 glColor4f(0.0f, 1.0f, 1.0f, 0.5f);
135 glBegin(GL_TRIANGLES);
143 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
150 size_t faceCount =
_indices.size() / 3;
153 for (
size_t i = 0; i < faceCount; ++i) {
bool testCollision(const glm::vec3 &orig, const glm::vec3 &dest) const
Only render transparent parts.
std::vector< uint32 > _indices
std::vector< bool > _faceWalkableMap
void setInvisible(bool invisible)
void render(Graphics::RenderPass pass)
Render the object.
Utility templates and functions.
std::vector< float > _vertices
void refreshIndexGroups()
void highlightFace(uint32 index)
Highlight face with specified index.
std::vector< uint32 > _indicesNonWalkable
An object that can be displayed by the graphics manager.
std::vector< uint32 > _indicesWalkable
Generic renderable walkmesh.
float getElevationAt(float x, float y, uint32 &faceIndex) const
Return elevation at given coordinates or FLT_MIN if can't walk there.
void calculateDistance()
Calculate the object's distance.