コード例 #1
0
ファイル: wxledpanel.cpp プロジェクト: DowerChest/codeblocks
void wxLEDPanel::SetText(const wxString& text, int align)
{
	// String emtpy
	if(text.IsEmpty()) return;

	// the MO for the Text
	MatrixObject* tmp=NULL;

	// save the align
	if(align!=-1) m_align=align;

	// save the string
	m_text=text;
	m_aniFrameNr=-1;

	// get the MO for the text
	if(m_align&wxALIGN_CENTER_HORIZONTAL)
		tmp=m_font.GetMOForText(text,wxALIGN_CENTER_HORIZONTAL);
	else if(m_align&wxALIGN_RIGHT)
		tmp=m_font.GetMOForText(text,wxALIGN_RIGHT);
	else tmp=m_font.GetMOForText(text);	// wxALIGN_LEFT

	// save the MO, and delete the tmp
	m_content_mo.Init(*tmp);
	delete tmp;

	// Find the place for the text
	ResetPos();

	// Set in field
	m_field.Clear();
	m_field.SetDatesAt(m_pos,m_content_mo);
}
コード例 #2
0
void CGrassDrawer::UnsyncedHeightMapUpdate(const SRectangle& rect)
{
	for (int z = rect.z1; z <= rect.z2; ++z) {
		for (int x = rect.x1; x <= rect.x2; ++x) {
			ResetPos(float3(x, 0.f, z));
		}
	}
}
コード例 #3
0
void CBasicTreeDrawer::DeleteTree(float3 pos)
{
	int hash=(int)pos.x+((int)(pos.z))*20000;
	int square=((int)pos.x)/(SQUARE_SIZE*TREE_SQUARE_SIZE)+((int)pos.z)/(SQUARE_SIZE*TREE_SQUARE_SIZE)*treesX;

	trees[square].trees.erase(hash);

	ResetPos(pos);
}
コード例 #4
0
ファイル: MarkupSTL.cpp プロジェクト: Avoidnf8/xbmc-fork
bool CMarkupSTL::SetDoc( const char * szDoc )
{
	// Reset indexes
	m_iPosFree = 1;
	ResetPos();
	m_mapSavedPos.clear();

	// Set document text
	if ( szDoc )
		m_csDoc = szDoc;
	else
		m_csDoc.Empty();

	// Starting size of position array: 1 element per 64 bytes of document
	// Tight fit when parsing small doc, only 0 to 2 reallocs when parsing large doc
	// Start at 8 when creating new document
	UINT nStartSize = m_csDoc.GetLength() / 64 + 8;
	if ( m_aPos.size() < nStartSize )
		m_aPos.resize( nStartSize );

	// Parse document
	bool bWellFormed = false;
	if ( m_csDoc.GetLength() )
	{
		m_aPos[0].Clear();
		int iPos = x_ParseElem( 0 );
		if ( iPos > 0 )
		{
			m_aPos[0].iElemChild = iPos;
			bWellFormed = true;
		}
	}

	// Clear indexes if parse failed or empty document
	if ( ! bWellFormed )
	{
		m_aPos[0].Clear();
		m_iPosFree = 1;
	}

	ResetPos();
	return bWellFormed;
};
コード例 #5
0
void CBasicTreeDrawer::AddTree(int type, float3 pos, float size)
{
	TreeStruct ts;
	ts.pos=pos;
	ts.type=type;
	int hash=(int)pos.x+((int)(pos.z))*20000;
	int square=((int)pos.x)/(SQUARE_SIZE*TREE_SQUARE_SIZE)+((int)pos.z)/(SQUARE_SIZE*TREE_SQUARE_SIZE)*treesX;
	trees[square].trees[hash]=ts;
	ResetPos(pos);
}
コード例 #6
0
void CBasicTreeDrawer::DeleteTree(int treeID, const float3& pos)
{
	const int treeSquareSize = SQUARE_SIZE * TREE_SQUARE_SIZE;
	const int treeSquareIdx =
		(((int)pos.x) / (treeSquareSize)) +
		(((int)pos.z) / (treeSquareSize) * treesX);

	trees[treeSquareIdx].trees.erase(treeID);

	ResetPos(pos);
}
コード例 #7
0
void CAdvTreeDrawer::DeleteTree(float3 pos)
{
	GML_STDMUTEX_LOCK(tree); // DeleteTree

	int hash=(int)pos.x+((int)(pos.z))*20000;
	int square=((int)pos.x)/(SQUARE_SIZE*TREE_SQUARE_SIZE)+((int)pos.z)/(SQUARE_SIZE*TREE_SQUARE_SIZE)*treesX;

	trees[square].trees.erase(hash);

	ResetPos(pos);
}
コード例 #8
0
ファイル: wxledpanel.cpp プロジェクト: DowerChest/codeblocks
void wxLEDPanel::SetContentAlign(int a)
{
	// save value
	m_align=a;

	// Reset the Horizontal position
	ResetPos();

	// Reinit the field
	m_field.Clear();
	m_field.SetDatesAt(m_pos,m_content_mo);
}
コード例 #9
0
ファイル: wxledpanel.cpp プロジェクト: DowerChest/codeblocks
void wxLEDPanel::SetContentPaddingRight(int padRight)
{
	// Save the Value
	m_padRight=padRight;

	// Reset the text position
	ResetPos();

	// Reinit the field
	m_field.Clear();
	m_field.SetDatesAt(m_pos,m_content_mo);
}
コード例 #10
0
void CAdvTreeDrawer::DeleteTree(const float3& pos)
{
	GML_STDMUTEX_LOCK(tree); // DeleteTree

	const int hash = (int)pos.x + ((int)pos.z * 20000);
	const int square =
		((int)pos.x / (SQUARE_SIZE * TREE_SQUARE_SIZE)) +
		((int)pos.z / (SQUARE_SIZE * TREE_SQUARE_SIZE) * treesX);

	trees[square].trees.erase(hash);

	ResetPos(pos);
}
コード例 #11
0
ファイル: GrassDrawer.cpp プロジェクト: nixtux/spring
void CGrassDrawer::AddGrass(const float3& pos)
{
	if (grassOff)
		return;

	const int x = int(pos.x) / GSSSQ;
	const int z = int(pos.z) / GSSSQ;
	assert(x >= 0 && x < (mapDims.mapx / grassSquareSize));
	assert(z >= 0 && z < (mapDims.mapy / grassSquareSize));

	grassMap[z * mapDims.mapx / grassSquareSize + x] = 1;
	ResetPos(pos);
}
コード例 #12
0
void CGrassDrawer::RemoveGrass(const float3& pos)
{
	if (grassOff)
		return;

	const int x = int(pos.x) / (SQUARE_SIZE * grassSquareSize);
	const int z = int(pos.z) / (SQUARE_SIZE * grassSquareSize);
	assert(x >= 0 && x < (mapDims.mapx / grassSquareSize));
	assert(z >= 0 && z < (mapDims.mapy / grassSquareSize));

	grassMap[z * mapDims.mapx / grassSquareSize + x] = 0;
	ResetPos(pos);
}
コード例 #13
0
ファイル: AdvTreeDrawer.cpp プロジェクト: BrainDamage/spring
void CAdvTreeDrawer::AddTree(int type, float3 pos, float size)
{
	GML_STDMUTEX_LOCK(tree); // AddTree

	TreeStruct ts;
	ts.pos = pos;
	ts.type = type;
	const int hash = (int)pos.x + ((int)(pos.z)) * 20000;
	const int square =
		((int)pos.x) / (SQUARE_SIZE * TREE_SQUARE_SIZE) +
		((int)pos.z) / (SQUARE_SIZE * TREE_SQUARE_SIZE) * treesX;
	trees[square].trees[hash] = ts;
	ResetPos(pos);
}
コード例 #14
0
ファイル: wxledpanel.cpp プロジェクト: DowerChest/codeblocks
void wxLEDPanel::SetImage(const wxImage img)
{
    if(!img.IsOk()) return;
    m_text.Empty();

    m_content_mo.Init(img);
    m_aniFrameNr=-1;

    // Find the place for the bitmap
	ResetPos();

	// Set in field
	m_field.Clear();
	m_field.SetDatesAt(m_pos,m_content_mo);
}
コード例 #15
0
void CBasicTreeDrawer::AddTree(int treeID, int treeType, const float3& pos, float size)
{
	TreeStruct ts;

	ts.id = treeID;
	ts.type = treeType;
	ts.pos = pos;

	const int treeSquareSize = SQUARE_SIZE * TREE_SQUARE_SIZE;
	const int treeSquareIdx =
		(((int)pos.x) / (treeSquareSize)) +
		(((int)pos.z) / (treeSquareSize) * treesX);

	trees[treeSquareIdx].trees[treeID] = ts;
	ResetPos(pos);
}
コード例 #16
0
void CHexEdit::OnEditPaste() 
{
	COleDataObject	obj;	
	if (obj.AttachClipboard()) 
	{
		HGLOBAL hmem = NULL;
		if (obj.IsDataAvailable(RegisterClipboardFormat("BinaryData"))) 
		{
			hmem = obj.GetGlobalData(RegisterClipboardFormat("BinaryData"));
		}	
		else if (obj.IsDataAvailable(CF_TEXT)) 
		{
			hmem = obj.GetGlobalData(CF_TEXT);
		}
		if(hmem)
		{
			LPBYTE	p = (BYTE*)::GlobalLock(hmem);
			DWORD	dwSizeMem=::GlobalSize(hmem);
			DWORD	dwSizeSel=GetSelLength();
			DWORD	dwLen =dwSizeMem>dwSizeSel?dwSizeSel:dwSizeMem;
			int		insert;
			
			NormalizeSel();
			if(m_selStart == 0xffffffff)
			{
				if(m_currentMode == EDIT_LOW)
					m_currentAddress++;
				insert = m_currentAddress;
				SelInsert(m_currentAddress, dwLen);
			}
			else
			{
				insert = m_selStart;
				SelDelete(m_selStart,m_selStart+dwLen-1);
				SelInsert(insert, dwLen);
			}
			memcpy(m_pData+insert, p, dwLen);
			
			m_currentAddress = insert+dwLen;
//			RepositionCaret(m_currentAddress);
			ResetPos();
			Invalidate(FALSE);
			::GlobalUnlock(hmem);
		}
	}
}
コード例 #17
0
ファイル: GrassDrawer.cpp プロジェクト: nixtux/spring
void CGrassDrawer::Update()
{
	// grass is never drawn in any special (non-opaque) pass
	const CCamera* cam = CCamera::GetCamera(CCamera::CAMTYPE_PLAYER);

	// update visible turfs
	updateVisibility |= (oldCamPos != cam->GetPos());
	updateVisibility |= (oldCamDir != cam->GetDir());

	if (updateVisibility) {
		SCOPED_TIMER("Update::Update::Grass");
		oldCamPos = cam->GetPos();
		oldCamDir = cam->GetDir();
		lastVisibilityUpdate = globalRendering->drawFrame;

		blockDrawer.ResetState();
		blockDrawer.cx = int(cam->GetPos().x / BMSSQ);
		blockDrawer.cy = int(cam->GetPos().z / BMSSQ);
		blockDrawer.gd = this;
		readMap->GridVisibility(nullptr, &blockDrawer, maxGrassDist, blockMapSize);

		// ATI crashes w/o an error when shadows are enabled!?
		static const bool shaders = globalRendering->haveGLSL;
		       const bool shadows = (shadowHandler->ShadowsLoaded() && globalRendering->atiHacks);

		if (shaders && !shadows) {
			std::sort(blockDrawer.inviewFarGrass.begin(), blockDrawer.inviewFarGrass.end(), GrassSort);
			std::sort(blockDrawer.inviewNearGrass.begin(), blockDrawer.inviewNearGrass.end(), GrassSortNear);
			farnearVA.Initialize();
			updateBillboards = true;
		}

		updateVisibility = false;
	}

	// collect garbage
	//   originally, this deleted the billboard VA of any patch that was not drawn for 50 frames
	//   now it only resets lastFar s.t. patches are forcibly recreated when they become visible
	//   again (reusing memory)
	//   pass negative coordinates since we do not want to set updateVisibility during this step
	for (const GrassStruct& gs: grass) {
		if ((gs.lastSeen != lastVisibilityUpdate) && (gs.lastSeen < globalRendering->drawFrame - 50) && gs.lastFar != 0) {
			ResetPos(-gs.posX, -gs.posZ);
		}
	}
}
コード例 #18
0
void CGrassDrawer::ChangeDetail(int detail) {
	// TODO: get rid of the magic constants
	const int detail_lim = std::min(3, detail);
	maxGrassDist = 800 + std::sqrt((float) detail) * 240;
	maxDetailedDist = 146 + detail * 24;
	detailedBlocks = int((maxDetailedDist + 128.f * 1.5f) / bMSsq) + 1;
	numTurfs = 3 + int(detail_lim * 0.5f);
	strawPerTurf = std::min(50 + int(std::sqrt((float)detail_lim) * 10), mapInfo->grass.maxStrawsPerTurf);

	// recreate textures & XBOs
	CreateGrassDispList(grassDL);
	CreateFarTex();

	// reset  all cached blocks
	for (GrassStruct& pGS: grass) {
		ResetPos(pGS.posX, pGS.posZ);
	}
}
コード例 #19
0
ファイル: wxledpanel.cpp プロジェクト: DowerChest/codeblocks
void wxLEDPanel::SetAnimation(const wxAnimation ani)
{
    if(!ani.IsOk() || ani.GetFrameCount()==0) return;

    m_ani = ani;
    m_text.Empty();
    m_aniFrameNr = 0;

    m_content_mo.Init(ani.GetFrame(0));

    // Find the place for the bitmap
	ResetPos();

	// Set in field
	m_field.Clear();
	m_field.SetDatesAt(m_pos,m_content_mo);

	// start timer
	m_scrollTimer.Stop();
	m_scrollspeed = m_ani.GetDelay(0);
	m_scrollTimer.Start(m_scrollspeed,true);
}
コード例 #20
0
ファイル: GrassDrawer.cpp プロジェクト: 304471720/spring
void CGrassDrawer::Update()
{
	// update visible turfs
	if (oldCamPos != camera->GetPos() || oldCamDir != camera->forward) {
		SCOPED_TIMER("Grass::Update");
		oldCamPos = camera->GetPos();
		oldCamDir = camera->forward;
		lastVisibilityUpdate = globalRendering->drawFrame;

		drawer.cx = int(camera->GetPos().x / bMSsq);
		drawer.cy = int(camera->GetPos().z / bMSsq);
		drawer.inviewGrass.clear();
		drawer.inviewFarGrass.clear();
		drawer.inviewNearGrass.clear();
		drawer.gd = this;
		readMap->GridVisibility(camera, blockMapSize, maxGrassDist, &drawer);

		if (
			globalRendering->haveGLSL
			&& (!shadowHandler->shadowsLoaded || !globalRendering->atiHacks) // Ati crashes w/o an error when shadows are enabled!?
		) {
			std::sort(drawer.inviewFarGrass.begin(), drawer.inviewFarGrass.end(), GrassSort);
			std::sort(drawer.inviewNearGrass.begin(), drawer.inviewNearGrass.end(), GrassSortNear);
			farnearVA->Initialize();
			updateBillboards = true;
		}
	}

	// collect garbage
	for (GrassStruct& pGS: grass) {
		if ((pGS.lastSeen != lastVisibilityUpdate)
		 && (pGS.lastSeen  < globalRendering->drawFrame - 50)
		 && pGS.va
		) {
			ResetPos(pGS.posX, pGS.posZ);
		}
	}
}
コード例 #21
0
ファイル: Allocator.cpp プロジェクト: Robograde/Robograde
	void Initialize( )
	{
		memset( (void*) Memory, 0, MEMORY_SIZE );
		ResetPos( );
	}
コード例 #22
0
ファイル: GrassDrawer.cpp プロジェクト: nixtux/spring
void CGrassDrawer::ResetPos(const float3& pos)
{
	ResetPos(pos.x / BMSSQ, pos.z / BMSSQ);
}
コード例 #23
0
void ClassDemoApp::UpdateAndRender() {
	while (SDL_PollEvent(&event)) {
		if (event.type == SDL_QUIT || event.type == SDL_WINDOWEVENT_CLOSE) {
			done = true;
		}
		else if (false && event.type == SDL_MOUSEBUTTONDOWN && state == PlayingLevel) {	//debugging - moves player(s) to cursor
			if (event.button.button == SDL_BUTTON_LEFT) {
				if (!includePlayer2) {
					player->x += (event.button.x / WINDOW_WIDTH - 0.5f) * PROJECTION_WIDTH * 2;
					player->y -= (event.button.y / WINDOW_HEIGHT - 0.5f) * PROJECTION_HEIGHT * 2;
					player->velocity_y = 0;
				}
				else {
					player->x = (player->x + player2->x) / 2 + (event.button.x / WINDOW_WIDTH - 0.5f) * PROJECTION_WIDTH * 2;
					player->y = (player->y + player2->y) / 2 - (event.button.y / WINDOW_HEIGHT - 0.5f) * PROJECTION_HEIGHT * 2;
					player->velocity_y = 0;
				}
			}
			else if (event.button.button == SDL_BUTTON_RIGHT) {
				if (includePlayer2) {
					player2->x = (player->x + player2->x) / 2 + (event.button.x / WINDOW_WIDTH - 0.5f) * PROJECTION_WIDTH * 2;
					player2->y = (player->y + player2->y) / 2 - (event.button.y / WINDOW_HEIGHT - 0.5f) * PROJECTION_HEIGHT * 2;
					player2->velocity_y = 0;
				}
			}
		}
		else if (event.type == SDL_KEYDOWN) {
			if (event.key.keysym.scancode == SDL_SCANCODE_R) {
				infoBoxTimer = 8;
				ResetPos();
			}
			else {
				infoBoxTimer *= 0.05f;
				if (!includePlayer2 && (event.key.keysym.scancode == controls[1]->UP ||
					event.key.keysym.scancode == controls[1]->DOWN ||
					event.key.keysym.scancode == controls[1]->LEFT ||
					event.key.keysym.scancode == controls[1]->RIGHT ||
					event.key.keysym.scancode == controls[1]->EXTEND)) {
					includePlayer2 = true;
					entities.push_back(player2);
				}
			}
		}
	}

	float ticks = (float)SDL_GetTicks() / 1000.0f;
	float elapsed = ticks - lastElapsedTime;
	lastElapsedTime = ticks;

	float fixedElapsed = elapsed;
	if (fixedElapsed > FIXED_TIMESTEP * MAX_TIMESTEP)
		fixedElapsed = FIXED_TIMESTEP * MAX_TIMESTEP;
	while (fixedElapsed > FIXED_TIMESTEP) {
		fixedElapsed -= FIXED_TIMESTEP;
		Update(FIXED_TIMESTEP);
	}
	Update(fixedElapsed);

	infoBoxTimer -= elapsed;
	movingColor += elapsed * 0.3f;
	Render();
}
コード例 #24
0
void ClassDemoApp::Update(float elapsed) {
	const Uint8 *keys = SDL_GetKeyboardState(NULL);

	for (int i = 0; i < 2; i++) {
		//Player control
		if (keys[controls[i]->EXTEND]) {
			if (keys[controls[i]->UP]) {
				if (!players[i]->collidedTop) {
					float oldHeight = players[i]->height;
					players[i]->height = lerp(players[i]->height, 5 * BOX_SIZE, 0.03f);
					players[i]->y += (players[i]->height - oldHeight) / 2;
				}
				float oldWidth = players[i]->width;
				players[i]->width = lerp(players[i]->width, BOX_SIZE, 0.06f);
				players[i]->x += players[i]->lastDirectionX * (players[i]->width - oldWidth) / 2;
			}
			else if (keys[controls[i]->DOWN]) {
				if (!players[i]->collidedBottom) {
					float oldHeight = players[i]->height;
					players[i]->height = lerp(players[i]->height, 5 * BOX_SIZE, 0.03f);
					players[i]->y -= (players[i]->height - oldHeight) / 2;
				}
				float oldWidth = players[i]->width;
				players[i]->width = lerp(players[i]->width, BOX_SIZE, 0.06f);
				players[i]->x += players[i]->lastDirectionX * (players[i]->width - oldWidth) / 2;
			}
			else if (keys[controls[i]->LEFT]) {
				if (!players[i]->collidedLeft) {
					float oldWidth = players[i]->width;
					players[i]->width = lerp(players[i]->width, 5 * BOX_SIZE, 0.02f);
					players[i]->x -= (players[i]->width - oldWidth) / 2;
					players[i]->lastDirectionX = 1;
				}
				float oldHeight = players[i]->height;
				players[i]->height = lerp(players[i]->height, BOX_SIZE, 0.04f);
				players[i]->y += (oldHeight - players[i]->height) / 2;
				players[i]->velocity_y += (oldHeight - players[i]->height) * 3.4f;
			}
			else if (keys[controls[i]->RIGHT]) {
				if (!players[i]->collidedRight) {
					float oldWidth = players[i]->width;
					players[i]->width = lerp(players[i]->width, 5 * BOX_SIZE, 0.02f);
					players[i]->x += (players[i]->width - oldWidth) / 2;
					players[i]->lastDirectionX = -1;
				}
				float oldHeight = players[i]->height;
				players[i]->height = lerp(players[i]->height, BOX_SIZE, 0.04f);
				players[i]->y += (oldHeight - players[i]->height) / 2;
				players[i]->velocity_y += (oldHeight - players[i]->height) * 3.4f;
			}
			else {
				float oldWidth = players[i]->width;
				players[i]->width = lerp(players[i]->width, BOX_SIZE, 0.003f);
				players[i]->x += players[i]->lastDirectionX * (players[i]->width - oldWidth) / 2;
				float oldHeight = players[i]->height;
				players[i]->height = lerp(players[i]->height, BOX_SIZE, 0.006f);
				players[i]->y += (oldHeight - players[i]->height) / 2;
				players[i]->velocity_y += (oldHeight - players[i]->height) * 3.4f;
			}
			players[i]->acceleration_x = 0;
		}
		else {
			if (keys[controls[i]->UP]) {
				float oldHeight = players[i]->height;
				players[i]->height = lerp(players[i]->height, BOX_SIZE, 0.08f);
				players[i]->y += (oldHeight - players[i]->height) / 2;
				players[i]->velocity_y += (oldHeight - players[i]->height) * 3.6f;
			}
			else if (keys[controls[i]->DOWN]) {
				float oldHeight = players[i]->height;
				players[i]->height = lerp(players[i]->height, BOX_SIZE, 0.06f);
				players[i]->y -= (oldHeight - players[i]->height) / 2;
			}
			else {
				float oldHeight = players[i]->height;
				players[i]->height = lerp(players[i]->height, BOX_SIZE, 0.04f);
				players[i]->y += (oldHeight - players[i]->height) / 2;
				players[i]->velocity_y += (oldHeight - players[i]->height);
			}
			if (keys[controls[i]->LEFT]) {
				players[i]->acceleration_x = -0.2f;
				float oldWidth = players[i]->width;
				players[i]->width = lerp(players[i]->width, BOX_SIZE, 0.09f);
				players[i]->x -= (oldWidth - players[i]->width) / 2;
				players[i]->velocity_x -= (oldWidth - players[i]->width) * 1.4f;
			}
			else if (keys[controls[i]->RIGHT]) {
				players[i]->acceleration_x = 0.2f;
				float oldWidth = players[i]->width;
				players[i]->width = lerp(players[i]->width, BOX_SIZE, 0.09f);
				players[i]->x += (oldWidth - players[i]->width) / 2;
				players[i]->velocity_x += (oldWidth - players[i]->width) * 1.4f;
			}
			else {
				float oldWidth = players[i]->width;
				players[i]->width = lerp(players[i]->width, BOX_SIZE, 0.04f);
				players[i]->x += players[i]->lastDirectionX * (players[i]->width - oldWidth) / 2;
				players[i]->acceleration_x = 0;
			}
		}
	}

	flag1 = false;
	flag2 = false;
	flag3 = false;
	//Global entities update
	for (size_t i = 0; i < entities.size(); i++) {
		if (!entities[i]->isStatic) {
			//Update acceleration and velocities of entities
			entities[i]->Update(elapsed);

			int gridX = 0, gridY = 0;
			worldToTileCoordinates(entities[i]->x, entities[i]->y, gridX, gridY);
			if (gridX == 5 && gridY == -6) {
				flag1 = true;
			}
			if ((gridX == 9 || gridX == 10) &&
				(gridY == -6 || gridY == -7)) {
				flag2 = true;
			}
			if (gridX == 16 && gridY == -7) {
				flag3 = true;
			}
			if ((gridX == 14 || gridX == 15) &&
				(gridY == -23 || gridY == -24)) {
				ResetPos();
			}

			for (size_t j = 0; j < entities.size(); j++) {
				if (j != i && entities[i]->CollidesWith(entities[j])) {
					if (entities[i]->entityType == Entity::ENTITY_PLAYER) {
						float xDiff = entities[i]->x - entities[j]->x;
						float yDiff = entities[i]->y - entities[j]->y;
						float topPen = (entities[j]->y + entities[j]->height / 2) - (entities[i]->y - entities[i]->height / 2);
						float bottomPen = (entities[i]->y + entities[i]->height / 2) - (entities[j]->y - entities[j]->height / 2);
						float leftPen = (entities[j]->x + entities[j]->width / 2) - (entities[i]->x - entities[i]->width / 2);
						float rightPen = (entities[i]->x + entities[i]->width / 2) - (entities[j]->x - entities[j]->width / 2);

						if (std::max(leftPen, rightPen) / (entities[i]->width + entities[j]->width) > std::max(topPen, bottomPen) / (entities[i]->height + entities[j]->height)) {
							//Horizontial collision : this condition indicates that entityI is to a side of entityJ
							entities[i]->velocity_x = (entities[i]->velocity_x + entities[j]->velocity_x) / 2;
							entities[j]->velocity_x = entities[i]->velocity_x;
							bool collisionLR = entities[i]->entityType == Entity::ENTITY_PLAYER &&
								((entities[i] == players[0] && keys[controls[0]->EXTEND] && (keys[controls[0]->LEFT] || keys[controls[0]->RIGHT])) ||
								(entities[i] == players[1] && keys[controls[1]->EXTEND] && (keys[controls[1]->LEFT] || keys[controls[1]->RIGHT])));

							if (xDiff > 0) {	//J <- I
								if (!entities[j]->collidedLeft && collisionLR) {
									entities[j]->x = entities[i]->x - entities[i]->width / 2 - entities[j]->width / 2;
								}
								else {
									entities[i]->x = entities[j]->x + entities[j]->width / 2 + entities[i]->width / 2;
									entities[i]->collidedLeft = true; entities[j]->collidedRight = true;
								}
							}
							else if (xDiff < 0) {
								if (!entities[j]->collidedRight && collisionLR) {
									entities[j]->x = entities[i]->x + entities[i]->width / 2 + entities[j]->width / 2;
								}
								else {
									entities[i]->x = entities[j]->x - entities[j]->width / 2 - entities[i]->width / 2;
									entities[i]->collidedRight = true; entities[j]->collidedLeft = true;
								}
							}
						}
						else {
							if (yDiff > 0) {	//I is on top
								entities[i]->y = entities[j]->y + entities[j]->height / 2 + entities[i]->height / 2;
								entities[j]->velocity_y = (entities[j]->velocity_y + entities[j]->velocity_y) / 2;
								entities[i]->collidedBottom = true; entities[j]->collidedTop = true;
								entities[i]->velocity_y = 0;
							}
							else if (yDiff < 0) {	//J is on top
								entities[j]->y = entities[i]->y + entities[i]->height / 2 + entities[j]->height / 2;
								if (!(entities[i]->entityType == Entity::ENTITY_PLAYER && !entities[j]->collidedTop &&
									((entities[i] == players[0] && keys[controls[0]->EXTEND] && keys[controls[0]->UP]) ||
									(entities[i] == players[1] && keys[controls[1]->EXTEND] && keys[controls[1]->UP])))) {
									entities[i]->collidedTop = true; entities[j]->collidedBottom = true;
								}
								entities[j]->velocity_y = 0;
							}

						}
					}
				}
			}

			//Perform Y calculations and collision with world map
			entities[i]->y += entities[i]->velocity_y * elapsed;
			for (int w = 0; w < 5; w++) {
				worldToTileCoordinates(entities[i]->x + ((float)w - 2) / 5.0f * entities[i]->width, entities[i]->y - entities[i]->height / 2, gridX, gridY);
				if (levelData[-gridY][gridX] != NO_TILE) {
					entities[i]->y = gridY * TILE_SIZE + entities[i]->height / 2 + 0.000001f;
					entities[i]->velocity_y = 0;
					entities[i]->collidedBottom = true;
					entities[i]->spawnX = gridX;
					entities[i]->spawnY = gridY;
				}
				worldToTileCoordinates(entities[i]->x + ((float)w - 2) / 5.0f * entities[i]->width, entities[i]->y + entities[i]->height / 2, gridX, gridY);
				if (levelData[-gridY][gridX] != NO_TILE) {
					entities[i]->y = (gridY - 1) * TILE_SIZE - entities[i]->height / 2 - 0.000001f;
					if (entities[i]->velocity_y > 0)
						entities[i]->velocity_y = 0;
					entities[i]->collidedTop = true;
				}
			}

			//Perform X calculations and collision with world map
			entities[i]->x += entities[i]->velocity_x * elapsed;
			for (int h = 0; h < 5; h++) {
				worldToTileCoordinates(entities[i]->x - entities[i]->width / 2, entities[i]->y + ((float)h - 2) / 5.0f * entities[i]->height, gridX, gridY);
				if (levelData[-gridY][gridX] != NO_TILE) {
					entities[i]->x = (gridX + 1) * TILE_SIZE + entities[i]->width / 2 - 0.000001f;
					entities[i]->velocity_x = 0;
					entities[i]->collidedLeft = true;
				}
				worldToTileCoordinates(entities[i]->x + entities[i]->width / 2, entities[i]->y + ((float)h - 2) / 5.0f * entities[i]->height, gridX, gridY);
				if (levelData[-gridY][gridX] != NO_TILE) {
					entities[i]->x = gridX * TILE_SIZE - entities[i]->width / 2 + 0.0000001f;
					entities[i]->velocity_x = 0;
					entities[i]->collidedRight = true;
				}
			}

			//Downward Bound Reset for player
			if (entities[i]->y - entities[i]->height / 2 < TILE_SIZE * (-LEVEL_HEIGHT + 0.5f)) {
				if (entities[i]->entityType == entities[i]->ENTITY_PLAYER) {
					entities[i]->width = TILE_SIZE;
					entities[i]->height = TILE_SIZE;
				}
				entities[i]->y = TILE_SIZE * entities[i]->spawnY + entities[i]->height / 2;
				entities[i]->x = TILE_SIZE * entities[i]->spawnX + entities[i]->width / 2;
				entities[i]->velocity_y = 0;
			}
		}
	}

	if (flag1 && flag2 && flag3) {
		levelData[6][20] = 255;
	}
	else {
		levelData[6][20] = 2;
	}

	GLint lightPositionsUniform = glGetUniformLocation(program->programID, "lightPositions");
	GLfloat lightPositions[2 * 2 * 4];

	float xDiff = player->x - player2->x;
	float yDiff = player->y - player2->y;
	float scale = 1.0f;
	if (fabs(xDiff) * 0.8f > fabs(yDiff) * 1.4f) {
		if (fabs(xDiff) > PROJECTION_WIDTH * 1.4f) {
			scale = PROJECTION_WIDTH * 1.4f / fabs(xDiff);
		}
	}
	else if (fabs(yDiff) > PROJECTION_WIDTH * 0.8f) {
		scale = PROJECTION_WIDTH * 0.8f / fabs(yDiff);
	}

	for (int i = 0; i < 2; i++) {
		if (!includePlayer2) {
			lightPositions[i * 8] = -players[i]->width / 2;
			lightPositions[i * 8 + 1] = -players[i]->height / 2;
			lightPositions[i * 8 + 2] = players[i]->width / 2;
			lightPositions[i * 8 + 3] = -players[i]->height / 2;
			lightPositions[i * 8 + 4] = -players[i]->width / 2;
			lightPositions[i * 8 + 5] = players[i]->height / 2;
			lightPositions[i * 8 + 6] = players[i]->width / 2;
			lightPositions[i * 8 + 7] = players[i]->height / 2;
			break;
		}
		else {
			lightPositions[i * 8] = (-players[i]->width / 2 - (i - 0.5f) * (xDiff)) * scale;
			lightPositions[i * 8 + 1] = (-players[i]->height / 2 - (i - 0.5f) * (yDiff)) * scale;
			lightPositions[i * 8 + 2] = (players[i]->width / 2 - (i - 0.5f) * (xDiff)) * scale;
			lightPositions[i * 8 + 3] = (-players[i]->height / 2 - (i - 0.5f) * (yDiff)) * scale;
			lightPositions[i * 8 + 4] = (-players[i]->width / 2 - (i - 0.5f) * (xDiff)) * scale;
			lightPositions[i * 8 + 5] = (players[i]->height / 2 - (i - 0.5f) * (yDiff)) * scale;
			lightPositions[i * 8 + 6] = (players[i]->width / 2 - (i - 0.5f) * (xDiff)) * scale;
			lightPositions[i * 8 + 7] = (players[i]->height / 2 - (i - 0.5f) * (yDiff)) * scale;
		}
	}

	glUniform2fv(lightPositionsUniform, 8, lightPositions);
}
コード例 #25
0
void CGrassDrawer::ResetPos(const float3& pos)
{
	ResetPos(pos.x / bMSsq, pos.z / bMSsq);
}