Commits

Frederic De Groef committed f0ecac1

fixed the keypressed()/keyreleased() mixup

Comments (0)

Files changed (3)

ogre-npr/EdgeGeometryBuilder.cpp

 //-----------------------------------------------------------------------------
 void EdgeGeometryBuilder::addEdgesForEntity(Ogre::Entity *_ent)
 {
-    assert(mIsBuilding);
+    if(mIsBuilding)
+    {
 
-    mLog->logMessage("Creating edges for entity : " + _ent->getName());
-    Ogre::MeshPtr mesh = _ent->getMesh();
+        mLog->logMessage("Creating edges for entity : " + _ent->getName());
+        Ogre::MeshPtr mesh = _ent->getMesh();
 
-    {
-        boost::format fmt("Mesh has %d submeshes");
-        fmt % mesh->getNumSubMeshes();
-        mLog->logMessage(fmt.str());
-    }
-
-    mesh->buildEdgeList();
-
-    Ogre::EdgeData *edgeData = mesh->getEdgeList();
-
-    {
-        boost::format fmt("Generating %d edgegroups");
-        fmt % edgeData->edgeGroups.size();
-        mLog->logMessage(fmt.str());
-    }
-    
-    for(int edgeGroupIdx = 0 ; edgeGroupIdx < edgeData->edgeGroups.size() ; edgeGroupIdx++)
-    {
         {
-            boost::format fmt("Adding edges for edgegroup[%d]");
-            fmt % edgeGroupIdx ;
+            boost::format fmt("Mesh has %d submeshes");
+            fmt % mesh->getNumSubMeshes();
             mLog->logMessage(fmt.str());
         }
 
-        Ogre::EdgeData::EdgeGroup &currentEdgeGroup = edgeData->edgeGroups[edgeGroupIdx];
-        _addEdgesForEdgeGroup(currentEdgeGroup, *edgeData);
+        mesh->buildEdgeList();
+
+        Ogre::EdgeData *edgeData = mesh->getEdgeList();
 
         {
-            boost::format fmt("%s : Added %d edges (%d tris, %d vertices)");
-            fmt % mEdges->getName() % (mIndex/6) % (mIndex/3) % (mIndex);
+            boost::format fmt("Generating %d edgegroups");
+            fmt % edgeData->edgeGroups.size();
             mLog->logMessage(fmt.str());
         }
+    
+        for(int edgeGroupIdx = 0 ; edgeGroupIdx < edgeData->edgeGroups.size() ; edgeGroupIdx++)
+        {
+            {
+                boost::format fmt("Adding edges for edgegroup[%d]");
+                fmt % edgeGroupIdx ;
+                mLog->logMessage(fmt.str());
+            }
 
+            Ogre::EdgeData::EdgeGroup &currentEdgeGroup = edgeData->edgeGroups[edgeGroupIdx];
+            _addEdgesForEdgeGroup(currentEdgeGroup, *edgeData);
+
+            {
+                boost::format fmt("%s : Added %d edges (%d tris, %d vertices)");
+                fmt % mEdges->getName() % (mIndex/6) % (mIndex/3) % (mIndex);
+                mLog->logMessage(fmt.str());
+            }
+
+        }
+    }
+    else
+    {
+        throw new Ogre::RuntimeAssertionException(Ogre::Exception::ERR_RT_ASSERTION_FAILED
+            , "EdgeGeometryBuilder::addEdgesForEntity() was called before EdgeGeometryBuilder::begin() was"
+            , "EdgeGeometryBuilder::addEdgesForEntity()"
+            , __FILE__
+            , __LINE__);
     }
 }
 //-----------------------------------------------------------------------------

ogre-npr/NPRDemoApp.cpp

 #include <boost/foreach.hpp>
 #include <boost/format.hpp>
 
-//#define ANIMATE_LIGHT
-
 //-----------------------------------------------------------------------------
 NPRDemoApp::NPRDemoApp()
     :OgreApplication("NPR Sandbox")
 bool NPRDemoApp::frameStarted(const FrameEvent& evt)
 {
     _updateDebugOverlay();
-
-#ifdef ANIMATE_LIGHT
-        mAnimState->addTime(evt.timeSinceLastFrame);
-#endif
-
     return OgreApplication::frameStarted(evt);
 }
 //-----------------------------------------------------------------------------
-bool NPRDemoApp::keyReleased( const OIS::KeyEvent &e )
+bool NPRDemoApp::keyPressed (const OIS::KeyEvent &e )
 {
-    if(mKeyboard->isKeyDown(OIS::KC_H))
+    if(mKeyboard->isKeyDown(OIS::KC_E))
     {
         mStaticEdges->setVisible(!mStaticEdges->isVisible());
     }
-    return OgreApplication::keyReleased(e);
+    return OgreApplication::keyPressed(e);
 }
 //-----------------------------------------------------------------------------
 void NPRDemoApp::_createDebugOverlay()
 
 
 
-    _loadMesh("ulb_building_BATIMENTS_EST", Vector3(-1200, 0, 0));
+    _loadMesh("ulb_building_BATIMENTS_EST", Vector3(-1300, 0, 0));
 
-    _loadMesh("ulb_building_bat_C", Vector3(-1200, 0, 0));
-    _loadMesh("ulb_building_ASCENCEUR", Vector3(-1200, 0, 0));
+    _loadMesh("ulb_building_bat_C", Vector3(-1300, 0, 0));
+    _loadMesh("ulb_building_ASCENCEUR", Vector3(-1300, 0, 0));
 
  
-    _loadMesh("ulb_building_BAT_NEXT", Vector3(-1200, 0, 0));
-    _loadMesh("ulb_building_BAT_PRINCIPAL", Vector3(-1200, 0, 0));
-    _loadMesh("ulb_building_bat_projet_broullion", Vector3(-1200, 0, 0));
-    _loadMesh("ulb_building_bat_S_W", Vector3(-1200, 0, 0));
-    _loadMesh("ulb_building_batiment_plus", Vector3(-1200, 0, 0));
+    _loadMesh("ulb_building_BAT_NEXT", Vector3(-1300, 0, 0));
+    _loadMesh("ulb_building_BAT_PRINCIPAL", Vector3(-1300, 0, 0));
+    //_loadMesh("ulb_building_bat_projet_broullion", Vector3(-1300, 0, 0));
+    _loadMesh("ulb_building_bat_S_W", Vector3(-1300, 0, 0));
+    _loadMesh("ulb_building_batiment_plus", Vector3(-1300, 0, 0));
 
 
-    _loadMesh("ulb_building_BATIMENTS_PROJET", Vector3(-1200, 0, 0));
-    _loadMesh("ulb_building_BATIMENTS_TOUT", Vector3(-1200, 0, 0));
-    _loadMesh("ulb_building_Calque1", Vector3(-1200, 0, 0));
-    _loadMesh("ulb_building_Calque2", Vector3(-1200, 0, 0));
-    _loadMesh("ulb_building_COURBES", Vector3(-1200, 0, 0));
+    _loadMesh("ulb_building_BATIMENTS_PROJET", Vector3(-1300, 0, 0));
+    _loadMesh("ulb_building_BATIMENTS_TOUT", Vector3(-1300, 0, 0));
+    _loadMesh("ulb_building_Calque1", Vector3(-1300, 0, 0));
+    _loadMesh("ulb_building_Calque2", Vector3(-1300, 0, 0));
+    _loadMesh("ulb_building_COURBES", Vector3(-1300, 0, 0));
 
-    _loadMesh("ulb_building_galleries", Vector3(-1200, 0, 0));
-    _loadMesh("ulb_building_Layer0", Vector3(-1200, 0, 0));
+    _loadMesh("ulb_building_galleries", Vector3(-1300, 0, 0));
+    _loadMesh("ulb_building_Layer0", Vector3(-1300, 0, 0));
 
-    _loadMesh("ulb_building_Le_Batiment", Vector3(-1200, 0, 0));
-    _loadMesh("ulb_building_route_relief", Vector3(-1200, 0, 0));
+    _loadMesh("ulb_building_Le_Batiment", Vector3(-1300, 0, 0));
+    _loadMesh("ulb_building_route_relief", Vector3(-1300, 0, 0));
 
-    _loadMesh("ulb_building_tour", Vector3(-1200, 0, 0));
-    _loadMesh("ulb_building_Z_LAYOUT", Vector3(-1200, 0, 0));
+    _loadMesh("ulb_building_tour", Vector3(-1300, 0, 0));
+    _loadMesh("ulb_building_Z_LAYOUT", Vector3(-1300, 0, 0));
 
     _buildStaticEdges();
 
+
+
 }
 //-----------------------------------------------------------------------------
 void NPRDemoApp::_loadScene(const String &_name, SceneNode* _node)
     }
     mStaticEdges->end();
 
-    mStaticEdges->setVisible(false);
-    Ogre::SceneNode *edgesNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("edges node", Ogre::Vector3(-1200, 0, 0));
+    mStaticEdges->setVisible(true);
+    Ogre::SceneNode *edgesNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("edges node", Ogre::Vector3(-1300, 0, 0));
     mStaticEdges->attachToSceneNode(edgesNode);
 }
 //-----------------------------------------------------------------------------
     mLightNode->attachObject(mLight);
     mLightNode->attachObject(mBBset);
 
+    mLightNode->setPosition(Ogre::Vector3(0, 500, 500));
 
-#ifdef ANIMATE_LIGHT
-    Real totalTime = 10;                
-    
-    Animation *anim = mSceneMgr->createAnimation("Light Track", totalTime);
-    anim->setInterpolationMode(Animation::IM_SPLINE);
-
-    NodeAnimationTrack *track = anim->createNodeTrack(0, mLightNode);
-    TransformKeyFrame *key;      
-
-    Real precision = 36, amplitude = 300;
-    int keyframeIndex = 0;
-    for(float phi=0.0; phi <= 2*Math::PI; phi+= Math::PI / precision)
-    {
-        key = track->createNodeKeyFrame(phi * (totalTime/ (2*Math::PI)));
-        key->setTranslate(Vector3(amplitude*Math::Cos(phi)
-                                 ,amplitude
-                                 ,amplitude*Math::Sin(phi)));
-    }
-
-    mAnimState = mSceneMgr->createAnimationState("Light Track");
-    mAnimState->setEnabled(true);
-#else
-    mLightNode->setPosition(0, 500, 500);
-#endif
 }
 //-----------------------------------------------------------------------------
 

ogre-npr/NPRDemoApp.h

     Ogre::ManualObject*   _createQuadFinGeometry(Entity*);
 
     bool frameStarted(const FrameEvent& evt);
-    bool keyReleased( const OIS::KeyEvent &e );
+    bool keyPressed( const OIS::KeyEvent &e );
 protected:
     // Scene generation
-    void            _populate();
-    void            _createLight();
-    SceneNode*      _loadMesh(const String&, const Vector3&);
-    void            _setCelShadingMaterial(Entity*);
-
-
+    void _populate();
+    void _createLight();
+    SceneNode* _loadMesh(const String&, const Vector3&);
+    void _setCelShadingMaterial(Entity*);
     void _loadScene(const String&, SceneNode*);
     void _buildStaticEdges();
 
-
-
     // overlay
     void _createDebugOverlay();
     void _updateDebugOverlay();
     // OgreMaxSceneCallback
     void CreatedEntity(const OgreMax::OgreMaxScene*, Ogre::Entity*){};
 
-    //void _setEdgesVisible(EdgeGeometryItem&, bool);
 
 protected:
     BillboardSet *mBBset;