Esempio n. 1
0
CTerrainTile* CTerrainTileRoot::AttachGlobalObject(CBaseObject* obj)
{
	if (obj != NULL)
	{
		m_listSolidObj.push_back(obj);
		// add to map list
		m_namemap[obj->GetIdentifier()] = obj;

		Vector3 vPos = obj->GetPosition();

		// object is always attached to the deepest terrain tile as a point
		// Note:2009.8.26: I used to use ViewCullingObject of obj to attach, but for async-loading, I will use just the object position.
		IGameObject* gameObj = obj->QueryIGameObject();
		CTerrainTile*  pTile = CreateTileByPoint(vPos.x, vPos.z);

		if (gameObj != NULL){
			gameObj->UpdateTileContainer();
			gameObj->On_Attached();
		}
		return obj->GetTileContainer();
	}
	return NULL;
}
Esempio n. 2
0
CTerrainTile* CTerrainTileRoot::AttachLocalObject(CBaseObject* obj)
{
	if (obj == NULL)
		return NULL;
	Vector3 vPos = obj->GetPosition();

	// object is always attached to the deepest terrain tile as a point
	// Note:2009.8.26: I used to use ViewCullingObject of obj to attach, but for async-loading, I will use just the object position.
	IGameObject* gameObj = obj->QueryIGameObject();
	CTerrainTile*  pTile = NULL;
	pTile = CreateTileByPoint(vPos.x, vPos.z);

	if (pTile != NULL)
	{
		if (obj->CheckVolumnField(OBJ_BIG_STATIC_OBJECT))
		{
			float width, height, facing;
			obj->GetBoundRect(&width, &height, &facing);
			if (facing != 0.0f)
			{
				float radius = obj->GetRadius();
				height = width = radius * 2;
			}

			// for big object, we will attach to the best fit terrain tile. 
			pTile = CreateTileByRect(vPos.x, vPos.z, width, height);
		}


		if (obj->CheckVolumnField(OBJ_VOLUMN_FREESPACE))
		{
			//TODO: if the object is already in the tile, it will be deleted and re-attached.
			//pTile->m_listFreespace.remove(obj);
			pTile->m_listFreespace.push_back(obj);
		}
		else
		{
			//TODO: if the object is already in the tile, it will be deleted and re-attached.
			//pTile->m_listSolidObj.remove(obj);
			pTile->m_listSolidObj.push_back(obj);
		}

		if (!obj->GetIdentifier().empty())
		{
			// we add it to the container tile 
			const string& sName = obj->GetIdentifier();
			pTile->m_namemap[sName] = obj;

			// we will also add it to root tile name mapping, if it begins with "g_", "s_"
			if (sName.size()>2 && sName[1] == '_' && (sName[0] == 'g' || sName[0] == 's'))
			{
				m_globalMeshNameMapping[sName] = obj;
			}
		}
		obj->SetTileContainer(pTile);
		if (gameObj != NULL)
		{
			gameObj->On_Attached();
		}
		return pTile;
	}
	else
		return NULL;
}