Ejemplo n.º 1
0
void EngineMap::create() {
	//carrega atributos do xml
	String fileName = "media/maps/";
	fileName += _name.c_str();
	fileName += ".xml";
	
	TiXmlDocument doc(fileName.c_str());
	if (!doc.LoadFile()) return;

	TiXmlHandle handleDoc(&doc);
	
	//obtém elemento com as configurações do mapa
	TiXmlElement* elMap = handleDoc.FirstChild("map").Element();
	if (!elMap) return;

	String stPlayerStart            = elMap->Attribute("player_start");
	String stPlayerStartOrientation = elMap->Attribute("player_start_orientation");
	String stSkyBox                 = elMap->Attribute("skybox");
	String stMinWorldSize           = elMap->Attribute("min_world_size");
	String stMaxWorldSize           = elMap->Attribute("max_world_size");
	String stAmbientLight           = elMap->Attribute("ambient_light");
	
	if (stPlayerStart != "") {
		_playerStart = StringConverter::parseVector3(stPlayerStart);
	} else {
		_playerStart = Vector3::ZERO;
	}

	if (stPlayerStartOrientation != "") {
		_playerStartOrientation = StringConverter::parseQuaternion(stPlayerStartOrientation);
	} else {
		_playerStartOrientation = Quaternion(1,0,0,0);
	}

	_skybox       = stSkyBox;
	_minWorldSize = StringConverter::parseVector3(stMinWorldSize);
	_maxWorldSize = StringConverter::parseVector3(stMaxWorldSize);

	//cria a iluminação geral do mapa
	Vector3 ambientLight = StringConverter::parseVector3(stAmbientLight);
	EngineGlobalObjects::getInstance().getSceneManager()->setAmbientLight(ColourValue(ambientLight.x, ambientLight.y, ambientLight.z));	
	
	//obtém elementos e cria
	TiXmlElement* elObject = elMap->FirstChildElement("object");

	while(elObject) {  
		
		//obtém o tipo do objeto
		String stType = elObject->Attribute("type");
		
		//verifica o tipo
		if (stType == "static_mesh") {
			String stMass         = elObject->Attribute("mass");
			String stInertia      = elObject->Attribute("inertia");
			String stCollision    = elObject->Attribute("collision");
			String stCastShadows  = elObject->Attribute("castshadows");
			String stMeshFile     = elObject->Attribute("meshfile");
			String stMaterial     = elObject->Attribute("material");
			String stName         = elObject->Attribute("name");
			String stPosition     = elObject->Attribute("position");
			String stOrientation  = elObject->Attribute("orientation");
			String stScale        = elObject->Attribute("scale");
			String stCenterOfMass = elObject->Attribute("center_of_mass");
			
			//prepara os atributos
			bool castShadow		   = StringConverter::parseBool(stCastShadows);
			String nodeName        = "map_object_" + stName;
			String entityName      = "map_object_entity_" + stName;
			Real mass			   = StringConverter::parseReal(stMass);
			Vector3 inertia	       = StringConverter::parseVector3(stInertia);
			Vector3 position	   = StringConverter::parseVector3(stPosition);
			Quaternion orientation = StringConverter::parseQuaternion(stOrientation);
			Vector3 scale          = StringConverter::parseVector3(stScale);
			Vector3 centerOfMass   = StringConverter::parseVector3(stCenterOfMass);

			//cria o node e entity
			Entity *entity;
			entity = EngineGlobalObjects::getInstance().getSceneManager()->createEntity(entityName, stMeshFile);
			
			if (stMaterial != "") {
				entity->setMaterialName(stMaterial);
			}

			entity->setCastShadows(castShadow);

			SceneNode *node = EngineGlobalObjects::getInstance().getSceneManager()->getRootSceneNode()->createChildSceneNode(nodeName);
			node->attachObject(entity);

			//define tamanho
			node->setScale(scale);

			//cria colisão
			if (stCollision == "fixed") {
				
				OgreNewt::CollisionPtr col = OgreNewt::CollisionPtr(new OgreNewt::CollisionPrimitives::TreeCollision( EngineGlobalObjects::getInstance().getWorld(), entity, true, 0 ));
				OgreNewt::Body* bod = new OgreNewt::Body( EngineGlobalObjects::getInstance().getWorld(), col );			
				
				bod->attachNode( node );
				bod->setPositionOrientation( position, orientation );
				
				//define callback customizado
				bod->setCustomForceAndTorqueCallback<EngineMap>(&EngineMap::forceCallback, this);

			} else if (stCollision == "normal") {				
				
				OgreNewt::ConvexCollisionPtr col = OgreNewt::ConvexCollisionPtr(new OgreNewt::CollisionPrimitives::ConvexHull(EngineGlobalObjects::getInstance().getWorld(), entity, 0));
				OgreNewt::Body* bod = new OgreNewt::Body( EngineGlobalObjects::getInstance().getWorld(), col );

				bod->attachNode( node );
				bod->setMassMatrix( mass, inertia );
				bod->setCenterOfMass(centerOfMass);
				bod->setStandardForceCallback();

				bod->setPositionOrientation( position, orientation );
				
				//define callback customizado
				bod->setCustomForceAndTorqueCallback<EngineMap>(&EngineMap::forceCallback, this);
			}

		} else if (stType == "light") {
			
			String stName         = elObject->Attribute("name");
			String stPosition     = elObject->Attribute("position");
			String stDirection    = elObject->Attribute("direction");
			String stAttenuation  = elObject->Attribute("attenuation");
			String stCastShadows  = elObject->Attribute("castshadows");
			String stDiffuse      = elObject->Attribute("diffuse");
			String stLightrange   = elObject->Attribute("lightrange");
			String stLighttype    = elObject->Attribute("lighttype");
			String stPower        = elObject->Attribute("power");
			String stSpecular     = elObject->Attribute("specular");

			Light *light;
			light = EngineGlobalObjects::getInstance().getSceneManager()->createLight(stName);
			
			if(stLighttype=="LT_POINT") light->setType(Light::LT_POINT);
			if(stLighttype=="LT_SPOTLIGHT") light->setType(Light::LT_SPOTLIGHT);
			if(stLighttype=="LT_DIRECTIONAL") light->setType(Light::LT_DIRECTIONAL);

			light->setPosition(StringConverter::parseVector3(stPosition));
			light->setDiffuseColour(StringConverter::parseColourValue(stDiffuse));
			light->setSpecularColour(StringConverter::parseColourValue(stSpecular));
			
			Vector4 att = StringConverter::parseVector4(stAttenuation);
			light->setAttenuation(att.x, att.y, att.z, att.w);
			light->setDirection(StringConverter::parseVector3(stDirection));
			light->setPowerScale(StringConverter::parseReal(stPower));
			light->setSpotlightFalloff(1);

			light->setCastShadows(StringConverter::parseBool(stCastShadows));

		}

		elObject = elObject->NextSiblingElement("object");
	}

	//obtém elementos da fog e cria
	TiXmlElement* elFog = elMap->FirstChildElement("fog");

	while(elFog) {  
		String stFogMode    = elFog->Attribute("mode");
		String stFogColour  = elFog->Attribute("colour");
		String stFogStart   = elFog->Attribute("start");
		String stFogEnd     = elFog->Attribute("end");
		String stFogDensity = elFog->Attribute("density");
		
		_fogMode    = stFogMode;
		_fogColour  = StringConverter::parseColourValue(stFogColour);
		_fogStart   = StringConverter::parseReal(stFogStart);
		_fogEnd     = StringConverter::parseReal(stFogEnd);
		_fogDensity = StringConverter::parseReal(stFogDensity);
		
		//configura a fog no cenário se o modo da fog foi informado
		if (stFogMode != "") {
			FogMode fogMode;

			if (_fogMode == "none") fogMode = FogMode::FOG_NONE;
			if (_fogMode == "exp") fogMode = FogMode::FOG_EXP;
			if (_fogMode == "exp2") fogMode = FogMode::FOG_EXP2;
			if (_fogMode == "linear") fogMode = FogMode::FOG_LINEAR;

			EngineGlobalObjects::getInstance().getSceneManager()->setFog(fogMode, _fogColour, _fogDensity, _fogStart, _fogEnd); 
		}


		elFog = elFog->NextSiblingElement("fog");
	}



	//cria o céu
	createSkyBox();	

	doc.Clear();
}
Ejemplo n.º 2
0
// load scripts
void doScriptsLoad()
{
    // clear the scripts vector
    vectorScripts.clear();

    // declare xml file
    TiXmlDocument file("tibialua.xml");

    // load xml file
    if (!file.LoadFile())
        return;

    // prepare to parse xml file
    TiXmlHandle handleDoc(&file);

    // find scripts
    TiXmlHandle handleScripts = handleDoc.FirstChildElement("scripts");

    // find script
    TiXmlElement* elementScript = handleScripts.FirstChildElement("script").Element();

    // parse xml file
    int scriptId = 0;
    for (elementScript; elementScript; elementScript = elementScript->NextSiblingElement())
    {
        // tibia lua script
        TibiaLuaScript script;

        // get id
        script.id = scriptId;

        // get file name
        script.fileName = elementScript->Attribute("filename");

        // get name
        script.name = elementScript->Attribute("name");

        // find hotkey
        TiXmlHandle handleHotkey = TiXmlHandle(elementScript);
        TiXmlElement* elementHotkey = handleHotkey.FirstChildElement("hotkey").Element();

        // get hotkey id
        elementHotkey->QueryIntAttribute("id" , &script.hotkeyId);

        // get hotkey name
        script.hotkeyName = elementHotkey->Attribute("name");

        // find timer
        TiXmlHandle handleTimer = TiXmlHandle(elementScript);
        TiXmlElement* elementTimer = handleTimer.FirstChildElement("timer").Element();

        // get timer delay
        elementTimer->QueryIntAttribute("delay" , &script.timerDelay);

        // get timer start enabled
        elementTimer->QueryIntAttribute("startenabled" , &script.timerStartEnabled);

        // find menu
        TiXmlHandle handleMenu = TiXmlHandle(elementScript);
        TiXmlElement* elementMenu = handleMenu.FirstChildElement("menu").Element();

        // get menu visible
        elementMenu->QueryIntAttribute("visible" , &script.menuVisible);

        // add the script to the scripts vector
        vectorScripts.push_back(script);

        // next script id
        scriptId++;
    }
}
Ejemplo n.º 3
0
void Engine::createWeapons() {
	//carrega atributos do xml
	String fileName = "media/weapons/weapons.xml";
	
	TiXmlDocument doc(fileName.c_str());
	if (!doc.LoadFile()) return;

	TiXmlHandle handleDoc(&doc);
	
	//obtém elemento com as configurações do mapa
	TiXmlElement* elWeapons = handleDoc.FirstChild("weapons").Element();
	if (!elWeapons) return;

	//obtém elementos e cria
	TiXmlElement* elWeapon = elWeapons->FirstChildElement("weapon");

	while(elWeapon) {  
		
		String stMass			    = elWeapon->Attribute("mass");
		String stInertia		    = elWeapon->Attribute("inertia");
		String stCollision		    = elWeapon->Attribute("collision");
		String stCastShadows	    = elWeapon->Attribute("castshadows");
		String stMeshFile		    = elWeapon->Attribute("meshfile");
		String stName			    = elWeapon->Attribute("name");
		String stMaterial		    = elWeapon->Attribute("material");
		String stScale			    = elWeapon->Attribute("scale");
		String stCenterOfMass	    = elWeapon->Attribute("center_of_mass");
		String stVelocity		    = elWeapon->Attribute("velocity");
		String stDistanceFromPlayer = elWeapon->Attribute("distance_from_player");
		String stMoveDirection      = elWeapon->Attribute("move_direction");
		String stShootInterval      = elWeapon->Attribute("shoot_interval");
		
		//prepara os atributos
		bool castShadow		       = StringConverter::parseBool(stCastShadows);
		String entityName          = "weapon_object_entity_" + stName;
		Real mass				   = StringConverter::parseReal(stMass);
		Vector3 inertia	           = StringConverter::parseVector3(stInertia);
		Vector3 scale              = StringConverter::parseVector3(stScale);
		Vector3 centerOfMass	   = StringConverter::parseVector3(stCenterOfMass);
		Vector3 distanceFromPlayer = StringConverter::parseVector3(stDistanceFromPlayer);
		Vector3 moveDirection      = StringConverter::parseVector3(stMoveDirection);
		Real velocity		       = StringConverter::parseReal(stVelocity);
		Real shootInterval         = StringConverter::parseReal(stShootInterval);

		//cria o node e entity
		Entity *entity;
		entity = EngineGlobalObjects::getInstance().getSceneManager()->createEntity(entityName, stMeshFile);
		
		if (stMaterial != "") {
			entity->setMaterialName(stMaterial);
		}

		entity->setCastShadows(castShadow);
		
		//cria objeto e define atributos
		_weapons.push_back( new EngineWeapon() );
		
		int lastWeapon = _weapons.size()-1;
		
		_weapons[lastWeapon]->setCastShadow(castShadow);
		_weapons[lastWeapon]->setEntity(entity);
		_weapons[lastWeapon]->setMaterial(stMaterial);
		_weapons[lastWeapon]->setModel(stMeshFile);
		_weapons[lastWeapon]->setName(stName);
		_weapons[lastWeapon]->setScale(scale);
		_weapons[lastWeapon]->setVelocity(velocity);
		_weapons[lastWeapon]->setMass(mass);
		_weapons[lastWeapon]->setInertia(inertia);
		_weapons[lastWeapon]->setCenterOfMass(centerOfMass);
		_weapons[lastWeapon]->setDistanceFromPlayer(distanceFromPlayer);
		_weapons[lastWeapon]->setMoveDirection(moveDirection);
		_weapons[lastWeapon]->setShootInterval(shootInterval);

		elWeapon = elWeapon->NextSiblingElement("weapon");
	}

	doc.Clear();

	EngineGlobalObjects::getInstance().setWeapons(_weapons);
}