+ Quad(const Vector3 vertices[4], const std::string& texture,
+ Tilemap::Index tileIndex) :
+ tilemap_(texture),
+ detail_(0),
+ blending_(false),
+ fog_(false)
+ {
+ for (int i = 0, num = 0; i < 4; ++i)
+ {
+ for (int j = 0; j < 3; ++j, ++num)
+ {
+ vertices_[num] = vertices[i][j];
+ }
+ }
+
+ if (!tilemap_.getTileCoords(tileIndex, texCoords_))
+ {
+ logWarning("no index %d in texture %s", tileIndex,
+ texture.c_str());
+
+ texCoords_[0] = texCoords_[1] =
+ texCoords_[3] = texCoords_[6] = 0.0;
+ texCoords_[2] = texCoords_[4] =
+ texCoords_[5] = texCoords_[7] = 1.0;
+ }
+
+ aabb_.encloseVertices(vertices, 4);
+ sphere_.point = aabb_.getCenter();
+ sphere_.radius = (aabb_.min - sphere_.point).length();
+ }
+
+ void setDetail(long detail)
+ {
+ detail_ = detail;
+ }
+
+ void setBlending(bool blending)
+ {
+ blending_ = blending;
+ }
+
+ void setFog(bool fog)
+ {
+ fog_ = fog;
+ }
+
+ void draw(Scalar alpha = 0.0) const
+ {
+ if (blending_)
+ {
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ }
+
+ if (fog_)
+ {
+ glEnable(GL_FOG);
+ glFogi(GL_FOG_MODE, GL_LINEAR);
+ }
+
+ glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ tilemap_.bind();
+
+ glVertexPointer(3, GL_SCALAR, 0, vertices_);
+ glTexCoordPointer(2, GL_SCALAR, 0, texCoords_);
+
+ glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+ glDisable(GL_BLEND);
+ glDisable(GL_FOG);
+ }
+
+ bool isVisible(const Frustum& frustum) const
+ {
+ return sphere_.isVisible(frustum);
+ }