Esempio n. 1
0
	iTileMapIt *cTileMap::GetRectIterator(const cRectf &a_Rect, int a_lLayer)
	{
		cVector2l vPos = cVector2l((int)floor(a_Rect.x/m_fTileSize),
									(int)floor(a_Rect.y/m_fTileSize));

		cVector2l vSize = cVector2l((int)(a_Rect.w/m_fTileSize)+1,
									(int)(a_Rect.h/m_fTileSize)+1);

		if (a_Rect.x+a_Rect.w>=(vPos.x+vSize.x)*m_fTileSize) vSize.x++;
		if (a_Rect.y+a_Rect.h>=(vPos.y+vSize.y)*m_fTileSize) vSize.y++;

		return efeNew(cTileMapRectIt, (vPos, vSize, this, a_lLayer));
	}
Esempio n. 2
0
	cTileMapLineIt::cTileMapLineIt(cVector2f avStartPos, cVector2f avEndPos, cTileMap* apTileMap, int alLayer)
	{
		mpTileMap = apTileMap;
		mpTile = NULL;

		mvPos = avStartPos;
		
		mlLayer = alLayer;
		mlLayerCount =0;
		mlCurrentLayer = 0;

		mbAtLastTile = false;
		mbAddNext = true;
		
		float fAngle = cMath::GetAngleFromPoints2D(avStartPos, avEndPos);
		float fDist = sqrt(mpTileMap->GetTileSize()*mpTileMap->GetTileSize());

		mvPosAdd = cMath::GetVectorFromAngle2D(fAngle,fDist);
		mvPos = avStartPos;
		
		//Get the current tile
		mvTilePos = cVector2l((int)floor(avStartPos.x/apTileMap->GetTileSize()),
							(int)floor(avStartPos.y/apTileMap->GetTileSize()));
		mlTileNum = mvTilePos.x +mvTilePos.y*mpTileMap->mvSize.x;

		mvEndPos = cVector2l((int)floor(avEndPos.x/apTileMap->GetTileSize()),
							(int)floor(avEndPos.y/apTileMap->GetTileSize()));

		if(mvEndPos == mvTilePos)mbAtLastTile = true;

		
		/*Log("Start: %d %d\n", mvTilePos.x,mvTilePos.y);
		Log("End: %d %d\n", mvEndPos.x,mvEndPos.y);
		Log("End: %f : %f\n",avEndPos.x,avEndPos.y);	
		Log("Pos: %s\n",mvPos.ToString().c_str());
		Log("Add: %s\n",mvPosAdd.ToString().c_str());
		Log("Angle: %f\n\n",(fAngle/k2Pif)*360);
		Log("%f : %f\n", mvPosAdd.x / (avEndPos.x - avStartPos.x), mvPosAdd.y / (avEndPos.y - avStartPos.y));
		Log("-------------\n");*/

		/*Check if the tilepos is outside of the map*/
		if(mvTilePos.x <0 || mvTilePos.y<0 || mvTilePos.x>=mpTileMap->mvSize.x ||
			mvTilePos.y >= mpTileMap->mvSize.y)
		{
			mlLayerCount = (int)mpTileMap->mvTileLayer.size();
		}
		
		mbUpdated = false;
	}
Esempio n. 3
0
iGridMap2DIt* cGridMap2D::GetRectIterator(const cRect2f& aRect)
{
    cVector2l vPos = cVector2l((int)floor(aRect.x/(float)mvGridSize.x),
                               (int)floor(aRect.y/(float)mvGridSize.y));
    cVector2l vSize = cVector2l((int)(aRect.w/(float)mvGridSize.x)+1,
                                (int)(aRect.h/(float)mvGridSize.y)+1);

    //Check if we need yet another grid for x and y
    if(aRect.x+aRect.w>=(vPos.x+vSize.x)*mvGridSize.x)vSize.x++;
    if(aRect.y+aRect.h>=(vPos.y+vSize.y)*mvGridSize.y)vSize.y++;

    //Log("\nPos: %d:%d\n",vPos.x,vPos.y);
    //Log("Size: %d:%d\n\n",vSize.x,vSize.y);

    return hplNew( cGridMap2DRectIt, (this,vPos,vSize) );
}
Esempio n. 4
0
	cRiftHMD::cRiftHMD(cInput* apInput, OVR::HMDDevice* apHMDDevice) : cHMD(apInput)
	{
		mpHMDDevice = apHMDDevice;

		// Framebuffer is 1600 / 1000 split to left and right;
		mvFramebufferDimensions = cVector2l(800, 1000);
		mpSensor = mpHMDDevice->GetSensor();
		mFusion.AttachToSensor(mpSensor);
		Update(0);
	}
Esempio n. 5
0
	cImageManager::cImageManager(cFileSearcher *apFileSearcher,iLowLevelGraphics *apLowLevelGraphics, 
								iLowLevelResources *apLowLevelResources,iLowLevelSystem *apLowLevelSystem)
	: iResourceManager(apFileSearcher, apLowLevelResources,apLowLevelSystem)
	{
       mpLowLevelGraphics = apLowLevelGraphics;

	   mpLowLevelResources->GetSupportedImageFormats(mlstFileFormats);

	   mvFrameSize = cVector2l(512,512);
	   mlFrameHandle = 0;
	}
Esempio n. 6
0
	bool cLight3DSpot::CreateClipRect(cRect2l &aClipRect, cRenderSettings *apRenderSettings,
											iLowLevelGraphics *apLowLevelGraphics)
	{
		cVector2f vScreenSize = apLowLevelGraphics->GetScreenSize();
		bool bVisible = cMath::GetClipRectFromBV(aClipRect,*GetBoundingVolume(),
												apRenderSettings->mpCamera->GetViewMatrix(),
												apRenderSettings->mpCamera->GetProjectionMatrix(),
												apRenderSettings->mpCamera->GetNearClipPlane(),
												cVector2l((int)vScreenSize.x,(int)vScreenSize.y));
		return bVisible;
	}
Esempio n. 7
0
cGrid2DObject::cGrid2DObject(iEntity2D *apEntity,cGridMap2D* apGridMap,unsigned int alHandle)
{
    mpEntity = apEntity;
    mpGridMap = apGridMap;

    mvGridParents.resize(mpGridMap->GetMaxArraySize());
    for(int i=0; i<(int)mvGridParents.size(); i++)
        mvGridParents[i] = NULL;

    mvPosition= cVector2l(-1000);
    mvGridSpan = cVector2l(-1,-1);
    mlHandle = alHandle;

    mbIsInOuter = false;
    mbIsInGLobal = false;
    mlCount =0;

    mpEntity->UpdateBoundingBox();
    Update(mpEntity->GetBoundingBox());
}
Esempio n. 8
0
	cResourceImage *cFrameBitmap::AddBitmap(iBitmap2D *apSrc)
	{
		cResourceImage *pImage=NULL;
		//source size
		//+2 because we are gonna have a border to get rid if some antialiasing problems
		int lSW = apSrc->GetWidth()+2; 
		int lSH = apSrc->GetHeight()+2;
		
		//destination size
		int lDW = mpBitmap->GetWidth();
		int lDH = mpBitmap->GetHeight();

		cVector2l vPos;
		
		bool bFoundEmptyNode = false;
		bool bFoundNode = false;
		//Debug
		int node=0;

		if(DEBUG_BTREE)Log("**** Image %d *****\n",mlPicCount);

		//Get the leaves of the tree and search it for a good pos.
		tRectTreeNodeList lstNodes =  mRects.GetLeafList();
		tRectTreeNodeListIt it;
		for(it = lstNodes.begin();it!=lstNodes.end();++it)
		{
			if(DEBUG_BTREE)Log("Checking node %d:\n",node++);
			tRectTreeNode *TopNode = *it;
			cFBitmapRect* pData = TopNode->GetData();
			
			//Check if the space is free
			if(pData->mlHandle<0)
			{
				if(DEBUG_BTREE)Log("Found free node\n");
				bFoundEmptyNode = true; //An empty node was found.. bitmap not full yet.
				
				//Check if the Image fits in the rect
				cRect2l NewRect = cRect2l(pData->mRect.x,pData->mRect.y,lSW, lSH);
				if(DEBUG_BTREE)Log("Fit: [%d:%d:%d:%d] in [%d:%d:%d:%d]\n",
						NewRect.x,NewRect.y,NewRect.w,NewRect.h,
						pData->mRect.x,pData->mRect.y,pData->mRect.w,pData->mRect.h);
				
				if(cMath::BoxFit(NewRect, pData->mRect))
				{
					if(DEBUG_BTREE)Log("The node fits!\n");
					bFoundNode = true;

                    //If the bitmap fits perfectly add the node without splitting
					if(MinimumFit(NewRect,pData->mRect))
					{
						if(DEBUG_BTREE)Log("Minimum fit!\n");
						pData->mRect = NewRect;
						pData->mlHandle = 1;
					}
					//If there is still space left, make new nodes.
					else
					{
						if(DEBUG_BTREE)Log("Normal fit!\n");
						//Insert 2 children for the top node (lower and upper part.
						tRectTreeNode* UpperNode;
						//Upper
						UpperNode = mRects.InsertAt(cFBitmapRect(NewRect.x,NewRect.y,
													pData->mRect.w,NewRect.h,-2),TopNode,
													eBinTreeNode_Left);
						
						//Lower
						mRects.InsertAt(cFBitmapRect(NewRect.x,NewRect.y+NewRect.h,
										pData->mRect.w,pData->mRect.h-NewRect.h,-3),TopNode,
										eBinTreeNode_Right);

						//Split the Upper Node into 2 nodes.
						pData = UpperNode->GetData();//Get the data for the upper node.
						//Upper split, this is the new bitmap
						mRects.InsertAt(cFBitmapRect(NewRect.x,NewRect.y,
										NewRect.w,NewRect.h,2),UpperNode,
										eBinTreeNode_Left);
						
						//Lower split, this is empty
						mRects.InsertAt(cFBitmapRect(NewRect.x+NewRect.w,NewRect.y,
										pData->mRect.w-NewRect.w,NewRect.h,-4),UpperNode,
										eBinTreeNode_Right);
					}
					
					vPos = cVector2l(NewRect.x+1,NewRect.y+1);//+1 for the right pos		            
					
					//Draw 4 times so we get a nice extra border
					for(int i=0;i<2;i++)for(int j=0;j<2;j++){
						apSrc->DrawToBitmap(mpBitmap,cVector2l(NewRect.x+i*2,NewRect.y+j*2));
					}
					//Fix the border a little more:
					for(int i=-1;i<2;i++)for(int j=-1;j<2;j++)
						if((i==0 || j==0) && (i!=j)){
						apSrc->DrawToBitmap(mpBitmap,cVector2l(NewRect.x+1+i,NewRect.y+1+j));
					}
					//Draw the final
					apSrc->DrawToBitmap(mpBitmap,cVector2l(NewRect.x+1,NewRect.y+1));
					
					
					mlPicCount++;
					mpFrameTexture->SetPicCount(mlPicCount);
					break;
				}
			}
		}

		if(bFoundNode)
		{
			//Create the image resource
			pImage = hplNew( cResourceImage, (apSrc->GetFileName(),mpFrameTexture, this,
				cRect2l(vPos,cVector2l(lSW-2,lSH-2)),//-2 to get the correct size.
				cVector2l(mpBitmap->GetWidth(),mpBitmap->GetHeight()),
				mlHandle) );
			
			if(!bFoundEmptyNode)
			{
				mbIsFull = true;
			}

			mbIsUpdated = true;
		}



		/// LAST DEBUG ///
		if(DEBUG_BTREE)
		{
			Log("Current Tree begin:\n");
			tRectTreeNodeList lstNodes =  mRects.GetNodeList();
			tRectTreeNodeListIt it;
			int node=0;
			for(it = lstNodes.begin();it!=lstNodes.end();++it)
			{
				cRect2l Rect = (*it)->GetData()->mRect;
				int h = (*it)->GetData()->mlHandle;
				Log(" %d: [%d:%d:%d:%d]:%d\n",node,Rect.x,Rect.y,Rect.w,Rect.h,h);
				node++;
			}
			Log("Current Tree end:\n");
			Log("-----------------\n");

			Log("Current Leaves begin:\n");
			lstNodes =  mRects.GetLeafList();
			node=0;
			for(it = lstNodes.begin();it!=lstNodes.end();++it)
			{
				cRect2l Rect = (*it)->GetData()->mRect;
				int h = (*it)->GetData()->mlHandle;
				Log(" %d: [%d:%d:%d:%d]: %d\n",node,Rect.x,Rect.y,Rect.w,Rect.h,h);
				node++;
			}
			Log("Current Tree end:\n");
			Log("-----------------\n");
		}

		
		return pImage;
	}
Esempio n. 9
0
	void cTileMapLineIt::GetTile()
	{
		if(mbUpdated)return;
		mbUpdated = true;

		//We are gonna check till we find a non NULL value or the end.
		while(true)
		{
			//Check if end of the this tile pos
			if( (mlLayer>=0 && mlLayerCount>0) || (mlLayer==-1 && mlLayerCount>= (int)mpTileMap->mvTileLayer.size()) )
			{
				if(mbAtLastTile){
					mpTile = NULL;
					break;
				}
				
				//add pos so we go to the next tile.
				if(mbAddNext)
				{
					mvPos += mvPosAdd;
				
					//Get the current tile
					cVector2l vLastTilePos = mvTilePos;
					mvTilePos =  cVector2l((int)floor(mvPos.x/mpTileMap->GetTileSize()),
										(int)floor(mvPos.y/mpTileMap->GetTileSize()));
					
					//if there has been a change on both x and y then I tile has been missed
					if(mvTilePos.x != vLastTilePos.x && mvTilePos.y != vLastTilePos.y)
					{
						cVector2l vAdd = mvTilePos - vLastTilePos;
						
						//Log("Too big jump!\n");
						cVector2f vIntersectX, vIntersectY;
						cVector2f vOldPos = mvPos - mvPosAdd;
						
						GetXYIntersection(vOldPos,&vIntersectX, &vIntersectY);

						if(cMath::SqrDist2D(vOldPos,vIntersectX) < cMath::SqrDist2D(vOldPos,vIntersectY))
							mvTilePos = cVector2l(vLastTilePos.x, vLastTilePos.y + vAdd.y);
						else
							mvTilePos = cVector2l(vLastTilePos.x + vAdd.x, vLastTilePos.y);
						
						mbAddNext = false;
					}		
				}
				else
				{
					mbAddNext = true;
					mvTilePos =  cVector2l((int)floor(mvPos.x/mpTileMap->GetTileSize()),
						(int)floor(mvPos.y/mpTileMap->GetTileSize()));
				}

				/*Check if the tilepos is outside of the map*/
				if(mvTilePos.x <0 || mvTilePos.y<0 || mvTilePos.x>=mpTileMap->mvSize.x ||
					mvTilePos.y >= mpTileMap->mvSize.y)
				{
					mpTile = NULL;
					Error("Outside of bounds!\n");
					//should just not set mlLayer count to 0. SO that the start can be soutside of the map.
					break;
				}
				else
				{
					mlLayerCount =0;
				}
				
				mlTileNum = mvTilePos.x +mvTilePos.y*mpTileMap->mvSize.x;

				//Log("Next: %d %d\n", mvTilePos.x,mvTilePos.y);
				//Log("Pos: %s\n",mvPos.ToString().c_str());
				
				if(mvTilePos == mvEndPos){
					mbAtLastTile = true;
				}
			}
			else
			{
				if(mlLayer<0){
					mpTile = mpTileMap->mvTileLayer[mlLayerCount]->mvTile[mlTileNum];
					mlCurrentLayer = mlLayerCount;
				}
				else{
					mpTile = mpTileMap->mvTileLayer[mlLayer]->mvTile[mlTileNum];
					mlCurrentLayer = mlLayer;
				}
				
				mlLayerCount++;
                
				if(mpTile!=NULL){
					iTileData* pData = mpTile->GetTileData();
					if(pData && pData->IsSolid()){
						mlLayerCount = (int)mpTileMap->mvTileLayer.size();
					}
					break;
				}
			}
		}
	}
Esempio n. 10
0
	cResourceImage *cFrameBitmap::AddBitmap(iBitmap2D *a_pSrc)
	{
		cResourceImage *pImage=NULL;

		int lSW = a_pSrc->GetWidth()+2;
		int lSH = a_pSrc->GetHeight()+2;

		int lDW = m_pBitmap->GetWidth();
		int lDH = m_pBitmap->GetHeight();

		cVector2l vPos;

		bool bFoundEmptyNode = false;
		bool bFoundNode = false;
		int node=0;

		if (DEBUG_BTREE)Log("**** Image %d ****\n", m_lPicCount);

		tRectTreeNodeList lstNodes = m_Rects.GetLeafList();
		tRectTreeNodeListIt it;
		for (it=lstNodes.begin();it!=lstNodes.end();++it)
		{
			if (DEBUG_BTREE)Log("Checking node %d:\n", node++);
			tRectTreeNode *TopNode = *it;
			cFBitmapRect *pData = TopNode->GetData();

			if (pData->m_lHandle<0)
			{
				if (DEBUG_BTREE)Log("Found tree node\n");
				bFoundEmptyNode = true;

				cRectl NewRect = cRectl(pData->m_Rect.x,pData->m_Rect.y,lSW,lSH);
				if (DEBUG_BTREE)Log("Fit: [%d:%d:%d:%d] in [%d:%d:%d:%d]\n",
					NewRect.x, NewRect.y, NewRect.w, NewRect.h,
					pData->m_Rect.x, pData->m_Rect.y, pData->m_Rect.w, pData->m_Rect.h); 

				if (cMath::BoxFit(NewRect,pData->m_Rect))
				{
					if (DEBUG_BTREE)Log("The node fits!\n");
					bFoundNode = true;

					if (MinimumFit(NewRect,pData->m_Rect))
					{
						if (DEBUG_BTREE)Log("Minimum fit!\n");
						pData->m_Rect = NewRect;
						pData->m_lHandle = 1;
					}
					else
					{
						if (DEBUG_BTREE)Log("Normal fit!\n");
						tRectTreeNode *UpperNode;
						UpperNode = m_Rects.InsertAt(cFBitmapRect(NewRect.x,NewRect.y,
													pData->m_Rect.w,NewRect.h,-2),TopNode,
													eBinTreeNode_Left);

						m_Rects.InsertAt(cFBitmapRect(NewRect.x,NewRect.y+NewRect.h,
										pData->m_Rect.w,pData->m_Rect.h-NewRect.h,-3),TopNode,
										eBinTreeNode_Right);

						pData = UpperNode->GetData();

						m_Rects.InsertAt(cFBitmapRect(NewRect.x,NewRect.y,
										NewRect.w,NewRect.h,2),UpperNode,
										eBinTreeNode_Left);

						m_Rects.InsertAt(cFBitmapRect(NewRect.x+NewRect.w,NewRect.y,
										pData->m_Rect.w-NewRect.w,NewRect.h,-4),UpperNode,
										eBinTreeNode_Right);
					}

					vPos = cVector2l(NewRect.x+1,NewRect.y+1);

					for (int i=0;i<2;i++) for (int j=0;j<2;j++)
					{
						a_pSrc->DrawToBitmap(m_pBitmap, cVector2l(NewRect.x+i*2, NewRect.y+j*2));
					}

					for (int i=0;i<2;i++)
					{
						for (int j=0;j<2;j++)
							if ((i==0 || j==0) && (i!=j))
								a_pSrc->DrawToBitmap(m_pBitmap,cVector2l(NewRect.x+1+i, NewRect.y+1+j));
					}
					a_pSrc->DrawToBitmap(m_pBitmap,cVector2l(NewRect.x+1,NewRect.y+1));

					m_lPicCount++;
					m_pFrameTexture->SetPicCount(m_lPicCount);
					break;
				}
			}
		}

		if (bFoundNode)
		{
			pImage = efeNew(cResourceImage, (a_pSrc->GetFileName(),m_pFrameTexture,this,
				cRectl(vPos,cVector2l(lSW-2,lSH-2)),
				cVector2l(m_pBitmap->GetWidth(),m_pBitmap->GetHeight()),
				m_lHandle));

			if (!bFoundEmptyNode)
				m_bIsFull = true;

			m_bIsUpdated = true;
		}

		if (DEBUG_BTREE)
		{
			Log("Current Tree begin:\n");
			tRectTreeNodeList lstNodes = m_Rects.GetNodeList();
			tRectTreeNodeListIt it;
			int node=0;
			for (it=lstNodes.begin();it!=lstNodes.end();++it)
			{
				cRectl Rect = (*it)->GetData()->m_Rect;
				int h = (*it)->GetData()->m_lHandle;
				Log(" %d: [%d:%d:%d:%d]:%d\n",node,Rect.x,Rect.y,Rect.w,Rect.h,h);
				node++;
			}
			Log("Current Tree end:\n");
			Log("-----------------\n");

			Log("Current Leaves begin:\n");
			lstNodes = m_Rects.GetLeafList();
			node=0;
			for(it=lstNodes.begin();it!=lstNodes.end();++it);
			{
				cRectl Rect = (*it)->GetData()->m_Rect;
				int h = (*it)->GetData()->m_lHandle;
				Log(" %d: [%d:%d:%d:%d]:%d\n",node,Rect.x,Rect.y,Rect.w,Rect.h,h);
				node++;
			}
			Log("Current Tree end:\n");
			Log("-----------------\n");
		}

		return pImage;
	}