X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FScene.hh;h=107e9938ca3131b18315e18c59894a5145f8f082;hp=f0e829db5e671edcead2652f6aca811f54efea92;hb=25aefe01ef7dbdb603c51411e04b0d6a6107684f;hpb=df541170776dc4ac4f241ca480812bd70bcb6eca diff --git a/src/Moof/Scene.hh b/src/Moof/Scene.hh index f0e829d..107e993 100644 --- a/src/Moof/Scene.hh +++ b/src/Moof/Scene.hh @@ -34,39 +34,107 @@ #include #include +#include #include #include +#include namespace Mf { -class Scene; -typedef boost::shared_ptr SceneP; +OctreeP loadScene(const std::string& name); -class Camera; - -class Scene : public Resource +class Quad : public Entity { - class Impl; - boost::shared_ptr impl_; + Scalar vertices_[12]; + Scalar texCoords_[8]; + + Tilemap tilemap_; + + long detail_; + bool blending_; + bool fog_; public: - inline static SceneP alloc(const std::string& name) + 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) { - return SceneP(new Scene(name)); + fog_ = fog; } - Scene(const std::string& name); + 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(); - void draw(Scalar alpha, const Camera& cam) const; - void refresh(); + glVertexPointer(3, GL_SCALAR, 0, vertices_); + glTexCoordPointer(2, GL_SCALAR, 0, texCoords_); - OctreeP getOctree() const; + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); - static std::string getPath(const std::string& name); + glDisable(GL_BLEND); + glDisable(GL_FOG); + } + + bool isVisible(const Frustum& frustum) const + { + return sphere_.isVisible(frustum); + } };