示例#1
0
void MiniMap::drawBackground(int showLevel, Rect boundaries, float startX, float startY, float zoom, float fadeBorder, float decalX, float decalY, bool invColor, float alpha) {
	
    m_mapVertices.resize(0);

	float caseX = zoom / ((float)MINIMAP_MAX_X);
	float caseY = zoom / ((float)MINIMAP_MAX_Z);
	
	GRenderer->SetTexture(0, m_levels[showLevel].m_texContainer);
	
	float div = (1.0f / 25);
	TextureContainer * tc = m_levels[showLevel].m_texContainer;
	float dw = 1.f / tc->m_pTexture->getStoredSize().x; 
	float dh = 1.f / tc->m_pTexture->getStoredSize().y;
	
	float vx2 = 4.f * dw * m_modX;
	float vy2 = 4.f * dh * m_modZ;
	
	float fadeDiv = 0.f;
	Rect fadeBounds(0, 0, 0, 0);
	
	if(fadeBorder > 0.f) {
		fadeDiv = 1.f/fadeBorder;
		fadeBounds.left = checked_range_cast<Rect::Num>((boundaries.left + fadeBorder) * Xratio);
		fadeBounds.right = checked_range_cast<Rect::Num>((boundaries.right - fadeBorder) * Xratio);
		fadeBounds.top = checked_range_cast<Rect::Num>((boundaries.top + fadeBorder) * Yratio);
		fadeBounds.bottom = checked_range_cast<Rect::Num>((boundaries.bottom - fadeBorder) * Yratio);
	}
	
	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
	if(invColor) {
		GRenderer->SetBlendFunc(Renderer::BlendOne, Renderer::BlendInvSrcColor);
	} else {
		GRenderer->SetBlendFunc(Renderer::BlendZero, Renderer::BlendInvSrcColor);
	}
	GRenderer->GetTextureStage(0)->setWrapMode(TextureStage::WrapClamp);

	for(int j = -2; j < MINIMAP_MAX_Z + 2; j++) {
		for(int i = -2; i < MINIMAP_MAX_X + 2; i++) {
			
			float vx, vy, vxx, vyy;
			vxx = ((float)i * (float)m_activeBkg->Xdiv * m_modX);
			vyy = ((float)j * (float)m_activeBkg->Zdiv * m_modZ);
			vx = (vxx * div) * dw;
			vy = (vyy * div) * dh;
			
			float posx = (startX + i * caseX) * Xratio;
			float posy = (startY + j * caseY) * Yratio;
			
			if((posx < boundaries.left * Xratio)
			   || (posx > boundaries.right * Xratio)
			   || (posy < boundaries.top * Yratio)
			   || (posy > boundaries.bottom * Yratio)) {
				continue; // out of bounds
			}

			TexturedVertex verts[4];
			
			verts[3].p.x = verts[0].p.x = (posx);
			verts[1].p.y = verts[0].p.y = (posy);
			verts[2].p.x = verts[1].p.x = posx + (caseX * Xratio);
			verts[3].p.y = verts[2].p.y = posy + (caseY * Yratio);
			
			verts[3].uv.x = verts[0].uv.x = vx;
			verts[1].uv.y = verts[0].uv.y = vy;
			verts[2].uv.x = verts[1].uv.x = vx + vx2;
			verts[3].uv.y = verts[2].uv.y = vy + vy2;
			
			float v;
			float oo = 0.f;
			
			for(int vert = 0; vert < 4; vert++) {
				verts[vert].color = 0xFFFFFFFF;
				verts[vert].rhw = 1;
				verts[vert].p.z = 0.00001f;

				// Array offset according to "vert"
				int iOffset = 0;
				int jOffset = 0;
				
				if(vert == 1 || vert == 2)
					iOffset = 1;
				if(vert == 2 || vert == 3)
					jOffset = 1;
				
				if((i + iOffset < 0) || (i + iOffset >= MINIMAP_MAX_X) || (j + jOffset < 0) || (j + jOffset >= MINIMAP_MAX_Z)) {
					v = 0;
				} else {
					v = ((float)m_levels[showLevel].m_revealed[min(i+iOffset, MINIMAP_MAX_X-iOffset)][min(j+jOffset, MINIMAP_MAX_Z-jOffset)]) * (1.0f / 255);
				}
				
				if(fadeBorder > 0.f) {
					
					float _px = verts[vert].p.x - fadeBounds.left;
					
					if(_px < 0.f) {
						v = 0.f;
					} else if(_px < fadeBorder) {
						v *= _px * fadeDiv;
					}
					
					_px = fadeBounds.right - verts[vert].p.x;
					
					if(_px < 0.f) {
						v = 0.f;
					} else if(_px < fadeBorder) {
						v *= _px * fadeDiv;
					}
					
					_px = verts[vert].p.y - fadeBounds.top;
					
					if(_px < 0.f) {
						v = 0.f;
					} else if(_px < fadeBorder) {
						v *= _px * fadeDiv;
					}
					
					_px = fadeBounds.bottom - verts[vert].p.y;
					
					if(_px < 0.f) {
						v = 0.f;
					} else if(_px < fadeBorder) {
						v *= _px * fadeDiv;
					}
				}
				
				verts[vert].color = Color::gray(v * alpha).toBGR();
				
				oo += v;
			}
			
			if(oo > 0.f) {
				
				verts[0].p.x += decalX * Xratio;
				verts[0].p.y += decalY * Yratio;
				verts[1].p.x += decalX * Xratio;
				verts[1].p.y += decalY * Yratio;
				verts[2].p.x += decalX * Xratio;
				verts[2].p.y += decalY * Yratio;
				verts[3].p.x += decalX * Xratio;
				verts[3].p.y += decalY * Yratio;
				
				m_mapVertices.push_back(verts[0]);
				m_mapVertices.push_back(verts[1]);
				m_mapVertices.push_back(verts[2]);

				m_mapVertices.push_back(verts[0]);
				m_mapVertices.push_back(verts[2]);
				m_mapVertices.push_back(verts[3]);
			}
		}
	}

    EERIEDRAWPRIM(Renderer::TriangleList, m_mapVertices.data(), m_mapVertices.size());
	
	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
}
示例#2
0
void MiniMap::drawBackground(int showLevel, Rect boundaries, Vec2f start, float zoom, float fadeBorder, Vec2f decal, bool invColor, float alpha) {
	
	m_mapVertices.clear();
	
	Vec2f cas;
	cas.x = zoom / MINIMAP_MAX_X;
	cas.y = zoom / MINIMAP_MAX_Z;
	
	GRenderer->SetTexture(0, m_levels[showLevel].m_texContainer);
	
	float div = (1.0f / 25);
	TextureContainer * tc = m_levels[showLevel].m_texContainer;
	Vec2f d;
	d.x = 1.f / tc->m_pTexture->getStoredSize().x;
	d.y = 1.f / tc->m_pTexture->getStoredSize().y;
	
	Vec2f v2;
	v2.x = 4.f * d.x * m_mod.x;
	v2.y = 4.f * d.y * m_mod.y;
	
	float fadeDiv = 0.f;
	Rect fadeBounds(0, 0, 0, 0);
	
	if(fadeBorder > 0.f) {
		fadeDiv = 1.f/fadeBorder;
		fadeBounds.left = checked_range_cast<Rect::Num>((boundaries.left + fadeBorder) * g_sizeRatio.x);
		fadeBounds.right = checked_range_cast<Rect::Num>((boundaries.right - fadeBorder) * g_sizeRatio.x);
		fadeBounds.top = checked_range_cast<Rect::Num>((boundaries.top + fadeBorder) * g_sizeRatio.y);
		fadeBounds.bottom = checked_range_cast<Rect::Num>((boundaries.bottom - fadeBorder) * g_sizeRatio.y);
	}
	
	GRenderer->SetRenderState(Renderer::AlphaBlending, true);
	if(invColor) {
		GRenderer->SetBlendFunc(BlendOne, BlendInvSrcColor);
	} else {
		GRenderer->SetBlendFunc(BlendZero, BlendInvSrcColor);
	}
	GRenderer->GetTextureStage(0)->setWrapMode(TextureStage::WrapClamp);
	GRenderer->GetTextureStage(0)->setMinFilter(TextureStage::FilterLinear);
	GRenderer->GetTextureStage(0)->setMagFilter(TextureStage::FilterLinear);

	for(int z = -2; z < int(MINIMAP_MAX_Z) + 2; z++) {
	for(int x = -2; x < int(MINIMAP_MAX_X) + 2; x++) {
		
		Vec2f v3;
		v3.x = float(x) * float(m_activeBkg->Xdiv) * m_mod.x;
		v3.y = float(z) * float(m_activeBkg->Zdiv) * m_mod.y;
		
		Vec2f v4;
		v4.x = (v3.x * div) * d.x;
		v4.y = (v3.y * div) * d.y;
		
		Vec2f pos;
		pos.x = (start.x + x * cas.x) * g_sizeRatio.x;
		pos.y = (start.y + z * cas.y) * g_sizeRatio.y;
		
		if((pos.x < boundaries.left * g_sizeRatio.x)
		   || (pos.x > boundaries.right * g_sizeRatio.x)
		   || (pos.y < boundaries.top * g_sizeRatio.y)
		   || (pos.y > boundaries.bottom * g_sizeRatio.y)) {
			continue; // out of bounds
		}
		
		TexturedVertex verts[4];
		
		verts[3].p.x = verts[0].p.x = pos.x;
		verts[1].p.y = verts[0].p.y = pos.y;
		verts[2].p.x = verts[1].p.x = pos.x + (cas.x * g_sizeRatio.x);
		verts[3].p.y = verts[2].p.y = pos.y + (cas.y * g_sizeRatio.y);
		
		verts[3].uv.x = verts[0].uv.x = v4.x;
		verts[1].uv.y = verts[0].uv.y = v4.y;
		verts[2].uv.x = verts[1].uv.x = v4.x + v2.x;
		verts[3].uv.y = verts[2].uv.y = v4.y + v2.y;
		
		float v;
		float oo = 0.f;
		
		for(int vert = 0; vert < 4; vert++) {
			verts[vert].color = Color(255, 255, 255, 255).toRGBA();
			verts[vert].rhw = 1;
			verts[vert].p.z = 0.00001f;

			// Array offset according to "vert"
			int iOffset = 0;
			int jOffset = 0;
			
			if(vert == 1 || vert == 2)
				iOffset = 1;
			if(vert == 2 || vert == 3)
				jOffset = 1;
			
			if((x + iOffset < 0) || (x + iOffset >= int(MINIMAP_MAX_X)) || (z + jOffset < 0) || (z + jOffset >= int(MINIMAP_MAX_Z))) {
				v = 0;
			} else {
				int minx = std::min(x + iOffset, int(MINIMAP_MAX_X) - iOffset);
				int minz = std::min(z + jOffset, int(MINIMAP_MAX_Z) - jOffset);
				v = float(m_levels[showLevel].m_revealed[minx][minz]) * (1.0f / 255);
			}
			
			if(fadeBorder > 0.f) {
				
				float _px = verts[vert].p.x - fadeBounds.left;
				
				if(_px < 0.f) {
					v = 0.f;
				} else if(_px < fadeBorder) {
					v *= _px * fadeDiv;
				}
				
				_px = fadeBounds.right - verts[vert].p.x;
				
				if(_px < 0.f) {
					v = 0.f;
				} else if(_px < fadeBorder) {
					v *= _px * fadeDiv;
				}
				
				_px = verts[vert].p.y - fadeBounds.top;
				
				if(_px < 0.f) {
					v = 0.f;
				} else if(_px < fadeBorder) {
					v *= _px * fadeDiv;
				}
				
				_px = fadeBounds.bottom - verts[vert].p.y;
				
				if(_px < 0.f) {
					v = 0.f;
				} else if(_px < fadeBorder) {
					v *= _px * fadeDiv;
				}
			}
			
			verts[vert].color = Color::gray(v * alpha).toRGB();
			
			oo += v;
		}
		
		if(oo > 0.f) {
			
			verts[0].p.x += decal.x * g_sizeRatio.x;
			verts[0].p.y += decal.y * g_sizeRatio.y;
			verts[1].p.x += decal.x * g_sizeRatio.x;
			verts[1].p.y += decal.y * g_sizeRatio.y;
			verts[2].p.x += decal.x * g_sizeRatio.x;
			verts[2].p.y += decal.y * g_sizeRatio.y;
			verts[3].p.x += decal.x * g_sizeRatio.x;
			verts[3].p.y += decal.y * g_sizeRatio.y;
			
			m_mapVertices.push_back(verts[0]);
			m_mapVertices.push_back(verts[1]);
			m_mapVertices.push_back(verts[2]);
			
			m_mapVertices.push_back(verts[0]);
			m_mapVertices.push_back(verts[2]);
			m_mapVertices.push_back(verts[3]);
		}
	}
	}

	if(!m_mapVertices.empty()) {
		EERIEDRAWPRIM(Renderer::TriangleList, &m_mapVertices[0], m_mapVertices.size());
	}
	
	GRenderer->SetRenderState(Renderer::AlphaBlending, false);
}