]> Dogcows Code - chaz/yoink/blobdiff - src/YoinkApp.cc
now using stlplus containers, especially ntree
[chaz/yoink] / src / YoinkApp.cc
index 232c097425b4f3a70803951644e3bdf634d1e203..493e6157cad7bdc2347f820cb26a1c1d406bbc39 100644 (file)
@@ -50,6 +50,7 @@ static std::string configFiles()
        std::string files;
 
        char* configFile = getenv("YOINKRC");
+       char* dataDir = getenv("YOINK_DATADIR");
 
        if (configFile)
        {
@@ -59,8 +60,23 @@ static std::string configFiles()
                files += ":";
        }
 
+       // add the colon-delimited paths from configure
        files += YOINK_CONFIGFILES;
 
+       if (dataDir)
+       {
+               // if another data directory is set in the environment, look for a
+               // config file there
+               files += ":";
+               files += dataDir;
+               files += "/yoinkrc";
+       }
+
+       // look in the configured data directory last of all
+       files += ":";
+       files += (dataDir ? dataDir : YOINK_DATADIR);
+       files += "/yoinkrc";
+
        return files;
 }
 
@@ -71,8 +87,11 @@ static std::string iconFile()
        // first set up the search paths so we can find the icon and other resources
        if (dataDir)
        {
+               // look first in the data directory specified by the environment
                Mf::Resource::addSearchPath(dataDir);
        }
+
+       // then look in the configured data directory
        Mf::Resource::addSearchPath(YOINK_DATADIR);
 
        return Mf::Resource::getPathToResource("yoink.png");
@@ -112,6 +131,7 @@ YoinkApp::~YoinkApp()
 {
        delete someChar;
        delete font;
+       delete testScene;
 
        Mf::Dispatcher::instance().removeHandler(this);
 }
@@ -125,7 +145,7 @@ void YoinkApp::setupGL()
        glEnable(GL_DEPTH_TEST);
 
        glShadeModel(GL_SMOOTH);
-       glEnable(GL_POLYGON_SMOOTH);
+       //glEnable(GL_POLYGON_SMOOTH);
 
        //int texSize;
        //glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize);
@@ -138,6 +158,14 @@ void YoinkApp::setupGL()
 
        glClearColor(1.0, 0.0, 0.0, 1.0);
 
+       //glMatrixMode(GL_PROJECTION);
+       //glLoadIdentity();
+       //gluPerspective(60.0, 1.33333, 1.0, 2500.0);
+       camera.setProjection(cml::rad(60.0), 1.33333, 32.0, 2500.0);
+       camera.uploadProjectionToGL();
+
+       //glMatrixMode(GL_MODELVIEW);
+       
        //glLineWidth(10.0f);
 }
 
@@ -155,6 +183,8 @@ void YoinkApp::update(Mf::Scalar t, Mf::Scalar dt)
        
        fadeIn.update(dt);
 
+       camera.update(t, dt);
+
        someChar->getAnimation().update(t, dt);
        interp.update(dt);
 
@@ -177,19 +207,16 @@ void YoinkApp::draw(Mf::Scalar alpha)
        
 
 
-       glMatrixMode(GL_PROJECTION);
-       glLoadIdentity();
-       gluPerspective(60.0, 1.33333, 1.0, 2000.0);
-       
        glMatrixMode(GL_MODELVIEW);
-       glLoadIdentity();
+       //glLoadIdentity();
 
        glBindTexture(GL_TEXTURE_2D, 0);
        //glRotatef(drawstate*15.0f, 0.0, 1.0, 0.0);
-       glTranslatef(x, y, z);
+       //glTranslatef(x, y, z);
+       glLoadMatrix(camera.getModelviewMatrix().data());
 
        // DRAW THE SCENE
-       testScene->draw(alpha);
+       testScene->draw(alpha, camera);
 
 
        /*
@@ -327,30 +354,43 @@ void YoinkApp::handleEvent(const Mf::Event& event)
                        {
                                someChar->getAnimation().startSequence("Punch");
                        }
-                       else if (event.key.keysym.sym == SDLK_RIGHT)
-                       {
-                               x -= 50.0;
-                       }
-                       else if (event.key.keysym.sym == SDLK_LEFT)
-                       {
-                               x += 50.0;
-                       }
-                       else if (event.key.keysym.sym == SDLK_UP)
+                       else if (event.key.keysym.sym == SDLK_r)
                        {
-                               y -= 50.0;
+                               testScene->refresh();
                        }
-                       else if (event.key.keysym.sym == SDLK_DOWN)
+                       else if (event.key.keysym.sym == SDLK_l)
                        {
-                               y += 50.0;
-                       }
-                       else if (event.key.keysym.sym == SDLK_PAGEUP)
-                       {
-                               z += 50.0;
-                       }
-                       else if (event.key.keysym.sym == SDLK_PAGEDOWN)
-                       {
-                               z -= 50.0;
+                               getVideo().toggleCursorGrab();
+                               getVideo().toggleCursorVisible();
                        }
+                       //else if (event.key.keysym.sym == SDLK_RIGHT)
+                       //{
+                               //x -= 50.0;
+                       //}
+                       //else if (event.key.keysym.sym == SDLK_LEFT)
+                       //{
+                               //x += 50.0;
+                       //}
+                       //else if (event.key.keysym.sym == SDLK_UP)
+                       //{
+                               //y -= 50.0;
+                       //}
+                       //else if (event.key.keysym.sym == SDLK_DOWN)
+                       //{
+                               //y += 50.0;
+                       //}
+                       //else if (event.key.keysym.sym == SDLK_PAGEUP)
+                       //{
+                               //z += 50.0;
+                       //}
+                       //else if (event.key.keysym.sym == SDLK_PAGEDOWN)
+                       //{
+                               //z -= 50.0;
+                       //}
+
+               case SDL_MOUSEMOTION:
+               case SDL_MOUSEBUTTONDOWN:
+                       camera.adjustFromInput(event);
                        break;
 
                case SDL_QUIT:
@@ -359,6 +399,8 @@ void YoinkApp::handleEvent(const Mf::Event& event)
 
                case SDL_VIDEORESIZE:
                        glViewport(0, 0, event.resize.w, event.resize.h);
+                       camera.setProjection(cml::rad(60.0), double(event.resize.w / event.resize.h), 32.0, 2500.0);
+                       camera.uploadProjectionToGL();
                        break;
        }
 }
@@ -389,5 +431,6 @@ int main(int argc, char* argv[])
        return status;
 }
 
+
 /** vim: set ts=4 sw=4 tw=80: *************************************************/
 
This page took 0.020578 seconds and 4 git commands to generate.