X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FScene.cc;h=b8cb23388c24b3ea8c41665bda818566eb504ce6;hp=f4dd1c0e3f9597bdd7505ed236bd3d91591fc40c;hb=29e3d45f7bbbf31eadf793c41ff2b3d9c47b7539;hpb=c2321281bf12a7efaedde930422c7ddbc92080d4 diff --git a/src/Moof/Scene.cc b/src/Moof/Scene.cc index f4dd1c0..b8cb233 100644 --- a/src/Moof/Scene.cc +++ b/src/Moof/Scene.cc @@ -32,11 +32,11 @@ #include "Aabb.hh" #include "Camera.hh" -#include "Cullable.hh" #include "Deserializer.hh" -#include "Drawable.hh" +#include "Entity.hh" #include "Math.hh" #include "Mippleton.hh" +#include "Octree.hh" #include "OpenGL.hh" #include "Scene.hh" #include "Serializable.hh" @@ -48,7 +48,7 @@ namespace Mf { class Scene::SceneImpl : public Mippleton { - class Scenery : public Drawable, public Cullable + class Scenery : public Entity { public: Scenery(const Matrix4& transform, const std::string& textureName) : @@ -118,12 +118,12 @@ class Scene::SceneImpl : public Mippleton } } - void draw(Scalar alpha) + void draw(Scalar alpha) const { glPushMatrix(); //std::cout << "transforming..." << std::endl; //std::cout << transformation << std::endl; - glMultMatrixf(transformation.data()); + glMultMatrix(transformation.data()); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); image.bind(); @@ -143,13 +143,13 @@ class Scene::SceneImpl : public Mippleton { glBegin(GL_TRIANGLE_FAN); glTexCoord2f(texCoords[0], texCoords[1]); - glVertex3f(xf, yf, 0.0f); + glVertex2f(xf, yf); glTexCoord2f(texCoords[2], texCoords[3]); - glVertex3f(xf+1.0, yf, 0.0f); + glVertex2f(xf+1.0, yf); glTexCoord2f(texCoords[4], texCoords[5]); - glVertex3f(xf+1.0, yf+1.0, 0.0f); + glVertex2f(xf+1.0, yf+1.0); glTexCoord2f(texCoords[6], texCoords[7]); - glVertex3f(xf, yf+1.0, 0.0f); + glVertex2f(xf, yf+1.0); glEnd(); } } @@ -174,7 +174,8 @@ class Scene::SceneImpl : public Mippleton Billboard(const Matrix4& transform, const std::string& textureName, SerializablePtr root) : Scenery(transform, textureName), - index(0) + index(0), + uScale(1) { std::map rootObj; @@ -190,29 +191,58 @@ class Scene::SceneImpl : public Mippleton index = Tilemap::Index(value); } } + if ((it = rootObj.find("u_scale")) != rootObj.end()) + { + (*it).second->get(uScale); + } + if ((it = rootObj.find("fog")) != rootObj.end()) + { + (*it).second->get(fog); + } + if ((it = rootObj.find("blend")) != rootObj.end()) + { + (*it).second->get(blending); + } } image.getTileCoords(index, texCoords); } - void draw(Scalar alpha) + void draw(Scalar alpha) const { glPushMatrix(); - glMultMatrixf(transformation.data()); + glMultMatrix(transformation.data()); + + if (blending) + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + /*if (fog) glEnable(GL_FOG);*/ glColor4f(1.0f, 1.0f, 1.0f, 1.0f); image.bind(); + float increment = 1.0f / float(uScale); + int x; + float xf; + + for (x = 0, xf = 0.0f; x < uScale; x++, xf += increment) + { glBegin(GL_TRIANGLE_FAN); glTexCoord2f(texCoords[0], texCoords[1]); - glVertex2f(0.0f, 0.0f); + glVertex2f(xf, 0.0f); glTexCoord2f(texCoords[2], texCoords[3]); - glVertex2f(1.0f, 0.0f); + glVertex2f(xf+increment, 0.0f); glTexCoord2f(texCoords[4], texCoords[5]); - glVertex2f(1.0f, 1.0f); + glVertex2f(xf+increment, 1.0f); glTexCoord2f(texCoords[6], texCoords[7]); - glVertex2f(0.0f, 1.0f); + glVertex2f(xf, 1.0f); glEnd(); + } + + glDisable(GL_BLEND); + glDisable(GL_FOG); glPopMatrix(); } @@ -225,6 +255,7 @@ class Scene::SceneImpl : public Mippleton private: Tilemap::Index index; Scalar texCoords[8]; + long uScale; }; @@ -240,7 +271,27 @@ class Scene::SceneImpl : public Mippleton if (numbers[0]->getNumber(num)) { - + theBox.min[0] = Scalar(num); + } + if (numbers[1]->getNumber(num)) + { + theBox.min[1] = Scalar(num); + } + if (numbers[2]->getNumber(num)) + { + theBox.min[2] = Scalar(num); + } + if (numbers[3]->getNumber(num)) + { + theBox.max[0] = Scalar(num); + } + if (numbers[4]->getNumber(num)) + { + theBox.max[1] = Scalar(num); + } + if (numbers[5]->getNumber(num)) + { + theBox.max[2] = Scalar(num); } } } @@ -255,6 +306,10 @@ public: loadFromFile(); } + ~SceneImpl() + { + } + void loadInstructions(SerializablePtr root) { @@ -276,7 +331,6 @@ public: if (instruction == "reset_transform") { transform.identity(); - //std::cout << "===================RESET=====================" << std::endl; } else if (instruction == "translate") { @@ -300,8 +354,6 @@ public: Matrix4 translation; cml::matrix_translation(translation, vec); transform = translation * transform; - //std::cout << "TRANSLATE\t" << vec << std::endl - //<< transform << std::endl; } } else if (instruction == "scale") @@ -320,8 +372,6 @@ public: Matrix4 scaling; cml::matrix_uniform_scale(scaling, Scalar(value)); transform = scaling * transform; - //std::cout << "SCALE\t\t" << value << std::endl - //<< transform << std::endl; } else if (values.size() == 3) { @@ -340,8 +390,6 @@ public: Matrix4 scaling; cml::matrix_scale(scaling, vec); transform = scaling * transform; - //std::cout << "SCALE\t\t" << vec << std::endl - //<< transform << std::endl; } } } @@ -357,28 +405,30 @@ public: std::string axis; size_t axisIndex = 0; double value = 0.0; + Vector3 vec(0.0, 0.0, 0.0); if (values[0]->get(axis)) { if (axis == "x") { axisIndex = 0; + vec[0] = 1.0; } else if (axis == "y") { axisIndex = 1; + vec[1] = 1.0; } else if (axis == "z") { axisIndex = 2; + vec[2] = 1.0; } values[1]->getNumber(value); } - cml::matrix_rotate_about_local_axis(transform, + cml::matrix_rotate_about_world_axis(transform, axisIndex, Scalar(value * cml::constantsd::rad_per_deg())); - //std::cout << "ROTATE\t" << axis << " " << value << std::endl - //<< transform << std::endl; } } } @@ -389,9 +439,6 @@ public: } else if (instruction == "tilemap") { - //std::cout << "TILEMAP\t" << texture<< std::endl; - //std::cout << transform << std::endl; - it++; TilePanel* tilePanel = new TilePanel(transform, texture, *it); @@ -400,9 +447,6 @@ public: } else if (instruction == "billboard") { - //std::cout << "BILLBOARD\t" << texture << std::endl; - //std::cout << transform << std::endl; - it++; Billboard* billboard = new Billboard(transform, texture, *it); @@ -445,6 +489,9 @@ public: } } } + + std::cout << "playfield: " << playfieldBounds.min << " ... " << + playfieldBounds.max << std::endl; } @@ -457,6 +504,14 @@ public: //std::cout << "draw object"; (*it)->draw(alpha); } + + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + + glBindTexture(GL_TEXTURE_2D, 0); + glColor4f(0.0f, 1.0f, 0.0f, 1.0f); + playfieldBounds.draw(0.0); + + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } @@ -473,12 +528,18 @@ Scene::Scene(const std::string& name) : impl_(Scene::SceneImpl::retain(name), &Scene::SceneImpl::release) {} -void Scene::draw(Scalar alpha) +void Scene::draw(Scalar alpha) const { // pass through impl_->draw(alpha); } +void Scene::refresh() +{ + impl_->objects.clear(); + impl_->loadFromFile(); +} + /** * Specialized search location for scene files. They can be found in the