コード例 #1
0
ファイル: ArrayGraphics.cpp プロジェクト: franaisa/Gloom
	bool CArrayGraphics::spawn(CEntity *entity, CMap *map, const Map::CEntity *entityInfo) 
	{
		if(!IComponent::spawn(entity,map,entityInfo))
			return false;
		
		_scene = _entity->getMap()->getScene();
		
		if(entityInfo->hasAttribute("numWeapons")){
			int numWeapons = entityInfo->getIntAttribute("numWeapons");
			
			_graphicsEntities = new TGraphicsWeapon[numWeapons];



			// Por ahora leo a mano cada una de las armas que tiene el usuario

			std::string armas[] = {"soulReaper","sniper","shotGun","miniGun", "grenadeLauncher"};

			
			for(int i = 0; i < numWeapons; ++i){
				
				std::stringstream aux;
				aux << "weapon" << armas[i];
				std::string weapon = aux.str();
				
				printf("%s", weapon.c_str());
				
				_graphicsEntities[i]._graphicsEntity = createGraphicsEntity(weapon, entityInfo->getStringAttribute(weapon+"Model"));
				assert(_graphicsEntities[i]._graphicsEntity != 0 && "error al cargar la entidad grafica");
				if(entityInfo->hasAttribute(weapon+"ModelYaw"))
					_graphicsEntities[i].yaw = entityInfo->getFloatAttribute(weapon+"ModelYaw");
				if(entityInfo->hasAttribute(weapon+"ModelPitch"))
					_graphicsEntities[i].pitch = entityInfo->getFloatAttribute(weapon+"ModelPitch");
				if(entityInfo->hasAttribute(weapon+"ModelRoll"))
					_graphicsEntities[i].pitch = entityInfo->getFloatAttribute(weapon+"ModelRoll");
				
				//Esto perta y creo q es necesario.
				_graphicsEntities[i].offset = new Vector3(entityInfo->getVector3Attribute(weapon+"Offset"));
				
				if(i!=0) _graphicsEntities[i]._graphicsEntity->setVisible(false);
			}
		}
		if(!_graphicsEntities)
			return false;
		
		setTransform();

		return true;

	} // spawn
コード例 #2
0
ファイル: Graphics.cpp プロジェクト: NoisyBass/Hulen
	bool CGraphics::spawn(CEntity *entity, CMap *map, const Map::CEntity *entityInfo) 
	{
		if(!IComponent::spawn(entity,map,entityInfo))
			return false;
		
		_scene = _entity->getMap()->getScene();

		if(entityInfo->hasAttribute("model"))
			_model = entityInfo->getStringAttribute("model");

		_graphicsEntity = createGraphicsEntity(entityInfo);
		if(!_graphicsEntity)
			return false;

		return true;

	} // spawn
コード例 #3
0
ファイル: Graphics.cpp プロジェクト: franaisa/Gloom
	bool CGraphics::spawn(CEntity *entity, CMap *map, const Map::CEntity *entityInfo) 
	{
		if(!IComponent::spawn(entity,map,entityInfo))
			return false;
		
		_scene = _entity->getMap()->getScene();

		if(entityInfo->hasAttribute("model"))
			_model = entityInfo->getStringAttribute("model");
		
		_graphicsEntity = createGraphicsEntity(entityInfo);
		if(!_graphicsEntity)
			return false;

		if(entityInfo->hasAttribute("scale")){

			//con el escale puedo escalar lo que quiera cuanto quiera. El mapa ya sale al tamaño que queramos ^^
			_graphicsEntity->setScale(entityInfo->getVector3Attribute("scale"));
			// con esto puedo girar lo que quiera cuanto quiera. Lo he probado con el mapa
		}
		
		//¿queremos material custom?
		/*if(entityInfo->hasAttribute("materialName") && _model == "heavy.mesh"){
			//material type
			std::string materialName = entityInfo->getStringAttribute("materialName");
			_material.push_back(materialName+"HeadBlue");
			_material.push_back(materialName+"EyeLBlue");
			_material.push_back(materialName+"EyeRBlue");
			_material.push_back(materialName+"BodyBlue");
			_material.push_back(materialName+"HandsBlue");

			_graphicsEntity->changeMaterial(_material);
		}else */if (entityInfo->hasAttribute("materialName")){
			_material = entityInfo->getStringAttribute("materialName");
		}

		_lightMask = readLightMask(entityInfo);

		return true;

	} // spawn
コード例 #4
0
	bool CGraphics::OnSpawn(const Map::CEntity *entityInfo)
	{
		_scene = _entity->getMap()->getScene();

		if(entityInfo->hasAttribute("basic_shape"))
		{
			std::string shape = entityInfo->getStringAttribute("basic_shape");
			if(shape.compare("Prefab_Cube") == 0)
			{
				_type = Graphics::PrefabType::PT_CUBE;
				_isPrefab = true;
			}
			else if(shape.compare("Prefab_Sphere") == 0)
			{
				_type = Graphics::PrefabType::PT_SPHERE;
				_isPrefab = true;
			}
			else if(shape.compare("Prefab_Plane") == 0)
			{
				_type = Graphics::PrefabType::PT_PLANE;
				_isPrefab = true;
			}
			else if(shape.compare("Plane") == 0)
			{
				_isPrefab = false;
				std::string _meshName = _entity->getName() + "_Plane";

				//Comprobamos que el plano tenga todos los atributos
				bool requiredAttributes = true;
			    requiredAttributes &= entityInfo->hasAttribute("plane_triangles");
				requiredAttributes &= entityInfo->hasAttribute("plane_width");
				requiredAttributes &= entityInfo->hasAttribute("plane_heigth");
				requiredAttributes &= entityInfo->hasAttribute("plane_normal");
				

				if(requiredAttributes)
				{
					//Obtenemos todos los datos del plano

					//la distancia sobre la normal por defecto es 0
					float _dist = .0f;
					if(entityInfo->hasAttribute("plane_dist"))
					{
						_dist = entityInfo->getFloatAttribute("plane_dist");
					}

					int _nTriangles = entityInfo->getIntAttribute("plane_triangles");
					float _width = entityInfo->getFloatAttribute("plane_width");
					float _heigth = entityInfo->getFloatAttribute("plane_heigth");
					Vector3 _normal = entityInfo->getVector3Attribute("plane_normal");

					Graphics::CServer::getSingletonPtr()->createPlaneMesh(_meshName, _normal, _dist, _width, _heigth, _nTriangles);
				
					_model = _meshName;
				}
				else
				{
					return false; //no podemos construir el meshPlane
				}
				
			}
			
		}
		else if(entityInfo->hasAttribute("model"))
		{
			_model = entityInfo->getStringAttribute("model");
			_isPrefab = false;
		}
		
		_isStatic = false;
		if(entityInfo->hasAttribute("static"))
			_isStatic = entityInfo->getBoolAttribute("static");

		// Si no es nodo se seteará leyendo "false" desde fichero
		if(entityInfo->hasAttribute("needNode"))
		{ 
			_needNode = entityInfo->getBoolAttribute("needNode");
		}

		if(!_isPrefab)
		{
			_graphicsEntity = createGraphicsEntity(entityInfo);
		}
		else
		{
			_graphicsEntity = createPrefabGraphicsEntity(entityInfo);
		}

		if(!_graphicsEntity)
			return false;

		//Seteamos la posicion de la entidad grafica
		_graphicsEntity->setTransform(_entity->getTransform());

		//Seteamos el material en caso de tenerlo
		if(entityInfo->hasAttribute("material"))
		{
			_material = entityInfo->getStringAttribute("material");
			_graphicsEntity->setMaterial(_material);
		}

		//Seteamos la escala en caso de tener
		if(entityInfo->hasAttribute("scale"))
		{
			_scale = entityInfo->getVector3Attribute("scale");
			_graphicsEntity->setScale(_scale);
		}

		//Si existe
		if(_graphicsEntity)
		{
			//La hacemos invisible antes de eliminar el sceneNode y quitarla de la escena
			_graphicsEntity->setVisible(false);
			//Elimino la entidad segun sea estatica o dinamica
			!_isStatic
			?
				_scene->removeEntity(_graphicsEntity)
			:
				_scene->removeStaticEntity((Graphics::CStaticEntity*)_graphicsEntity);

		}

		return true;

	} // spawn