]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Scene.hh
refactoring the scene class
[chaz/yoink] / src / Moof / Scene.hh
index f0e829db5e671edcead2652f6aca811f54efea92..107e9938ca3131b18315e18c59894a5145f8f082 100644 (file)
 #include <boost/shared_ptr.hpp>
 
 #include <Moof/Drawable.hh>
 #include <boost/shared_ptr.hpp>
 
 #include <Moof/Drawable.hh>
+#include <Moof/Entity.hh>
 #include <Moof/Octree.hh>
 #include <Moof/Resource.hh>
 #include <Moof/Octree.hh>
 #include <Moof/Resource.hh>
+#include <Moof/Tilemap.hh>
 
 
 namespace Mf {
 
 
 
 
 namespace Mf {
 
 
-class Scene;
-typedef boost::shared_ptr<Scene> SceneP;
+OctreeP loadScene(const std::string& name);
 
 
-class Camera;
 
 
-
-class Scene : public Resource
+class Quad : public Entity
 {
 {
-       class Impl;
-       boost::shared_ptr<Impl> impl_;
+       Scalar          vertices_[12];
+       Scalar          texCoords_[8];
+       
+       Tilemap         tilemap_;
+
+       long            detail_;
+       bool            blending_;
+       bool            fog_;
 
 public:
 
 
 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);
+       }
 };
 
 
 };
 
 
This page took 0.021731 seconds and 4 git commands to generate.