Index: GTP/trunk/App/Demos/Geom/Demo_LodStrips/main.cpp
===================================================================
--- GTP/trunk/App/Demos/Geom/Demo_LodStrips/main.cpp	(revision 1561)
+++ GTP/trunk/App/Demos/Geom/Demo_LodStrips/main.cpp	(revision 1775)
@@ -26,4 +26,5 @@
 
 //Global variables
+
 Entity* entity;
 Geometry::LodStripsLibrary* myStrips;
@@ -42,6 +43,16 @@
 OverlayElement* mInfo2;
 OverlayElement* mHelp;
-
-char HelpString[]="(F1) Help\n"
+OverlayElement* mLOD;
+OverlayElement* mShad;
+SceneManager* SceneMgrAux;
+
+char LODStringAuto[]="(F3) LOD Mode: AUTOMATIC";
+char LODStringManu[]="(F3) LOD Mode: MANUAL";
+char ShadON[]       ="(F2) Shadows ON";
+char ShadOFF[]      ="(F2) Shadows OFF";
+
+int degAA=0, degABAB=0;
+
+char HelpString[]="(F1) Quit Help\n"
 			"This demo shows an example of the LODStrips model in action. The models in the scene\n"
 			"are associated to a LodStrips object that manage their level of detail.\n"
@@ -50,10 +61,14 @@
 			"closer to them the level of detail increases to restore the original geometry of the\n"
 			"model.\n"
-			"The current level of detail can be seen in real-time in the top-left corner of the screen.\n"
+			"The current level of detail can be seen in real-time in the bottom-left corner of the screen.\n"
 			"The level of detail begins to decrease at a certain distance of the crowd, and stops\n"
 			"decreasing when the objects reach the their minimum LOD. This 'lodding' distance is\n"
-			"customizable from the source code of the demo.";
-
-char NoHelpString[]="(F1) Help\n";
+			"customizable from the source code of the demo.\n\n"
+			"(F3) LOD Mode   ( AUTOMATIC  vs  MANUAL )\n"
+			"           MANUAL MODE:  Use (+) and (-) keys to change de LOD\n";
+
+char NoHelpString[]="\n\n\n\n\n\n\n\n\n\n\n\n\n(F1) Help\n";
+
+int num_ogres = 90;
 
 
@@ -82,4 +97,45 @@
 	}
 	virtual void End(){
+		int v0, v1, v2, v3;
+		unsigned int i;
+
+		v0 = pIdx[0];
+		v1 = pIdx[1];
+		for ( i=2; i < mRenderOp.indexData->indexCount; i++)
+		{
+			if ( v0 == v1 ) degAA++;
+			v0 = v1;
+			v1 = pIdx[i];
+		}
+
+		v0 = pIdx[0];
+		v1 = pIdx[1];
+		v2 = pIdx[2];
+		v3 = pIdx[3];
+        for ( i=4; i < mRenderOp.indexData->indexCount; i++)
+		{
+			if ( ( v0 == v2 ) && ( v1 == v3 ) )
+			{
+				v0 = v2;
+				v1 = v3;
+				v2 = pIdx[i];
+				if ( i < mRenderOp.indexData->indexCount )
+				{
+					i++;
+					v3 = pIdx[i];
+				}
+				else v3 = -1;
+
+				degABAB++;
+			}
+			else
+			{
+			    v0 = v1;
+			    v1 = v2;
+				v2 = v3;
+				v3 = pIdx[i];
+			}
+		}
+
 		ibuf->unlock();
 	}
@@ -89,5 +145,5 @@
 class FresnelFrameListener : public ExampleFrameListener
 {
-	int manage;
+	float miButtonTimer;
 
 public:
@@ -96,5 +152,5 @@
         : ExampleFrameListener(win, cam, false, false)
     {
-		manage=1;
+		miButtonTimer=0;
 	}
 
@@ -102,6 +158,20 @@
     {
 		Vector3 dist; 
-		int distance=0,inc2=0,d;
-		unsigned int nlod,diflods;
+		int distance=0,inc2=0;
+	    static int modo=0;
+		static int shadows=1;
+
+		float tiempo = evt.timeSinceLastFrame;
+		miButtonTimer -= tiempo;
+
+		if (shadows == 0)
+		{
+			SceneMgrAux->setShadowTechnique(SHADOWTYPE_NONE);
+		}
+		else
+		{
+			SceneMgrAux->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
+		}
+
 
 		// Move upto 80 units/second
@@ -131,13 +201,29 @@
 
 		//LOD selection
-		int difdist = dist_max - dist_min;
-	
-		int i=0;
-
+		static float lodfactor=0;
+		static float lodfactorBefore = -1.0f;
+		
 		dist = node->getPosition() - mCamera->getPosition(); 
 		distance =dist.length();
 
-		float lodfactor = (float)(distance - dist_min) / (float)(dist_max - dist_min);
-		lodfactor = 1.0f - lodfactor;
+		if ( modo == 0 )      //Automatic LOD
+		{
+			int difdist = dist_max - dist_min;
+	
+			int i=0;
+
+			lodfactor = (float)(distance - dist_min) / (float)(dist_max - dist_min);
+			lodfactor = 1.0f - lodfactor;
+		}
+		else
+		{
+          //  lodfactor = lodfactorBefore;
+		}
+
+			
+        if (( mInputDevice->isKeyDown(Ogre::KC_ADD) ) && (modo == 1))
+				lodfactor += 0.001f;
+	    if (( mInputDevice->isKeyDown(Ogre::KC_SUBTRACT) ) && (modo == 1))
+				lodfactor -= 0.001f;
 
 		if (lodfactor<0.0f)
@@ -146,11 +232,43 @@
 			lodfactor=1.0f;
 
-		static float lodfactorBefore = -1.0f;
 		if (fabsf(lodfactorBefore-lodfactor)>0.03f || 
 			(lodfactorBefore>0.0f && lodfactor==0.0f) ||
 			(lodfactorBefore<1.0f && lodfactor==1.0f))
 		{
+			degAA=0; degABAB=0;
 			myStrips->GoToLod(lodfactor);
 			lodfactorBefore=lodfactor;
+		}
+
+		if ( mInputDevice->isKeyDown(Ogre::KC_F3) && ( miButtonTimer <= 0 ) )
+		{
+			    miButtonTimer = 0.5;
+				
+				if (modo == 0)
+				{
+					modo=1;
+					mLOD->setCaption(LODStringManu);
+				}
+				else 
+				{
+					modo=0;
+					mLOD->setCaption(LODStringAuto);
+				}
+		}
+
+		if ( mInputDevice->isKeyDown(Ogre::KC_F2) && ( miButtonTimer <= 0 ) )
+		{
+			    miButtonTimer = 0.5;
+				
+				if (shadows == 0)
+				{
+					shadows = 1;
+					mShad->setCaption(ShadON);
+				}
+				else 
+				{
+					shadows = 0;
+					mShad->setCaption(ShadOFF);
+				}
 		}
 
@@ -215,15 +333,18 @@
         }
 
+		SceneMgrAux->setShadowFarDistance(distance + 200);
 
 		char cadena[256];
-
+        const RenderTarget::FrameStats& stats = mWindow->getStatistics();
 				
-		sprintf(cadena,"Distance: %d",distance);
-		
+		sprintf(cadena,"\nDistance: %d\nLOD factor: %f\nTriangle Count: %d\nDegenerated AA: %d\nDegenerated ABAB: %d"
+			             ,    distance,      lodfactor,stats.triangleCount,    degAA*num_ogres,    degABAB*num_ogres);
 		mInfo->setCaption(cadena);
-
-		sprintf(cadena,"LOD factor: %f",lodfactor);
-
+		sprintf(cadena,"Current FPS: %f\n",stats.lastFPS);
 		mInfo2->setCaption(cadena);
+
+		//sprintf(cadena,"LOD factor: %f",lodfactor);
+
+		//mInfo2->setCaption(cadena);
 
 		mCamera->yaw(mRotX);
@@ -248,19 +369,23 @@
     void createScene(void)
     {
-		Entity* pEnt;
+		SceneMgrAux = mSceneMgr;
+        mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.2));
+		mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_MODULATIVE);
+		mSceneMgr->setShadowTextureSettings(2048,1);
+		mSceneMgr->setShadowFarDistance(1024);
+		mSceneMgr->setShadowColour(ColourValue(0.5, 0.5, 0.5));
 
 		mat = new MaterialPtr[1];
 
-        theCam = mCamera;
-        theCam->setPosition(0,50,dist_min-600.0f);
+		theCam = mCamera;
+        theCam->setPosition(-35,50,dist_min-600.0f);
         // Set ambient light
-        mSceneMgr->setAmbientLight(ColourValue(0.3, 0.3, 0.3));
 
         // Create a directional light
         Light* l = mSceneMgr->createLight("MainLight");
         l->setType(Light::LT_DIRECTIONAL);
-        l->setDirection(0.0,0.0,-1.0);
-       
-       
+        l->setDirection(-0.5,-1.0,-1.0);
+		l->setCastShadows(true);
+
         mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
 
@@ -273,11 +398,11 @@
 		MeshManager::getSingleton().createPlane("ground",
 			ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, plane,
-			4000,4000,6,6,true,1,10,10,Vector3::UNIT_Z);
+			20000,10000,6,6,true,1,250,250,Vector3::UNIT_Z);
 
 		Entity* groundEntity = mSceneMgr->createEntity( "GroundEntity", "ground" );
 		mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(groundEntity);
 		
-		groundEntity->setMaterialName("RockTerrain");
-		groundEntity->setCastShadows(false);       
+		groundEntity->setMaterialName("SnowTerrain");
+		groundEntity->setCastShadows(false);
 
 		std::string model_file=model_name;
@@ -294,5 +419,5 @@
         node = mSceneMgr->getRootSceneNode()->createChildSceneNode();
         node->attachObject( entity );
-		node->setVisible(false);
+		node->setVisible(false);		
 
 		std::string lod_file="../../media/GT/";
@@ -310,6 +435,9 @@
 		entity->setMaterialName("LODStripsDemo/Ogro");
 
-		for (int i=-3; i<6; i++) // 7
-			for (int j=0; j<10; j++) // 4
+
+		num_ogres=0;
+
+		for (int i=-4; i<4; i++) // 7
+			for (int j=0; j<8; j++) // 4
 			{
 				char newObjName[16]="";
@@ -322,6 +450,9 @@
 				float randomsepx = (float)((rand()%18)-9);
 				float randomsepy = (float)((rand()%12)-6);
-				auxnode->translate(i*70.0f+randomsepx,0.0f,-j*70.0f-randomsepx);
+				auxnode->translate(i*70.0f+randomsepx,-0.3f,-j*70.0f-randomsepx);
 				auxen->setNormaliseNormals(true);
+				auxen->setCastShadows(true);
+
+				num_ogres++;
 			}
 
@@ -333,6 +464,11 @@
 		mInfo2 = OverlayManager::getSingleton().getOverlayElement("Demo_LodStrips/Info_2");
 		mHelp = OverlayManager::getSingleton().getOverlayElement("Demo_LodStrips/Help");
+		mLOD = OverlayManager::getSingleton().getOverlayElement("Demo_LodStrips/ModoLOD");
+		mShad = OverlayManager::getSingleton().getOverlayElement("Demo_LodStrips/Shadows");
 		mHelp->setCaption(NoHelpString);
-	    pOver->show();
+		mLOD->setCaption(LODStringAuto);
+		mShad->setCaption(ShadON);
+		pOver->show();
+		//mWindow->getStatistics();
 
     }
@@ -341,5 +477,5 @@
     {
         mFrameListener= new FresnelFrameListener(mWindow, mCamera);
-        mFrameListener->showDebugOverlay(true);
+        mFrameListener->showDebugOverlay(false);
         mRoot->addFrameListener(mFrameListener);
     }
