]> Dogcows Code - chaz/yoink/blobdiff - src/YoinkApp.cc
initial working frustum culling implementation
[chaz/yoink] / src / YoinkApp.cc
index 232c097425b4f3a70803951644e3bdf634d1e203..43767d25c94468bd7d2d3b140dff4c26e0749caf 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)
+                       else if (event.key.keysym.sym == SDLK_r)
                        {
-                               x += 50.0;
+                               testScene->refresh();
                        }
-                       else if (event.key.keysym.sym == SDLK_UP)
+                       else if (event.key.keysym.sym == SDLK_l)
                        {
-                               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;
+                               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,11 +399,15 @@ 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;
        }
 }
 
 
+#include <Moof/Tree.hh>
+
 
 int main(int argc, char* argv[])
 {
@@ -374,6 +418,39 @@ int main(int argc, char* argv[])
 
        int status = 0;
 
+       //Mf::Tree<int>::Ptr rootNode;
+       //Mf::Tree<int>::Ptr temp, temp2, temp3;
+
+       //rootNode = Mf::Tree<int>::Ptr(Mf::Tree<int>::createNewNode(1));
+
+       //temp = Mf::Tree<int>::Ptr(Mf::Tree<int>::createNewNode(2));
+       //temp3 = temp;
+       //rootNode->addChild(temp);
+
+       //temp = Mf::Tree<int>::Ptr(Mf::Tree<int>::createNewNode(3));
+       //temp2 = temp;
+       //rootNode->addChild(temp);
+
+       //temp = Mf::Tree<int>::Ptr(Mf::Tree<int>::createNewNode(4));
+       //rootNode->addChild(temp);
+
+       //temp = Mf::Tree<int>::Ptr(Mf::Tree<int>::createNewNode(5));
+       //temp2->addChild(temp);
+
+       //temp = Mf::Tree<int>::Ptr(Mf::Tree<int>::createNewNode(6));
+       //temp2->addChild(temp);
+
+       //temp = Mf::Tree<int>::Ptr(Mf::Tree<int>::createNewNode(7));
+       //temp3->addChild(temp);
+
+       //temp = rootNode;
+       //while (temp)
+       //{
+               //temp->print();
+               //temp = temp->getNext();
+       //}
+       //return 0;
+
        try
        {
                YoinkApp app(argc, argv);
This page took 0.020905 seconds and 4 git commands to generate.