Ejemplo n.º 1
0
void Objects::removeCell(MWWorld::Ptr::CellStore* store)
{
    if(mCellSceneNodes.find(store) != mCellSceneNodes.end())
    {
        Ogre::SceneNode* base = mCellSceneNodes[store];

        for (int i=0; i<base->numChildren(); ++i)
            clearSceneNode (static_cast<Ogre::SceneNode *> (base->getChild (i)));

        base->removeAndDestroyAllChildren();
        mCellSceneNodes.erase(store);
        mRenderer.getScene()->destroySceneNode(base);
        base = 0;
    }

    if(mStaticGeometry.find(store) != mStaticGeometry.end())
    {
        Ogre::StaticGeometry* sg = mStaticGeometry[store];
        mStaticGeometry.erase(store);
        mRenderer.getScene()->destroyStaticGeometry (sg);
        sg = 0;
    }
    if(mStaticGeometrySmall.find(store) != mStaticGeometrySmall.end())
    {
        Ogre::StaticGeometry* sg = mStaticGeometrySmall[store];
        mStaticGeometrySmall.erase(store);
        mRenderer.getScene()->destroyStaticGeometry (sg);
        sg = 0;
    }

    if(mBounds.find(store) != mBounds.end())
        mBounds.erase(store);
}
 void FootstepDisplay::allocateTexts(size_t num) {
   if (num > texts_.size()) {
     // need to allocate
     for (size_t i = texts_.size(); i < num; i++) {
       // create nodes
       Ogre::SceneNode* node = scene_node_->createChildSceneNode();
       rviz::MovableText* text 
         = new rviz::MovableText("not initialized", "Arial", 0.05);
       text->setVisible(false);
       text->setTextAlignment(rviz::MovableText::H_CENTER,
                              rviz::MovableText::V_ABOVE);
       node->attachObject(text);
       texts_.push_back(text);
       text_nodes_.push_back(node);
     }
   }
   else if (num < texts_.size()) {
     for (int i = texts_.size() - 1; i >= (int)num; i--) {
       Ogre::SceneNode* node = text_nodes_[i];
       node->detachAllObjects();
       node->removeAndDestroyAllChildren();
       scene_manager_->destroySceneNode(node);
     }
     text_nodes_.resize(num);
     texts_.resize(num);
     
   }
 }
Ejemplo n.º 3
0
SnapToMovement::~SnapToMovement()
{
	for (std::vector<Ogre::SceneNode*>::iterator I = mDebugNodes.begin(); I != mDebugNodes.end(); ++I) {
		Ogre::SceneNode* node = *I;
		node->removeAndDestroyAllChildren();
		mSceneManager.destroySceneNode(node);
	}

}
Ejemplo n.º 4
0
void InteriorCellRender::deleteObject (const std::string& handle)
{
    if (!handle.empty())
    {
        Ogre::SceneNode *node = scene.getMgr()->getSceneNode (handle);
        node->removeAndDestroyAllChildren();
        scene.getMgr()->destroySceneNode (node);
    }
}
Ejemplo n.º 5
0
void GraphicsImpl::removeNode(int ID)
{
	Ogre::SceneNode* node = nodes[ID];

	if (node->getParent() != NULL) {
		node->getParent()->removeChild(node);
	}

	node->removeAndDestroyAllChildren();

	delete node;
	nodes.erase(ID);
}
Ejemplo n.º 6
0
void ChunkManager::deleteChunk(int chunk_x, int chunk_y, int chunk_z) {
    if (!hasChunkAtChunkCoords(chunk_x, chunk_y, chunk_z)) {
        // Don't do anything if we don't have a chunk there.
        return;
    }
    //TODO: serialize the chunk before deletion
    Chunk* chunk = mChunks[chunk_x][chunk_y][chunk_z];
    mGame->getDynamicsWorld()->removeRigidBody(chunk->mRigidBody);
    Ogre::SceneNode* sceneNode = chunk->mSceneNode;
    sceneNode->removeAndDestroyAllChildren();
    mGame->destroySceneNode(sceneNode);
    delete chunk;
}
 FootstepDisplay::~FootstepDisplay()
 {
   delete alpha_property_;
   delete width_property_;
   delete height_property_;
   delete depth_property_;
   delete show_name_property_;
   delete use_group_coloring_property_;
   delete line_;
   // remove all the nodes
   for (size_t i = 0; i < text_nodes_.size(); i++) {
     Ogre::SceneNode* node = text_nodes_[i];
     node->removeAndDestroyAllChildren();
     node->detachAllObjects();
     scene_manager_->destroySceneNode(node);
   }
 }
Ejemplo n.º 8
0
void Actors::removeCell(MWWorld::Ptr::CellStore* store){
    if(mCellSceneNodes.find(store) != mCellSceneNodes.end())
    {
        Ogre::SceneNode* base = mCellSceneNodes[store];
        base->removeAndDestroyAllChildren();
        mCellSceneNodes.erase(store);
        mRend.getScene()->destroySceneNode(base);
        base = 0;
    }
    for(std::map<MWWorld::Ptr, Animation*>::iterator iter = mAllActors.begin(); iter != mAllActors.end(); )
    {
        if(iter->first.getCell() == store){
            delete iter->second;
            mAllActors.erase(iter++);
        }
        else
            ++iter;
    }
}
TowerTemporal::~TowerTemporal(void)
{
  printf("~TowerTemporal\n");
  if (mpShotGraphics)
  {
    // Remove from scene node
    Ogre::SceneNode* node = mpShotGraphics->getParentSceneNode();
    if (node)
    {
      node->removeAndDestroyAllChildren();
      node->getParentSceneNode()->removeChild(node);
      mpsSceneMgr->destroySceneNode(node);
      node = NULL;
    }

    // Destroy shot graphics
    mpsSceneMgr->destroyManualObject(mpShotGraphics);
    mpShotGraphics = NULL;
  }
}
Ejemplo n.º 10
0
void Actors::removeCell(MWWorld::Ptr::CellStore* store)
{
    for(PtrAnimationMap::iterator iter = mAllActors.begin();iter != mAllActors.end();)
    {
        if(iter->first.getCell() == store)
        {
            delete iter->second;
            mAllActors.erase(iter++);
        }
        else
            ++iter;
    }
    CellSceneNodeMap::iterator celliter = mCellSceneNodes.find(store);
    if(celliter != mCellSceneNodes.end())
    {
        Ogre::SceneNode *base = celliter->second;
        base->removeAndDestroyAllChildren();
        mRend.getScene()->destroySceneNode(base);
        mCellSceneNodes.erase(celliter);
    }
}
Ejemplo n.º 11
0
//update that checks the loaded list for adding or removing objects inside
void MapManager::UpdateLoadedList(std::vector<MapArea*> *input)
{
	//run through our current list
	//see if there is anything in the list to be updated
	std::vector<MapArea*>::iterator loadedIterator;
	for(loadedIterator = input->begin(); loadedIterator != input->end(); loadedIterator++)
	{
		//No matter if the area is fully inside or not, let's check if the area is now outside of the HOLDRADIUS
		if(!IsAreaInsideLoadRadius((*loadedIterator)))
		{
			if(!IsAreaInsideHoldRadius((*loadedIterator)))
			{
				//now, time to remove the area node
				//std::cout << "REMOVING AREA NODE!\n";
				char areaString[30];
				sprintf(areaString, "map_area_%d", (*loadedIterator)->getIndex());

				//get the area node from map node.
				Ogre::SceneNode* areaNode = (Ogre::SceneNode*)mMapNode->getChild(Ogre::String(areaString));

				//delete ground node
				char groundString[30];
				sprintf(groundString, "map_area_ground_%d", (*loadedIterator)->getIndex());

				Ogre::SceneNode* groundNode = (Ogre::SceneNode*)areaNode->getChild(Ogre::String(groundString));

				groundNode->removeAndDestroyAllChildren();
				groundNode->detachAllObjects();

				areaNode->removeAndDestroyChild(groundString);

				areaNode->removeAndDestroyAllChildren();
				areaNode->detachAllObjects();
				
				mMapNode->removeAndDestroyChild(areaString);

				//set the map area to be unloaded
				(*loadedIterator)->setLoaded(false);

				//remove it from the list
				input->erase(loadedIterator);
				return;
			}
		}

		//since this area is not fully inside, lets check if this object is currently inside the scene
		std::vector<Objects*>::iterator obstacleIterator;
		for(obstacleIterator = (*loadedIterator)->_mObstacleList.begin(); obstacleIterator!=(*loadedIterator)->_mObstacleList.end(); obstacleIterator++)
		{
			//is this object in the load radius?
			if(IsObjectInsideRadius((*obstacleIterator), LOADRADIUS))
			{
				//yes
				//is this object already loaded in the game?
				if((*obstacleIterator)->mLoaded)
				{
					//yes
					//skip
					continue;
				}
				else
				{
					//no
					//add it into the game
					AddObstacle((*loadedIterator), (*obstacleIterator));
				}
			}
			//is this object out of hold radius?
			else if(!IsObjectInsideRadius((*obstacleIterator), HOLDRADIUS))
			{
				//no
				//is this object already loaded in the game?
				if((*obstacleIterator)->mLoaded)
				{
					//yes
					//remove it
					RemoveObstacle((*loadedIterator),(*obstacleIterator));
				}
				else
				{
					//no
					//skip
					continue;
				}
			}
		}

		std::vector<Objects*>::iterator enemyIterator;
		for(enemyIterator = (*loadedIterator)->_mEnemySpawnPointList.begin(); enemyIterator!=(*loadedIterator)->_mEnemySpawnPointList.end(); enemyIterator++)
		{
			//is this object inside the load radius?
			if(IsObjectInsideRadius((*enemyIterator), ENEMY_LOADRADIUS))
			{
				//yes
				//is this enemy spawn point already loaded?
				if(!(*enemyIterator)->mLoaded)
				{
					//no
					//add enemy
					AddEnemy((*enemyIterator));
				}
			}
		}

		std::vector<Objects*>::iterator flamethrowerIterator;
		for(flamethrowerIterator = (*loadedIterator)->_mFlameThrowerList.begin(); flamethrowerIterator!=(*loadedIterator)->_mFlameThrowerList.end(); flamethrowerIterator++)
		{
			//no
			//is this object inside the load radius?
			if(!IsObjectInsideRadius((*flamethrowerIterator), ENEMY_LOADRADIUS))
			{
				//no
				//skip this object
				continue;
			}
			//yes continue whatever we need to do

			if(!(*flamethrowerIterator)->mLoaded)
				AddFlameThrower((*flamethrowerIterator));
		}
	}
}
Ejemplo n.º 12
0
INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
#else
int main (int argc, char *argv[]) {
#endif

	#define OGRE_STATIC_ParticleFX 1

	Ogre::Root *ogre;
	Ogre::RenderWindow *window;
	Ogre::SceneManager *sceneMgr;
	Ogre::Camera *camera;

	// fire up an Ogre rendering window. Clearing the first two (of three) params will let us 
	// specify plugins and resources in code instead of via text file
	ogre = new Ogre::Root("", "");


	// This is a VERY minimal rendersystem loading example; we are hardcoding the OpenGL 
	// renderer, instead of loading GL and D3D9. We will add renderer selection support in a 
	// future article.

	// I separate the debug and release versions of my plugins using the same "_d" suffix that
	// the Ogre main libraries use; you may need to remove the "_d" in your code, depending on the
	// naming convention you use 
	ogre->loadPlugin("RenderSystem_GL_d");
	ogre->loadPlugin("Plugin_ParticleFX_d");
	const Ogre::RenderSystemList &renderSystems = ogre->getAvailableRenderers();
	Ogre::RenderSystemList::const_iterator r_it;

	// we do this step just to get an iterator that we can use with setRenderSystem. In a future article
	// we actually will iterate the list to display which renderers are available. 
	// renderSystems = ogre->getAvailableRenderers();
	r_it = renderSystems.begin();
	ogre->setRenderSystem(*r_it);
	ogre->initialise(false);

	// load common plugins
	ogre->loadPlugin("Plugin_CgProgramManager_d");		
	ogre->loadPlugin("Plugin_OctreeSceneManager_d");

	// setup main window; hardcode some defaults for the sake of presentation
	Ogre::NameValuePairList opts;
	opts["resolution"] = "1024x768";
	opts["fullscreen"] = "false";
	opts["vsync"] = "true";

	// create a rendering window with the title "CDK"
	window = ogre->createRenderWindow("CDK", 1024, 768, false, &opts);

		// load the basic resource location(s)
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
		"resource", "FileSystem", "General");
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
		"resource/gui.zip", "Zip", "GUI");
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
		"resource/textures", "FileSystem", "Textures");
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
		"resource/particles", "FileSystem", "Particles");
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
		"resource/materials", "FileSystem", "Materials");
#if defined(WIN32)
	Ogre::ResourceGroupManager::getSingleton().addResourceLocation(
		"c:\\windows\\fonts", "FileSystem", "GUI"); 
#endif
	//Must initialize resource groups after window if using particle effects.
	Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("General");
	Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("GUI");
	Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Textures");
	Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Materials");
	Ogre::ResourceGroupManager::getSingleton().initialiseResourceGroup("Particles");

	// since this is basically a CEGUI app, we can use the ST_GENERIC scene manager for now; in a later article 
	// we'll see how to change this
	sceneMgr = ogre->createSceneManager(Ogre::ST_GENERIC);
	camera = sceneMgr->createCamera("camera");
	camera->setNearClipDistance(1);
    Ogre::Viewport* vp = window->addViewport(camera);
    vp->setBackgroundColour(Ogre::ColourValue(0,0,0));

	// most examples get the viewport size to calculate this; for now, we'll just 
	// set it to 4:3 the easy way
	camera->setAspectRatio((Ogre::Real)1.333333);

// with a scene manager and window, we can create a the GUI renderer
	
	// new way to instantiate a CEGUIOgreRenderer (Ogre 1.7)
	Ogre::RenderTarget *mRenderTarget = window;
	CEGUI::OgreRenderer* pGUIRenderer = &CEGUI::OgreRenderer::bootstrapSystem(*mRenderTarget);
 
	// create the root CEGUI class
	CEGUI::System* pSystem = CEGUI::System::getSingletonPtr();
 
	// tell us a lot about what is going on (see CEGUI.log in the working directory)
	CEGUI::Logger::getSingleton().setLoggingLevel(CEGUI::Informative);
 
	// use this CEGUI scheme definition (see CEGUI docs for more)
	CEGUI::SchemeManager::getSingleton().create((CEGUI::utf8*)"TaharezLookSkin.scheme", (CEGUI::utf8*)"GUI");
 
	// show the CEGUI mouse cursor (defined in the look-n-feel)
	pSystem->setDefaultMouseCursor((CEGUI::utf8*)"TaharezLook", (CEGUI::utf8*)"MouseArrow");
 
	// use this font for text in the UI
	CEGUI::FontManager::getSingleton().create("Tahoma-8.font", (CEGUI::utf8*)"GUI");
	pSystem->setDefaultFont((CEGUI::utf8*)"Tahoma-8");
 
	// load a layout from the XML layout file (you'll find this in resources/gui.zip), and 
	// put it in the GUI resource group
	CEGUI::Window* pLayout = CEGUI::WindowManager::getSingleton().loadWindowLayout("katana.layout", "", "GUI");
 
	// you need to tell CEGUI which layout to display. You can call this at any time to change the layout to
	// another loaded layout (i.e. moving from screen to screen or to load your HUD layout). Note that this takes
	// a CEGUI::Window instance -- you can use anything (any widget) that serves as a root window.
	pSystem->setGUISheet(pLayout);

	// this next bit is for the sake of the input handler
	unsigned long hWnd;
	// WINDOW is generic to all platforms now as of Eihort
	window->getCustomAttribute("WINDOW", &hWnd);

	// set up the input handlers
	Simulation *sim = new Simulation();

	// since the input handler deals with pushing input to CEGUI, we need to give it a pointer
	// to the CEGUI System instance to use
	InputHandler *handler = new InputHandler(pSystem, sim, hWnd);

	// put us into our "main menu" state
	sim->requestStateChange(GUI);

	// make an instance of our GUI sheet handler class
	MainMenuDlg* pDlg = new MainMenuDlg(pSystem, pLayout, sim);
	
	//testing shit
	Ogre::SceneNode *systemNode = sceneMgr->getRootSceneNode()->createChildSceneNode(Ogre::Vector3(0,0,0));
	

	
	SphereMesh *sphere = NULL;
	sphere->createSphere("sphereMesh", 80, 64, 64);


	/*
	// Now I can create several entities using that mesh
	Ogre::Entity *MoonEntity = sceneMgr->createEntity("Moon", planetMesh);
	// Now I attach it to a scenenode, so that it becomes present in the scene.
	Ogre::SceneNode *EarthOrbitNode = systemNode->createChildSceneNode("Earth Orbit", Ogre::Vector3(0,0,0));
	Ogre::SceneNode *EarthNode = EarthOrbitNode->createChildSceneNode("Earth", Ogre::Vector3(200,0,0));
	Ogre::SceneNode *MoonNode = EarthNode->createChildSceneNode("Moon", Ogre::Vector3(150,0,0));
	MoonNode->attachObject(MoonEntity);
	MoonEntity->getParentNode()->scale(0.5,0.5,0.5);
	*/
	//Material Tests
	Ogre::MaterialManager& lMaterialManager = Ogre::MaterialManager::getSingleton();
	Ogre::String lNameOfResourceGroup = "Mission 1 : Deliver Tom";
	
	Ogre::ResourceGroupManager& lRgMgr = Ogre::ResourceGroupManager::getSingleton();
	lRgMgr.createResourceGroup(lNameOfResourceGroup);

	{
			Ogre::MaterialPtr lMaterial = lMaterialManager.create("M_Lighting+OneTexture",lNameOfResourceGroup);
			Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0);
			Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0);
 
			lFirstPass->setDiffuse(0.8f, 0.8f, 0.8f,1.0f);
			lFirstPass->setAmbient(0.3f, 0.3f, 0.3f);
			lFirstPass->setSpecular(1.0f, 1.0f, 1.0f, 1.0f);
			lFirstPass->setShininess(64.0f);
			lFirstPass->setSelfIllumination(0.1f, 0.1f, 0.1f);

			Ogre::TextureUnitState* lTextureUnit = lFirstPass->createTextureUnitState();
			lTextureUnit->setTextureName("SimpleTexture.bmp", Ogre::TEX_TYPE_2D);
			lTextureUnit->setTextureCoordSet(0);
	}
	
	
	// 3/ Lighting color.
	// To have the feeling of '3D', the lighting is good feeling.
		// It often requires the object to have correct normals (see my manual object construction), 
		// and some lights in the scene.
		
	{
			Ogre::MaterialPtr lMaterial = lMaterialManager.create("Sun",lNameOfResourceGroup);
			Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0);
			Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0);
			
			// Lighting is allowed on this pass.
			lFirstPass->setLightingEnabled(true);

			// Emissive / self illumination is the color 'produced' by the object.
			// Color values vary between 0.0(minimum) to 1.0 (maximum).
			Ogre::ColourValue lSelfIllumnationColour(0.5f, 0.0f, 0.0f, 1.0f);
			lFirstPass->setSelfIllumination(lSelfIllumnationColour);

			// diffuse color is the traditionnal color of the lit object.
			Ogre::ColourValue lDiffuseColour(1.0f, 0.4f, 0.4f, 1.0f);
			lFirstPass->setDiffuse(lDiffuseColour);

			// ambient colour is linked to ambient lighting.
			// If there is no ambient lighting, then this has no influence.
			// It the ambient lighting is at 1, then this colour is fully added.
			// This is often use to change the general feeling of a whole scene.
			Ogre::ColourValue lAmbientColour(0.4f, 0.1f, 0.1f, 1.0f);
			lFirstPass->setAmbient(lAmbientColour);

			// specular colour, is the colour of the 'little light reflection'
			// that you can see on some object. For example, my bald head skin
			// reflect the sun. This make a 'round of specular lighting'.
			// Set this to black if you don't want to see it.
			Ogre::ColourValue lSpecularColour(1.0f, 1.0f, 1.0f, 1.0f);
			lFirstPass->setSpecular(lSpecularColour);

			// Shininess is the 'inverse of specular color splattering' coefficient.
			// If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface).
			// If this is 0, you get a simple color layer (the dot has become very wide).
			Ogre::Real lShininess = 64.0f;
			lFirstPass->setShininess(lShininess);
	}
		{
			Ogre::MaterialPtr lMaterial = lMaterialManager.create("mars",lNameOfResourceGroup);
			Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0);
			Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0);
			
			// Lighting is allowed on this pass.
			lFirstPass->setLightingEnabled(true);

			// Emissive / self illumination is the color 'produced' by the object.
			// Color values vary between 0.0(minimum) to 1.0 (maximum).
			Ogre::ColourValue lSelfIllumnationColour(0.6f, 0.1f, 0.1f, 0.0f);
			lFirstPass->setSelfIllumination(lSelfIllumnationColour);

			// diffuse color is the traditionnal color of the lit object.
			Ogre::ColourValue lDiffuseColour(1.0f, 0.2f, 0.0f, 0.0f);
			lFirstPass->setDiffuse(lDiffuseColour);

			// ambient colour is linked to ambient lighting.
			// If there is no ambient lighting, then this has no influence.
			// It the ambient lighting is at 1, then this colour is fully added.
			// This is often use to change the general feeling of a whole scene.
			Ogre::ColourValue lAmbientColour(1.0f, 0.2f, 0.0f, 0.0f);
			lFirstPass->setAmbient(lAmbientColour);

			// specular colour, is the colour of the 'little light reflection'
			// that you can see on some object. For example, my bald head skin
			// reflect the sun. This make a 'round of specular lighting'.
			// Set this to black if you don't want to see it.
			Ogre::ColourValue lSpecularColour(1.0f, 0.3f, 0.3f, 0.3f);
			lFirstPass->setSpecular(lSpecularColour);

			// Shininess is the 'inverse of specular color splattering' coefficient.
			// If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface).
			// If this is 0, you get a simple color layer (the dot has become very wide).
			Ogre::Real lShininess = 34.0f;
			lFirstPass->setShininess(lShininess);
		}

	{
			Ogre::MaterialPtr lMaterial = lMaterialManager.create("gaia",lNameOfResourceGroup);
			Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0);
			Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0);
			
			// Lighting is allowed on this pass.
			lFirstPass->setLightingEnabled(true);

			// Emissive / self illumination is the color 'produced' by the object.
			// Color values vary between 0.0(minimum) to 1.0 (maximum).
			Ogre::ColourValue lSelfIllumnationColour(0.0f, 0.0f, 0.1f, 0.3f);
			lFirstPass->setSelfIllumination(lSelfIllumnationColour);

			// diffuse color is the traditionnal color of the lit object.
			Ogre::ColourValue lDiffuseColour(0.1f, 0.2f, 0.8f, 1.0f);
			lFirstPass->setDiffuse(lDiffuseColour);

			// ambient colour is linked to ambient lighting.
			// If there is no ambient lighting, then this has no influence.
			// It the ambient lighting is at 1, then this colour is fully added.
			// This is often use to change the general feeling of a whole scene.
			Ogre::ColourValue lAmbientColour(0.0f, 0.1f, 0.4f, 1.0f);
			lFirstPass->setAmbient(lAmbientColour);

			// specular colour, is the colour of the 'little light reflection'
			// that you can see on some object. For example, my bald head skin
			// reflect the sun. This make a 'round of specular lighting'.
			// Set this to black if you don't want to see it.
			Ogre::ColourValue lSpecularColour(0.0f, 0.3f, 1.0f, 1.0f);
			lFirstPass->setSpecular(lSpecularColour);

			// Shininess is the 'inverse of specular color splattering' coefficient.
			// If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface).
			// If this is 0, you get a simple color layer (the dot has become very wide).
			Ogre::Real lShininess = 34.0f;
			lFirstPass->setShininess(lShininess);
		}
		{
			Ogre::MaterialPtr lMaterial = lMaterialManager.create("barren",lNameOfResourceGroup);
			Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0);
			Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0);
			
			// Lighting is allowed on this pass.
			lFirstPass->setLightingEnabled(true);

			// Emissive / self illumination is the color 'produced' by the object.
			// Color values vary between 0.0(minimum) to 1.0 (maximum).
			Ogre::ColourValue lSelfIllumnationColour(0.1f, 0.1f, 0.1f, 0.1f);
			lFirstPass->setSelfIllumination(lSelfIllumnationColour);

			// diffuse color is the traditionnal color of the lit object.
			Ogre::ColourValue lDiffuseColour(0.3f, 0.3f, 0.3f, 0.3f);
			lFirstPass->setDiffuse(lDiffuseColour);

			// ambient colour is linked to ambient lighting.
			// If there is no ambient lighting, then this has no influence.
			// It the ambient lighting is at 1, then this colour is fully added.
			// This is often use to change the general feeling of a whole scene.
			Ogre::ColourValue lAmbientColour(0.3f, 0.3f, 0.3f, 0.3f);
			lFirstPass->setAmbient(lAmbientColour);

			// specular colour, is the colour of the 'little light reflection'
			// that you can see on some object. For example, my bald head skin
			// reflect the sun. This make a 'round of specular lighting'.
			// Set this to black if you don't want to see it.
			Ogre::ColourValue lSpecularColour(0.7f, 0.7f, 0.7f, 0.7f);
			lFirstPass->setSpecular(lSpecularColour);

			// Shininess is the 'inverse of specular color splattering' coefficient.
			// If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface).
			// If this is 0, you get a simple color layer (the dot has become very wide).
			Ogre::Real lShininess = 34.0f;
			lFirstPass->setShininess(lShininess);
		}
	{
			Ogre::MaterialPtr lMaterial = lMaterialManager.create("gasgiant",lNameOfResourceGroup);
			Ogre::Technique* lFirstTechnique = lMaterial->getTechnique(0);
			Ogre::Pass* lFirstPass = lFirstTechnique->getPass(0);
			
			// Lighting is allowed on this pass.
			lFirstPass->setLightingEnabled(true);

			// Emissive / self illumination is the color 'produced' by the object.
			// Color values vary between 0.0(minimum) to 1.0 (maximum).
			Ogre::ColourValue lSelfIllumnationColour(0.0f, 0.3f, 0.0f, 0.1f);
			lFirstPass->setSelfIllumination(lSelfIllumnationColour);

			// diffuse color is the traditionnal color of the lit object.
			Ogre::ColourValue lDiffuseColour(0.1f, 0.7f, 0.1f, 0.3f);
			lFirstPass->setDiffuse(lDiffuseColour);

			// ambient colour is linked to ambient lighting.
			// If there is no ambient lighting, then this has no influence.
			// It the ambient lighting is at 1, then this colour is fully added.
			// This is often use to change the general feeling of a whole scene.
			Ogre::ColourValue lAmbientColour(0.1f, 0.7f, 0.3f, 0.3f);
			lFirstPass->setAmbient(lAmbientColour);

			// specular colour, is the colour of the 'little light reflection'
			// that you can see on some object. For example, my bald head skin
			// reflect the sun. This make a 'round of specular lighting'.
			// Set this to black if you don't want to see it.
			Ogre::ColourValue lSpecularColour(0.2f, 1.0f, 0.6f, 0.6f);
			lFirstPass->setSpecular(lSpecularColour);

			// Shininess is the 'inverse of specular color splattering' coefficient.
			// If this is big (e.g : 64) you get a very tiny dot with a quite strong color (on round surface).
			// If this is 0, you get a simple color layer (the dot has become very wide).
			Ogre::Real lShininess = 34.0f;
			lFirstPass->setShininess(lShininess);
		}

	//end material tests

	//System Creator
	std::string systemDefinition[10] = {"15000,0,0,false,false,false,700000,0", "300,0,0,false,false,barren,2500,1",
		"300,x,y,false,co2,barren,6000,2", "300,x,y,h2o,n2/o2,gaia,6300,3", "300,x,y,false,co2,mars,3400,4",
		"300,x,y,false,h2/he,gasgiant,71000,5", "300,x,y,false,h2/he,gasgiant,60000,6", "300,x,y,false,h2/he,gasgiant,25001,7",
		"300,x,y,false,h2/he,gasgiant,25000,8", "300,x,y,false,n-ice,ice,1100,9"};

	StarSystem sol = StarSystem::StarSystem(sceneMgr, systemDefinition);

	//Star Creator
	/*
	{
	int x = 0;
	int y = 0;
	int kelvin = 15000;
	CelestialBody newstar = CelestialBody::CelestialBody(kelvin, 100, systemNode, sceneMgr, x, y);
	}

	// Spectrum testing and multi star generation.
	
	int time = 200;
	int x = -500;
	int y = 500;

	for ( int count = 1; count <= time; count++){
	
		int kelvin = count * (40000/time);
		Star newstar = Star::Star(kelvin, 100, systemNode, sceneMgr, x, y);
		x += 20;

		if (count % 10 == 0) {
			y -= 20;
			x = -500;
		}
	}
	*/

	// I move the SceneNode back 15 so that it is visible to the camera.
	float PositionOffset = 0.0;
	float distance = -2000.0;

	systemNode->translate(0, PositionOffset, distance);
	
	camera->lookAt(Ogre::Vector3(0,0,distance));

	while (sim->getCurrentState() != SHUTDOWN) {
		
		sol.rotateOrbits();
		
		handler->capture();

		ogre->renderOneFrame();

		// run the message pump (uncomment for Eihort)
		Ogre::WindowEventUtilities::messagePump();
	}

	{
		window->removeAllViewports();
	}
	{
		sceneMgr->destroyAllCameras();
		sceneMgr->destroyAllManualObjects();
		sceneMgr->destroyAllEntities();
		sceneMgr->destroyAllLights();
		systemNode->removeAndDestroyAllChildren();
	}

	{
		Ogre::ResourceGroupManager& lRgMgr = Ogre::ResourceGroupManager::getSingleton();
		lRgMgr.destroyResourceGroup(lNameOfResourceGroup);
	}

	// clean up after ourselves
	delete pDlg;
	delete handler;
	delete sim;
	delete ogre;

	return 0;
}
Ejemplo n.º 13
0
/*
 * Runs on each frame starts
 */
bool MyFrameListener::frameStarted(const Ogre::FrameEvent& evt) {


  
  _mouse->capture();
    
  MyGUI::InputManager::getInstance().injectMouseMove(_mouse->getMouseState().X.abs,
                                                     _mouse->getMouseState().Y.abs,
                                                     _mouse->getMouseState().Z.abs);


  bool leftMouseclick = false;
  bool releaseMouseclick= false;
  int mousex = _mouse->getMouseState().X.abs;
  int mousey = _mouse->getMouseState().Y.abs;

  if ( _mouse->getMouseState().buttonDown(OIS::MB_Left) == true &&
       this->_btnIzqPulsado == false){
    MyGUI::InputManager::getInstance().injectMousePress(_mouse->getMouseState().X.abs,
                                                        _mouse->getMouseState().Y.abs,
                                                        MyGUI::MouseButton::Left);
    this->_btnIzqPulsado = true;
    leftMouseclick = true;

  }
  if (_mouse->getMouseState().buttonDown(OIS::MB_Left) == false &&
      this->_btnIzqPulsado==true ){
    this->_btnIzqPulsado =false;
    releaseMouseclick = true;
    MyGUI::InputManager::getInstance().injectMouseRelease(_mouse->getMouseState().X.abs,
                                                          _mouse->getMouseState().Y.abs,
                                                          MyGUI::MouseButton::Left);
  }


  if (_mode == GAME_FINISHED){
    if (leftMouseclick){
      Ogre::SceneNode *popup = Ogre::Root::getSingleton().
                               getSceneManager("mainSM")->getSceneNode("popup");
      popup->removeAndDestroyAllChildren();
      Ogre::Root::getSingleton().getSceneManager("mainSM")->destroySceneNode("popup");
      _mode = MODE_STARTED;
      if (_points > 0){
        _gui->add_record(_user,_points);
        _points = 0;
      }
      _gui->createScene();
      _gui->enable();

    }
  }
  if (_mode == MODE_PLACE_SHIP) {
    if (leftMouseclick){
      this->selectShip();
    } else if (releaseMouseclick) {
      if (this->_idSelectedShip >= 0) {
        this->setSelectedShipGameCoords();
        //Check if all ships are placed to start playing
        if (this->playerBoard->areAllShipsPlaced() == true) {
          _turn = PLAYER_TURN;
          _mode = MODE_SHOOT;
          this->paintShootingBoard();
        }
      }
      this->_idSelectedShip = -1;
    }
    /*
     * If there is a ship selected, translate drag and drop
     */
    if (this->_idSelectedShip >= 0) {
      const Ogre::Vector3 &position = this->getMouse3DPoint();
      this->playerBoard->getShip(this->_idSelectedShip)
          ->setShipPosition(position);
    }
    if ( _mouse->getMouseState().buttonDown(OIS::MB_Right) == true
         && this->_btnDchoPulsado == false) {
      this->_btnDchoPulsado = true;
      if (this->_idSelectedShip >= 0) {
        this->playerBoard->getShip(this->_idSelectedShip)
            ->rotateShip();
      }
    }
    if (!_mouse->getMouseState().buttonDown(OIS::MB_Right)) {
      this->_btnDchoPulsado = false;
    }

      


  }
  else if (_mode == MODE_SHOOT){
    manageShootMode();
  }
  _keyboard->capture();

  _keyboard->setEventCallback(_guiHandler);
    
  if (_keyboard->isKeyDown(OIS::KC_ESCAPE)) {
    return false;
  }
  return true;
}
bool TutorialApplication::frameRenderingQueued(const Ogre::FrameEvent& evt) {
	if (BaseApplication::frameRenderingQueued(evt)) {
		PhysicsManager::reference()->Update(evt.timeSinceLastFrame);
        
		//player->Translate( player->entity()->getParentSceneNode()->getOrientation() * mDirection * evt.timeSinceLastFrame);
        player->Move( camera->actual_orientation() * mDirection * (1.0/50.0) );
        
        if (mJoyStick) {
            /* For some reason, OIS reports one of my gamepad's axes as a 'slider'(at least in windows)...
            Also, joystick event are called only when axis/slider value changes, and since they aren't 
            continuous, you can stick a axis to one side continuosly but the event will only be called once,
            so we need to do this here.
            Finally, aparently after moving from the initial state of value 0 the axis rest at [-]256 and not at 0...
            */
            OIS::JoyStickState joy = mJoyStick->getJoyStickState();
            double yaw = 0;
            if ( Ogre::Math::Abs(CAMERA_YAW_VALUE) > 256)
                yaw = -150 * evt.timeSinceLastFrame * CAMERA_YAW_VALUE / OIS::JoyStick::MAX_AXIS;
            double pitch = 0;
            if ( Ogre::Math::Abs(CAMERA_PITCH_VALUE) > 256)
                pitch = -150 * evt.timeSinceLastFrame * CAMERA_PITCH_VALUE / OIS::JoyStick::MAX_AXIS;
            camera->Rotate(yaw, pitch);
            //player->Rotate(pitch*100, yaw*100, 0);

            if (joy.mPOV[0].direction == OIS::Pov::North)
                camera->SetDistance( camera->GetDistance() - evt.timeSinceLastFrame*2);
            else if (joy.mPOV[0].direction == OIS::Pov::South)
                camera->SetDistance( camera->GetDistance() + evt.timeSinceLastFrame*2);

        }

        for (auto& pair: projectiles_) {
            Projectile& proj = pair.second;
            proj.lifetime -= evt.timeSinceLastFrame;
            if (proj.lifetime < 0) {
                //objects_.remove(proj.owner);
                if (std::find(projs_to_remove_.begin(), projs_to_remove_.end(), pair.first) == projs_to_remove_.end() )
                    projs_to_remove_.push_back(pair.first);
                //delete proj.owner;
            }
        }
        for (auto& name : projs_to_remove_) {
            Projectile& proj = projectiles_[name];
            objects_.remove(proj.owner);
            delete proj.owner;
            projectiles_.erase(name);
        }
        projs_to_remove_.clear();
            
        for (auto& pair: enemies_) {
            Enemy& ene = pair.second;
            if (ene.owner->entity()->getVisible()) {
                ene.timeElapsed += evt.timeSinceLastFrame;
                if (ene.timeElapsed > ene.cooldown) {
                    ene.timeElapsed = 0.0;
                    evilShot(ene.owner, Ogre::Math::UnitRandom()*70);
                }
            }
            else if (ene.particles != nullptr) {
                if (! ene.particles->getEmitter(0)->getEnabled()) {
                    if (std::find(enemies_to_remove_.begin(), enemies_to_remove_.end(), ene.owner->entity_name()) == enemies_to_remove_.end() )
                        enemies_to_remove_.push_back(ene.owner->entity_name());
                }
            }
        }
        for (auto& name : enemies_to_remove_) {
            Enemy& ene = enemies_[name];
            objects_.remove(ene.owner);
            delete ene.owner;
            if (ene.particles != nullptr) {
                Ogre::SceneNode* node = ene.particles->getParentSceneNode();
                node->removeAndDestroyAllChildren();
                mSceneMgr->destroySceneNode(node);
                mSceneMgr->destroyParticleSystem(ene.particles);
            }
            enemies_.erase(name);
        }
        enemies_to_remove_.clear();        
		return true;
	}
	return false;
}