X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FScene.hh;h=107e9938ca3131b18315e18c59894a5145f8f082;hp=db25db7a42ea096c0e017e6b008ba5695fc039b0;hb=25aefe01ef7dbdb603c51411e04b0d6a6107684f;hpb=29e3d45f7bbbf31eadf793c41ff2b3d9c47b7539 diff --git a/src/Moof/Scene.hh b/src/Moof/Scene.hh index db25db7..107e993 100644 --- a/src/Moof/Scene.hh +++ b/src/Moof/Scene.hh @@ -34,25 +34,107 @@ #include #include +#include +#include #include +#include namespace Mf { -class Scene : public Resource, public Drawable +OctreeP loadScene(const std::string& name); + + +class Quad : public Entity { -public: - Scene(const std::string& name); + Scalar vertices_[12]; + Scalar texCoords_[8]; + + Tilemap tilemap_; - void draw(Scalar alpha) const; - void refresh(); + long detail_; + bool blending_; + bool fog_; - static std::string getPathToResource(const std::string& name); +public: -private: - class SceneImpl; - boost::shared_ptr impl_; + 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); + } };