]> Dogcows Code - chaz/yoink/blobdiff - src/GameLayer.cc
ray-scene intersection
[chaz/yoink] / src / GameLayer.cc
index 41000f395d645b8f13b4031e4f7db9e7a88bfcb6..1e607586d486169afa681b8cea57015b5353e2e9 100644 (file)
@@ -31,6 +31,7 @@
 #include <Moof/Log.hh>
 #include <Moof/Math.hh>
 #include <Moof/OpenGL.hh>
+#include <Moof/Settings.hh>
 #include <Moof/Video.hh>
 
 #include "GameLayer.hh"
@@ -92,7 +93,16 @@ void GameLayer::advanceScene()
        {
                mState.scene = Scene::alloc(mState.sceneList[0]);
                mState.sceneList.erase(mState.sceneList.begin());
-               mState.scene->load(mState.script);
+
+               Mf::Script::Status status = mState.scene->load(mState.script);
+               if (status != Mf::Script::SUCCESS)
+               {
+                       std::string str;
+                       mState.script[-1].get(str);
+
+                       Mf::logScript("%s", str.c_str());
+                       throw Mf::Exception(Mf::ErrorCode::SCRIPT_ERROR, str);
+               }
        }
 }
 
@@ -103,7 +113,10 @@ GameLayer::GameLayer() :
 {
        mMusic.setLooping(true);
        mMusic.enqueue("NightFusionLoop");
-       mMusic.stream();
+
+       bool isMute = false;
+       Mf::Settings::getInstance().get("nomusic", isMute);
+       if (!isMute) mMusic.play();
 
        loadSceneLoader();
        advanceScene();                         // load the first scene
@@ -123,6 +136,7 @@ void GameLayer::pushed(Mf::Engine& engine)
        engine.push(Hud::alloc(mState));
 
        mRay.direction.set(1.0, 0.0);
+       mRay3.direction.set(1.0, 0.0, 0.0);
 
        mLine.a.set(20, 10);
        mLine.b.set(19, 14);
@@ -150,8 +164,11 @@ void GameLayer::update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt)
        //Mf::Sound::setListenerPosition(heroinePosition);
        
        mRay.point = mState.heroine->getState().position;
+       mRay3.point = Mf::promote(mRay.point);
+       mRay3.direction = Mf::promote(mRay.direction);
 
        Mf::Ray<2>::Intersection meh;
+       Mf::Ray<3>::Intersection meh3;
 
        Mf::Scalar d = mLine.intersectRay(mRay, meh);
        if (d > 0.0)
@@ -160,12 +177,12 @@ void GameLayer::update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt)
                Mf::logDebug("      P = <%f,%f>", meh.point[0], meh.point[1]);
                Mf::logDebug("      n = <%f,%f>", meh.normal[0], meh.normal[1]);
        }
-       //d = mPlane.intersectRay(mRay, meh);
+       //d = mPlane.intersectRay(mRay3, meh3);
        //if (d > 0.0)
        //{
                //Mf::logDebug("plane: d = %f", d);
-               //Mf::logDebug("       P = <%f,%f>", meh.point[0], meh.point[1]);
-               //Mf::logDebug("       n = <%f,%f>", meh.normal[0], meh.normal[1]);
+               //Mf::logDebug("       P = <%f,%f>", meh3.point[0], meh3.point[1]);
+               //Mf::logDebug("       n = <%f,%f>", meh3.normal[0], meh3.normal[1]);
        //}
        d = mSphere.intersectRay(mRay, meh);
        if (d > 0.0)
@@ -174,6 +191,14 @@ void GameLayer::update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt)
                Mf::logDebug("        P = <%f,%f>", meh.point[0], meh.point[1]);
                Mf::logDebug("        n = <%f,%f>", meh.normal[0], meh.normal[1]);
        }
+
+       std::list<Mf::Ray<2>::Intersection> hits;
+       if (mState.scene->castRay(mRay, hits))
+       {
+               Mf::logDebug("scene: d = %f", d);
+               Mf::logDebug("       P = <%f,%f>", hits.front().point[0], hits.front().point[1]);
+               Mf::logDebug("       n = <%f,%f>", hits.front().normal[0], hits.front().normal[1]);
+       }
 }
 
 
This page took 0.022911 seconds and 4 git commands to generate.