]> Dogcows Code - chaz/yoink/blobdiff - src/GameLayer.cc
experimental shapes hierarchy and raycasting
[chaz/yoink] / src / GameLayer.cc
index f61ec3d43adf07da1b7fe0d9884fa713ae0d83d1..41000f395d645b8f13b4031e4f7db9e7a88bfcb6 100644 (file)
@@ -121,6 +121,17 @@ GameLayer::GameLayer() :
 void GameLayer::pushed(Mf::Engine& engine)
 {
        engine.push(Hud::alloc(mState));
+
+       mRay.direction.set(1.0, 0.0);
+
+       mLine.a.set(20, 10);
+       mLine.b.set(19, 14);
+
+       mPlane.normal.set(-1.0, 0.0, 0.0);
+       mPlane.d = 0.0;
+
+       mSphere.point.set(22, 5);
+       mSphere.radius = 2;
 }
 
 
@@ -132,11 +143,37 @@ void GameLayer::update(Mf::Engine& engine, Mf::Scalar t, Mf::Scalar dt)
        mState.scene->checkForCollision(*mState.heroine);
 
        mState.camera.setPosition(Mf::Vector3(-mState.heroine->getState().position[0],
-                               -mState.heroine->getState().position[1], -10));
+                               -mState.heroine->getState().position[1], -9));
        //mState.camera.lookAt(Mf::promote(mState.heroine->getState().position));
 
        //Mf::Vector3 heroinePosition = Mf::promote(mState.heroine->getState().position);
        //Mf::Sound::setListenerPosition(heroinePosition);
+       
+       mRay.point = mState.heroine->getState().position;
+
+       Mf::Ray<2>::Intersection meh;
+
+       Mf::Scalar d = mLine.intersectRay(mRay, meh);
+       if (d > 0.0)
+       {
+               Mf::logDebug("line: 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]);
+       }
+       //d = mPlane.intersectRay(mRay, meh);
+       //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]);
+       //}
+       d = mSphere.intersectRay(mRay, meh);
+       if (d > 0.0)
+       {
+               Mf::logDebug("sphere: 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]);
+       }
 }
 
 
@@ -154,6 +191,10 @@ void GameLayer::draw(Mf::Engine& engine, Mf::Scalar alpha) const
 
        mState.heroine->setZCoord(getZCoord(mState.heroine->getState().position));
        mState.heroine->draw(alpha);
+
+       mRay.draw();
+       mLine.draw();
+       mSphere.draw();
 }
 
 bool GameLayer::handleEvent(Mf::Engine& engine, const Mf::Event& event)
@@ -173,6 +214,16 @@ bool GameLayer::handleEvent(Mf::Engine& engine, const Mf::Event& event)
                                mMusic.toggle();
                                return true;
                        }
+                       else if (event.key.keysym.sym == SDLK_PAGEUP)
+                       {
+                               mRay.direction = cml::rotate_vector_2D(mRay.direction, cml::rad(10.0));
+                               return true;
+                       }
+                       else if (event.key.keysym.sym == SDLK_PAGEDOWN)
+                       {
+                               mRay.direction = cml::rotate_vector_2D(mRay.direction, cml::rad(-10.0));
+                               return true;
+                       }
                        return mState.heroine->handleEvent(event);
 
                case SDL_KEYUP:
This page took 0.018726 seconds and 4 git commands to generate.