inline Vector2f VectorLocalization2D::attractorFunction(line2f l, Vector2f p, float attractorRange, float margin)
{
  static const bool debug = false;
  
  Vector2f attraction(0.0,0.0), dir(V2COMP(l.Dir())), p0(V2COMP(l.P0())), p1(V2COMP(l.P1()));
  
  float location = (p-p0).dot(dir);
  
  if(location<-margin || location>l.Length()+margin){
    return attraction;
  }
  
  attraction = (p-p0) - dir*location ;
  
  float d = attraction.norm();
  /*
  if(d>0.5*attractorRange){
    float d2 = max(0.0f, attractorRange - d);
    attraction *= 2.0f*d2/attractorRange;
  }
  */
  if(d>attractorRange){
    attraction = Vector2f::Zero();
  }
  if(debug){
    debugLines.push_back( line2f( vector2f(p.x(),p.y()) ,vector2f((p-attraction).x(),(p-attraction).y()) ) );
  }
  return attraction;
}
Exemplo n.º 2
0
void SystemInfoView::BodyIcon::Draw()
{
	Gui::ImageRadioButton::Draw();
	if (!GetSelected() && !HasStarport()) return;
	float size[2];
	GetSize(size);
	if (HasStarport()) {
	    Color portColor = Color(64, 128, 128, 255);
	    // The -0.1f offset seems to be the best compromise to make the circles closed (e.g. around Mars), symmetric, fitting with selection
	    // and not overlapping to much with asteroids
	    Graphics::Drawables::Circle circle =
			Graphics::Drawables::Circle(size[0]*0.5f, size[0]*0.5f-0.1f, size[1]*0.5f, 0.f,
			portColor, m_renderState);
	    circle.Draw(m_renderer);
	}
	if (GetSelected()) {
	    const vector2f vts[] = {
		    vector2f(0.f, 0.f),
		    vector2f(size[0], 0.f),
		    vector2f(size[0], size[1]),
		    vector2f(0.f, size[1]),
	    };
	    m_renderer->DrawLines2D(COUNTOF(vts), vts, m_selectColor, m_renderState, Graphics::LINE_LOOP);
	}
}
Exemplo n.º 3
0
void Scene::Render(Camera* cam)
{
	const Uint32 w = m_renderer->GetWindow()->GetWidth();
	const Uint32 h = m_renderer->GetWindow()->GetHeight();

	const float aspect = (cam->viewport.z * w) / (cam->viewport.w * h);
	m_renderer->SetViewport(cam->viewport.x * w, cam->viewport.y * h, cam->viewport.z * w, cam->viewport.w * h);
	m_renderer->SetScissor(true,
	                       vector2f(cam->viewport.x * w, cam->viewport.y * h),
	                       vector2f(cam->viewport.z * w, cam->viewport.w * h));
	m_renderer->SetClearColor(cam->clearColor);
	m_renderer->ClearScreen();
	m_renderer->SetPerspectiveProjection(cam->fovY, aspect, cam->nearZ, cam->farZ);

	m_renderer->SetViewMatrix(cam->viewMatrix);
	for (auto g : m_bgGraphics)
		g->Render();

	m_renderer->EnableFramebufferSRGB(true);

	if (!m_lights.empty())
		m_renderer->SetLights(m_lights.size(), m_lights[0]);

	for (auto g : m_graphics)
		g->Render();

	m_lights.clear();
	m_renderer->EnableFramebufferSRGB(false);
}
Exemplo n.º 4
0
void DeadVideoLink::Draw()
{
	float size[2];
	GetSize(size);

	Uint32 now = SDL_GetTicks();

	if (now - m_created < 1500) {
		glBegin(GL_QUADS);
			glColor3f(0,0,0);
			glVertex2f(0,0);
			glVertex2f(0,size[1]);
			glVertex2f(size[0],size[1]);
			glVertex2f(size[0],0);
		glEnd();

		m_message->SetText(Lang::VID_CONNECTING);
		DrawMessage();

		return;
	}

	m_message->SetText(Lang::VID_LINK_DOWN);

	UpdateWhiteNoise();

	m_quad->Draw(Gui::Screen::GetRenderer(), vector2f(0.0f), vector2f(size[0],size[1]));
	DrawMessage();
}
Exemplo n.º 5
0
void UIImage9::setLocation(const aabox2f &rect) {
	m_rect[4].min_corner = rect.min_corner + vector2f(m_widthLeft, m_heightTop);
	m_rect[4].max_corner = rect.max_corner - vector2f(m_widthRight, m_heightBottom);
	
	m_rect[0].min_corner = rect.min_corner;
	m_rect[0].max_corner = m_rect[4].min_corner;
	
	m_rect[1].min_corner.set(m_rect[4].min_corner.x, rect.min_corner.y);
	m_rect[1].max_corner.set(m_rect[4].max_corner.x, m_rect[4].min_corner.y);
	
	m_rect[2].min_corner.set(m_rect[4].max_corner.x, rect.min_corner.y);
	m_rect[2].max_corner.set(rect.max_corner.x, m_rect[4].min_corner.y);
	
	m_rect[3].min_corner.set(rect.min_corner.x, m_rect[4].min_corner.y);
	m_rect[3].max_corner.set(m_rect[4].min_corner.x, m_rect[4].max_corner.y);
	
	m_rect[5].min_corner.set(m_rect[4].max_corner.x, m_rect[4].min_corner.y);
	m_rect[5].max_corner.set(rect.max_corner.x, m_rect[4].max_corner.y);
	
	m_rect[6].min_corner.set(rect.min_corner.x, m_rect[4].max_corner.y);
	m_rect[6].max_corner.set(m_rect[4].min_corner.x, rect.max_corner.y);
	
	m_rect[7].min_corner.set(m_rect[4].min_corner.x, m_rect[4].max_corner.y);
	m_rect[7].max_corner.set(m_rect[4].max_corner.x, rect.max_corner.y);
	
	m_rect[8].min_corner = m_rect[4].max_corner;
	m_rect[8].max_corner = rect.max_corner;
}
Exemplo n.º 6
0
void Face::Draw()
{
	const Point &offset = GetActiveOffset();
	const Point &area = GetActiveArea();

	const float x = offset.x;
	const float y = offset.y;
	const float sx = area.x;
	const float sy = area.y;

	const vector2f texSize = m_texture->GetDescriptor().texSize;

	Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0);
	va.Add(vector3f(x,    y,    0.0f), vector2f(0.0f,      0.0f));
	va.Add(vector3f(x,    y+sy, 0.0f), vector2f(0.0f,      texSize.y));
	va.Add(vector3f(x+sx, y,    0.0f), vector2f(texSize.x, 0.0f));
	va.Add(vector3f(x+sx, y+sy, 0.0f), vector2f(texSize.x, texSize.y));

	Graphics::Renderer *r = GetContext()->GetRenderer();
	s_material->texture0 = m_texture.get();
	auto state = GetContext()->GetSkin().GetAlphaBlendState();
	r->DrawTriangles(&va, state, s_material.Get(), Graphics::TRIANGLE_STRIP);

	Single::Draw();
}
Exemplo n.º 7
0
void Gradient::Draw()
{
	float size[2];
	GetSize(size);

	m_quad->Draw(Gui::Screen::GetRenderer(), vector2f(0.0f), vector2f(size[0],size[1]));
}
Exemplo n.º 8
0
void Face::Draw()
{
	Graphics::Renderer *r = GetContext()->GetRenderer();
	if (!m_quad) {
		const Point &offset = GetActiveOffset();
		const Point &area = GetActiveArea();

		const float x = offset.x;
		const float y = offset.y;
		const float sx = area.x;
		const float sy = area.y;

		const vector2f texSize = m_texture->GetDescriptor().texSize;

		Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0);
		va.Add(vector3f(x, y, 0.0f), vector2f(0.0f, 0.0f));
		va.Add(vector3f(x, y + sy, 0.0f), vector2f(0.0f, texSize.y));
		va.Add(vector3f(x + sx, y, 0.0f), vector2f(texSize.x, 0.0f));
		va.Add(vector3f(x + sx, y + sy, 0.0f), vector2f(texSize.x, texSize.y));

		Graphics::Renderer *r = GetContext()->GetRenderer();
		s_material->texture0 = m_texture.get();
		auto state = GetContext()->GetSkin().GetAlphaBlendState();
		m_quad.reset(new Graphics::Drawables::TexturedQuad(r, s_material, va, state));
	}
	m_quad->Draw(r);

	Single::Draw();
}
Exemplo n.º 9
0
	//-------------------------------------------------------------------------------------------------------
	void SSAOPostEffect::Process( Engine& engine, const RenderTarget* const org, const RenderTarget* const scene, RenderTarget* const out )
	{
		engine.GetDevice()->DisableDepthTest();
		engine.GetDevice()->DisableAlpha();

		{
			engine.GetDevice()->PushRenderTarget(m_pDownSimple_1);

			SSAOShader& ssao = engine.GetShaderManage()->GetShader<SSAOShader>(ShaderManage::SSAOShader);
			ssao.SetParamDepthTex( org->GetDepthBuffer() );
			ssao.SetParamJitterTex( m_JitterTex );
			ssao.SetParamNormalTex( engine.GetPipeline()->NormalRenderTarget()->GetColorBuffer() );
			ssao.SetParamAOEdgeFinder( AOEdgeFinder );
			ssao.SetParamAOIntensity( AOIntensity );
			ssao.SetParamJitterAmount( JitterAmount );
			ssao.SetParamStepSize( vector2f( 1.0 / m_pDownSimple_1->GetSize().m_x , 1.0 / m_pDownSimple_1->GetSize().m_y ) );
			engine.GetDevice()->Draw( *m_pRendBuffer, ssao, NULL );
			engine.GetDevice()->PopRenderTarget();

		}

		{//模糊
			//x
			engine.GetDevice()->PushRenderTarget(m_pDownSimple_2);
			engine.GetDevice()->Clear( Device::COLOR_BUFFER );
			Blur2x2Shader& bs = engine.GetShaderManage()->GetShader<Blur2x2Shader>(ShaderManage::Blur2x2Shader);
			bs.SetParamColorTexture( m_pDownSimple_1->GetColorBuffer() );
			bs.SetParamStepSize( vector2f( (1.0f / m_pDownSimple_2->GetSize().m_x) * GaussSpread, 0.0 ) );
			bs.SetParamGaussWeight( GaussWeight );
			engine.GetDevice()->Draw( *m_pRendBuffer, bs, NULL );
			engine.GetDevice()->PopRenderTarget();

			//y
			engine.GetDevice()->PushRenderTarget(m_pDownSimple_1);
			engine.GetDevice()->Clear( Device::COLOR_BUFFER );
			bs.SetParamColorTexture( m_pDownSimple_2->GetColorBuffer() );
			bs.SetParamStepSize( vector2f( 0.0, (1.0f / m_pDownSimple_1->GetSize().m_y) * GaussSpread ) );
			bs.SetParamGaussWeight( GaussWeight );
			engine.GetDevice()->Draw( *m_pRendBuffer, bs, NULL );
			engine.GetDevice()->PopRenderTarget();
		}

		engine.GetDevice()->PushRenderTarget( out );//如果画在了输出上面,则需要更换输出,下一个pe就用另外一张rt
		engine.GetDevice()->Clear( Device::COLOR_BUFFER );
		if( 1 )
		{
			SSAOCombine& sc = engine.GetShaderManage()->GetShader<SSAOCombine>(ShaderManage::SSAOCombine);
			sc.SetParamSceneTexture( scene->GetColorBuffer() );
			sc.SetParamSSVOTexture( m_pDownSimple_1->GetColorBuffer() );
			engine.GetDevice()->Draw( *m_pRendBuffer, sc, NULL );
		}
		else
		{
			QuadShader& qs = engine.GetShaderManage()->GetShader<QuadShader>(ShaderManage::QuadShader);
			//engine.GetDevice()->Draw( *m_pRendBuffer, qs, engine.GetPipeline()->NormalRenderTarget()->GetColorBuffer() );
			engine.GetDevice()->Draw( *m_pRendBuffer, qs, m_pDownSimple_1->GetColorBuffer() );
		}
		engine.GetDevice()->PopRenderTarget( );
	}
Exemplo n.º 10
0
void TextureBuilder::UpdateTexture(Texture *texture)
{
	if( m_surface ) {
		texture->Update(m_surface->pixels, vector2f(m_surface->w,m_surface->h), m_descriptor.format, 0);
	} else {
		assert(m_dds.headerdone_);
		assert(m_descriptor.format == TEXTURE_DXT1 || m_descriptor.format == TEXTURE_DXT5);
		texture->Update(m_dds.imgdata_.imgData, vector2f(m_dds.imgdata_.width,m_dds.imgdata_.height), m_descriptor.format, m_dds.imgdata_.numMipMaps);
	}
}
Exemplo n.º 11
0
void TextureBuilder::PrepareSurface()
{
	if (m_prepared) return;

	if (!m_surface && m_filename.length() > 0)
		LoadSurface();

	TextureFormat targetTextureFormat;
	SDL_PixelFormat *targetPixelFormat;
	bool needConvert = !GetTargetFormat(m_surface->format, &targetTextureFormat, &targetPixelFormat, m_forceRGBA);

	if (needConvert) {
		SDL_Surface *s = SDL_ConvertSurface(m_surface, targetPixelFormat, SDL_SWSURFACE);
		SDL_FreeSurface(m_surface);
		m_surface = s;
	}

	unsigned int virtualWidth, actualWidth, virtualHeight, actualHeight;
	virtualWidth = actualWidth = m_surface->w;
	virtualHeight = actualHeight = m_surface->h;

	if (m_potExtend) {
		// extend to power-of-two if necessary
		actualWidth = ceil_pow2(m_surface->w);
		actualHeight = ceil_pow2(m_surface->h);
		if (actualWidth != virtualWidth || actualHeight != virtualHeight) {
			SDL_Surface *s = SDL_CreateRGBSurface(SDL_SWSURFACE, actualWidth, actualHeight, targetPixelFormat->BitsPerPixel,
				targetPixelFormat->Rmask, targetPixelFormat->Gmask, targetPixelFormat->Bmask, targetPixelFormat->Amask);

			SDL_SetAlpha(m_surface, 0, 0);
			SDL_SetAlpha(s, 0, 0);
			SDL_BlitSurface(m_surface, 0, s, 0);

			SDL_FreeSurface(m_surface);
			m_surface = s;
		}
	}

	else if (m_filename.length() > 0) {
		// power-of-to check
		unsigned long width = ceil_pow2(m_surface->w);
		unsigned long height = ceil_pow2(m_surface->h);

		if (width != virtualWidth || height != virtualHeight)
			fprintf(stderr, "WARNING: texture '%s' is not power-of-two and may not display correctly\n", m_filename.c_str());
	}

	m_descriptor = TextureDescriptor(
		targetTextureFormat,
		vector2f(actualWidth,actualHeight),
		vector2f(float(virtualWidth)/float(actualWidth),float(virtualHeight)/float(actualHeight)),
		m_sampleMode, m_generateMipmaps);
	
	m_prepared = true;
}
Exemplo n.º 12
0
//-------------------------------------------------------------------------------------------------------
void BloomPS::Process(IDriver& driver, const RenderTarget* const org, const RenderTarget* const scene, RenderTarget* const out, bool& isSwitch)
{
	float Range = 2; //控制模糊度

	//降采样
	//driver.PushRenderTarget(m_pDownSimple_1);
	//driver.Clear( IDriver::COLOR_BUFFER );
	//QuadShader& qs = driver.GetShaderManage().GetShader<QuadShader>(ShaderManage::QuadShader);
	//driver.Draw( *m_pRendBuffer, qs, scene->GetColorBuffer() );
	//driver.PopRenderTarget();

	//流明化
	driver.PushRenderTarget(m_pDownSimple_1);
	driver.Clear( IDriver::COLOR_BUFFER );
	Luminance& le = driver.GetShaderManage().GetShader<Luminance>(ShaderManage::Luminance);
	driver.Draw( *m_pRendBuffer, le, scene->GetColorBuffer() );
	driver.PopRenderTarget();

	//x方向模糊
	driver.PushRenderTarget(m_pDownSimple_2);
	driver.Clear( IDriver::COLOR_BUFFER );
	Gaussian& gauss = driver.GetShaderManage().GetShader<Gaussian>(ShaderManage::Gaussian);
	gauss.SetParamStep( vector2f( Range / m_pDownSimple_1->GetSize().m_x, 0.0f ) );
	driver.Draw( *m_pRendBuffer, gauss, m_pDownSimple_1->GetColorBuffer() );
	driver.PopRenderTarget();

	//y方向模糊
	driver.PushRenderTarget(m_pDownSimple_1);
	driver.Clear( IDriver::COLOR_BUFFER );
	gauss.SetParamStep( vector2f( 0.0f, Range / m_pDownSimple_2->GetSize().m_y ) );
	driver.Draw( *m_pRendBuffer, gauss, m_pDownSimple_2->GetColorBuffer() );
	driver.PopRenderTarget();

	driver.PushRenderTarget( out );//如果画在了输出上面,则需要更换输出,下一个pe就用另外一张rt
	isSwitch = true;
	driver.Clear( IDriver::COLOR_BUFFER );
	//if( 0 )
	{
		driver.EnableAlphaBlend(IDriver::BL_SRC_ALPHA, IDriver::BL_ONE_MINUS_SRC_ALPHA, IDriver::BL_SRC_ALPHA, IDriver::BL_ONE_MINUS_SRC_ALPHA );
		Combine& ce = driver.GetShaderManage().GetShader<Combine>(ShaderManage::Combine);
		ce.SetParamOrginial( scene->GetColorBuffer() );
		ce.SetParamSecen( m_pDownSimple_1->GetColorBuffer() );
		ce.SetParamOrginialWeight(1.0f);
		ce.SetParamSecenWeight(0.0f);//was 0.75
		driver.Draw( *m_pRendBuffer, ce, NULL );
	}
	//else
	//{
	//	QuadShader& qs = driver.GetShaderManage().GetShader<QuadShader>(ShaderManage::QuadShader);
	//	driver.Draw( *m_pRendBuffer, qs, m_pDownSimple_1->GetColorBuffer() );
	//	//driver.Draw( *m_pRendBuffer, ui, org->GetDepthBuffer() );
	//}
	driver.PopRenderTarget( );
}
Exemplo n.º 13
0
void Skin::DrawRectElement(const RectElement &element, const Point &pos, const Point &size, Graphics::BlendMode blendMode) const
{
	Graphics::VertexArray va(Graphics::ATTRIB_POSITION | Graphics::ATTRIB_UV0);

	va.Add(vector3f(pos.x,        pos.y,        0.0f), scaled(vector2f(element.pos.x,                element.pos.y)));
	va.Add(vector3f(pos.x,        pos.y+size.y, 0.0f), scaled(vector2f(element.pos.x,                element.pos.y+element.size.y)));
	va.Add(vector3f(pos.x+size.x, pos.y,        0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y)));
	va.Add(vector3f(pos.x+size.x, pos.y+size.y, 0.0f), scaled(vector2f(element.pos.x+element.size.x, element.pos.y+element.size.y)));

	m_renderer->DrawTriangles(&va, GetRenderState(blendMode), m_textureMaterial.Get(), Graphics::TRIANGLE_STRIP);
}
Exemplo n.º 14
0
void TextEntry::Draw()
{
	PROFILE_SCOPED()
	m_justFocused = false;

	Graphics::Renderer *pRenderer = Screen::GetRenderer();

	float size[2];
	GetSize(size);

	// find cursor position
	float curs_x, curs_y;
	Gui::Screen::MeasureCharacterPos(m_text, m_cursPos, curs_x, curs_y, m_font.Get());

	if (curs_x - m_scroll > size[0]*0.75f) {
		m_scroll += int(size[0]*0.25f);
	} else if (curs_x - m_scroll < size[0]*0.25f) {
		m_scroll -= int(size[0]*0.25f);
		if (m_scroll < 0) m_scroll = 0;
	}

	//background
	if(!m_background) {
		m_background.reset( new Graphics::Drawables::Rect(pRenderer, vector2f(0.f), vector2f(size[0], size[1]), Color(0,0,0,192), Screen::alphaBlendState));
	}
	m_background->Draw(pRenderer);

	//outline
	const Color c = IsFocused() ? Color::WHITE : Color(192, 192, 192, 255);
	const vector3f boxVts[] = {
		vector3f(0.f, 0.f, 0.f),
		vector3f(size[0],0.f, 0.f),
		vector3f(size[0],size[1], 0.f),
		vector3f(0,size[1], 0.f)
	};
	m_outlines.SetData(2, &boxVts[0], c);
	m_outlines.Draw(pRenderer, Screen::alphaBlendState, Graphics::LINE_LOOP);

	//text
	SetScissor(true);
	Gui::Screen::RenderStringBuffer(m_vb, m_text, 1.0f - m_scroll, 0.0f, c, m_font.Get());
	SetScissor(false);

	//cursor
	const vector3f cursorVts[] = {
		vector3f(curs_x + 1.0f - m_scroll, curs_y + Gui::Screen::GetFontDescender(m_font.Get()) - Gui::Screen::GetFontHeight(m_font.Get()), 0.f),
		vector3f(curs_x + 1.0f - m_scroll, curs_y + Gui::Screen::GetFontDescender(m_font.Get()), 0.f),
	};
	m_cursorLines.SetData(2, &cursorVts[0], Color(128, 128, 128));
	m_cursorLines.Draw(pRenderer, Screen::alphaBlendState);
}
Exemplo n.º 15
0
Sprite::Sprite()
{
	// Tähän annetaan pikselikoordinaatit
	texture = NULL;
	vertexData = NULL;
	indexData = NULL;
	sourceRectSize.x = 0.0f;
	sourceRectSize.y = 0.0f;
	position = vector2f(0.0f, 0.0f);
	sourceRectPosition = vector2f(0.0f, 0.0f);
	origin = vector2f(0.0f, 0.0f);
	red = 255.0f; blue = 255.0f; green = 255.0f;
	createIndexData();

}
Exemplo n.º 16
0
void SystemInfoView::BodyIcon::Draw()
{
	Gui::ImageRadioButton::Draw();
	if (!GetSelected()) return;
	float size[2];
	GetSize(size);
	Color green = Color(0.f, 1.f, 0.f, 1.f);
	const vector2f vts[] = {
		vector2f(0.f, 0.f),
		vector2f(size[0], 0.f),
		vector2f(size[0], size[1]),
		vector2f(0.f, size[1]),
	};
	m_renderer->DrawLines2D(4, vts, green, Graphics::LINE_LOOP);
}
void VectorLocalization2D::lowVarianceResample()
{ 
  vector<Particle2D> newParticles;
  newParticles.resize(numParticles);
  float totalWeight = 0.0;
  float newWeight = 1.0/float(numParticles);
  int numRefinedParticles = (int) particlesRefined.size();
  
  refinedImportanceWeights = unrefinedImportanceWeights = 0.0;
  for(int i=0; i<numRefinedParticles; i++){
    //Get rid of particles with undefined weights
    if(isnan(particlesRefined[i].weight) || isinf(particlesRefined[i].weight) || particlesRefined[i].weight<0.0)
      particlesRefined[i].weight = 0.0;
    totalWeight += particlesRefined[i].weight;
    if(i<numParticles)
      refinedImportanceWeights += particlesRefined[i].weight;
    else
      unrefinedImportanceWeights += particlesRefined[i].weight;
  }
  
  if(totalWeight<FLT_MIN){
    //TerminalWarning("Particles have zero total weight!");
    for(int i=0; i<numParticles; i++){
      particles[i].weight = newWeight;
    }
    return;
    //exit(0);
  }
  
  float weightIncrement = totalWeight/float(numParticles);
  if(weightIncrement<FLT_MIN) TerminalWarning("Particle weights less than float precision");
  
  numRefinedParticlesSampled = numUnrefinedParticlesSampled = 0;
  float x = frand(0.0f,totalWeight);
  int j=0;
  float f=particlesRefined[0].weight;
  for(int i=0; i<numParticles; i++){
    while(f<x){
      j = (j+1)%numRefinedParticles;
      f += particlesRefined[j].weight;
    }
    if(j<numParticles)
      numRefinedParticlesSampled++;
    else
      numUnrefinedParticlesSampled++;
    
    newParticles[i] = particlesRefined[j];
    newParticles[i].weight = newWeight;
    if(particlesRefined[i].weight < FLT_MIN){
      //This particle was depleted: add replacement noise
      vector2f deltaLoc = vector2f(frand(-1.0,1.0),frand(-1.0,1.0))*0.05;
      float deltaAngle = frand(-1.0,1.0)*RAD(5.0);
      newParticles[i].loc += deltaLoc;
      newParticles[i].angle += deltaAngle;
    }
    x += weightIncrement;
  }
  
  particles = newParticles;
}
Exemplo n.º 18
0
void Label3D::SetText(const std::string &text)
{
	//regenerate geometry
	m_geometry->Clear();
	if (!text.empty())
		m_font->GetGeometry(*m_geometry.Get(), text, vector2f(0.f));
}
Exemplo n.º 19
0
Icon::Icon(Context *context, const std::string &iconName): Widget(context),
	m_color(Color::WHITE)
{
	if (!s_texture) {
		s_config.Read(FileSystem::gameDataFiles, CONFIG_FILE);

		s_texture.Reset(Graphics::TextureBuilder::UI(s_config.String("TextureFile")).GetOrCreateTexture(GetContext()->GetRenderer(), "ui"));

		const Graphics::TextureDescriptor &texDesc = s_texture->GetDescriptor();
		s_texScale = vector2f(1.0f/texDesc.dataSize.x, 1.0f/texDesc.dataSize.y);

		Graphics::MaterialDescriptor matDesc;
		matDesc.textures = 1;
		s_material.Reset(GetContext()->GetRenderer()->CreateMaterial(matDesc));
		s_material->texture0 = s_texture.Get();
	}

	std::string spec(s_config.String(iconName.c_str()));
	if (spec.size() == 0)
		spec = s_config.String(FALLBACK_ICON);
	assert(spec.size() > 0);

	std::vector<int> v(2);
	SplitSpec(spec, v);
	m_texPos = Point(v[0], v[1]);
}
	//--------------------------------------------------------------------------------------
	void VolumeLightPost::_SetParameters ()
	{
		Engine& engine = Engine::Instance();
		Device* device = engine.GetDevice();
		device->SetShaderParameter( m_hTextureHandle, *m_pTexOrginial );

		const Matrix44f& mvp = engine.GetCamera()->GetViewProj();
		vector4f lp( engine.GetCamera()->GetPosition() + engine.GetEnvironment()->GetCurrentLight().GetWorldDirection() * engine.GetCamera()->GetMiddle()  );
		lp *= mvp ;//与摄像机的位置没有关系,所以始终只乘投影矩阵
		lp /= lp.m_w;
		float alpha = 1.0 - Math::Clamp0to1( ( lp.m_x*lp.m_x+lp.m_y*lp.m_y - 1.0 ) / 7.0 );//这个计算公式计算的是在看到太阳前的alpha衰减,假设太阳的曝光极致是在一个屏幕空间内,所以减去2.0,修改这里需要对应修改Environment的Unpdata
		vector2f lps = vector2f(lp.m_x * 0.5 + 0.5, lp.m_y * 0.5 + 0.5);
		device->SetShaderParameter( m_hLightPositionOnScreenHandle, lps );
#ifdef WIN32
		device->SetShaderParameter( m_hExposureHandle, 0.000016f );//最终曝光强度
		device->SetShaderParameter( m_hDecayHandle, 0.98f );//暗线衰减
		device->SetShaderParameter( m_hDensityHandle, 1.2f );//暗线的长度
		device->SetShaderParameter( m_hWeightHandle, 800.0f * alpha );//黑白色差权重
#else
#ifdef LOWVOLUMELIGHT
		device->SetShaderParameter( m_hExposureHandle, 0.0003f );//最终曝光强度
		device->SetShaderParameter( m_hDecayHandle, 0.87f );//暗线衰减
		device->SetShaderParameter( m_hDensityHandle, 0.6f );//暗线的长度
		device->SetShaderParameter( m_hWeightHandle, 550.0f * alpha );//黑白色差权重
#else
		device->SetShaderParameter( m_hExposureHandle, 0.00032f );//最终曝光强度
		device->SetShaderParameter( m_hDecayHandle, 0.88f );//暗线衰减
		device->SetShaderParameter( m_hDensityHandle, 0.8f );//暗线的长度
		device->SetShaderParameter( m_hWeightHandle, 320.0f * alpha );//黑白色差权重
#endif
#endif
	}
Exemplo n.º 21
0
void TexturedQuad::Draw(Graphics::Renderer *renderer, const vector2f &pos, const vector2f &size, const vector2f &texPos, const vector2f &texSize, const Color &tint)
{
    Graphics::VertexArray va(ATTRIB_POSITION | ATTRIB_UV0);

	va.Add(vector3f(pos.x,        pos.y,        0.0f), vector2f(texPos.x,           texPos.y));
	va.Add(vector3f(pos.x,        pos.y+size.y, 0.0f), vector2f(texPos.x,           texPos.y+texSize.y));
	va.Add(vector3f(pos.x+size.x, pos.y,        0.0f), vector2f(texPos.x+texSize.x, texPos.y));
	va.Add(vector3f(pos.x+size.x, pos.y+size.y, 0.0f), vector2f(texPos.x+texSize.x, texPos.y+texSize.y));

	Graphics::Material m;
	m.unlit = true;
	m.texture0 = m_texture.Get();
	m.vertexColors = false;
	m.diffuse = tint;
	renderer->DrawTriangles(&va, &m, TRIANGLE_STRIP);
}
Exemplo n.º 22
0
void Label3D::SetText(const std::string &text)
{
	//regenerate geometry
	m_geometry->Clear();
	if (!text.empty()) {
		m_font->GetGeometry(*m_geometry, text, vector2f(0.f));

		// Happens if none of the characters in the string have glyphs in the SDF font.
		// Most noticeably, this means text consisting of entirely Cyrillic
		// or Chinese characters will vanish when rendered on a Label3D.
		if (m_geometry->IsEmpty()) { return; }
		
		//create buffer and upload data
		Graphics::VertexBufferDesc vbd;
		vbd.attrib[0].semantic = Graphics::ATTRIB_POSITION;
		vbd.attrib[0].format   = Graphics::ATTRIB_FORMAT_FLOAT3;
		vbd.attrib[1].semantic = Graphics::ATTRIB_NORMAL;
		vbd.attrib[1].format   = Graphics::ATTRIB_FORMAT_FLOAT3;
		vbd.attrib[2].semantic = Graphics::ATTRIB_UV0;
		vbd.attrib[2].format   = Graphics::ATTRIB_FORMAT_FLOAT2;
		vbd.numVertices = m_geometry->GetNumVerts();
		vbd.usage = Graphics::BUFFER_USAGE_STATIC;

		m_vbuffer.reset( m_renderer->CreateVertexBuffer(vbd) );
		m_vbuffer->Populate(*m_geometry);
	}
}
void VectorLocalization2D::setLocation(vector2f loc, float angle, float locationUncertainty, float angleUncertainty)
{
  for(unsigned int i=0; i<particles.size(); i++){
    particles[i].loc = vector2f(randn(locationUncertainty, loc.x), randn(locationUncertainty, loc.y));
    particles[i].angle = randn(angleUncertainty, angle);
  }
}
Exemplo n.º 24
0
Gradient::Gradient(float width, float height, const Color &beginColor, const Color &endColor, Direction direction)
{
	SetSize(width, height);

	Color4ub c0(beginColor);
	Color4ub c1(endColor);
	const unsigned char data[4][4] = {
		{ c0.r, c0.g, c0.b, c0.a },
		{ c1.r, c1.g, c1.b, c1.a },
	};

	vector2f size = direction == HORIZONTAL ? vector2f(2.0f,1.0f) : vector2f(1.0f,2.0f);
	Graphics::Texture *texture = Gui::Screen::GetRenderer()->CreateTexture(Graphics::TextureDescriptor(Graphics::TEXTURE_RGBA, size));
	texture->Update(data, size, Graphics::IMAGE_RGBA, Graphics::IMAGE_UNSIGNED_BYTE);
	m_quad.Reset(new TexturedQuad(texture));
}
Exemplo n.º 25
0
void Context::DrawWidget(Widget *w)
{
	const Point &pos = w->GetPosition();
	const Point &drawOffset = w->GetDrawOffset();
	const Point &size = w->GetSize();

	m_drawWidgetPosition += pos;

	const std::pair<Point,Point> &currentScissor(m_scissorStack.top());
	const Point &currentScissorPos(currentScissor.first);
	const Point &currentScissorSize(currentScissor.second);

	const Point newScissorPos(std::max(m_drawWidgetPosition.x, currentScissorPos.x), std::max(m_drawWidgetPosition.y, currentScissorPos.y));

	const Point newScissorSize(
		Clamp(std::min(newScissorPos.x + size.x, currentScissorPos.x + currentScissorSize.x) - newScissorPos.x, 0, m_width),
		Clamp(std::min(newScissorPos.y + size.y, currentScissorPos.y + currentScissorSize.y) - newScissorPos.y, 0, m_height));

	m_scissorStack.push(std::make_pair(newScissorPos, newScissorSize));

	m_renderer->SetScissor(true, vector2f(newScissorPos.x, m_height - newScissorPos.y - newScissorSize.y), vector2f(newScissorSize.x, newScissorSize.y));

	m_drawWidgetPosition += drawOffset;

	m_renderer->SetTransform(matrix4x4f::Translation(m_drawWidgetPosition.x, m_drawWidgetPosition.y, 0));

	w->Draw();

	m_scissorStack.pop();

	m_drawWidgetPosition -= pos + drawOffset;
}
Exemplo n.º 26
0
	static int l_set_centre_sector(lua_State *l) {
		GalaxyMap *map = LuaObject<GalaxyMap>::CheckFromLua(1);
		float x = luaL_checknumber(l, 2);
		float y = luaL_checknumber(l, 3);
		map->SetCentreSector(vector2f(x, y));
		lua_settop(l, 1);
		return 1;
	}
Exemplo n.º 27
0
SpriteBatch::SpriteBatch(GraphicsDevice &window)
{
	changes = true;
	size = vector2f((float) window.GetSize().x, (float) window.GetSize().y);
	(this->graphicsDevice) = &window;
	glGenBuffers(2, &buffer[0]);

}
Exemplo n.º 28
0
//get font definitions from a line of xml, insert glyph information into the map
void DistanceFieldFont::ParseChar(const StringRange &r)
{
	std::stringstream ss(r.ToString());
	std::string token;

	Uint32 id = 0;
	double x = 0.0;
	double y = 0.0;
	double uSize = 0.0;
	double vSize = 0.0;
	double xoffset = 0.0;
	double yoffset = 0.0;
	double advance = 0.0;

	while (ss >> token) {
			std::pair<std::string, std::string> pair;
			split_token(token, pair);

			//only care about some values
			if (pair.first == "id")
				id = get_value<Uint32>(pair.second);
			else if (pair.first == "x")
				x = get_value<double>(pair.second);
			else if (pair.first == "y")
				y = get_value<double>(pair.second);
			else if (pair.first == "width")
				uSize = get_value<double>(pair.second);
			else if (pair.first == "height")
				vSize = get_value<double>(pair.second);
			else if (pair.first == "xoffset")
				xoffset = get_value<float>(pair.second);
			else if (pair.first == "yoffset")
				yoffset = get_value<float>(pair.second);
			else if (pair.first == "xadvance")
				advance = get_value<float>(pair.second);
	}

	const float scale = 1.f/m_fontSize;
	Glyph g;
	g.uv = vector2f(float(x)/m_sheetSize.x, float(y)/m_sheetSize.y);
	g.uvSize = vector2f(float(uSize)/m_sheetSize.x, float(vSize)/m_sheetSize.y);
	g.size = vector2f(float(uSize), float(vSize)) * scale;
	g.offset = vector2f(float(xoffset), float(m_lineHeight-vSize-yoffset)) * scale;
	g.xAdvance = advance * scale;
	m_glyphs[id] = g;
}
void VectorLocalization2D::predict(float dx, float dy, float dtheta, const MotionModelParams &motionParams)
{
  lastDistanceMoved += vector2f(dx,dy).rotate(lastAngleTurned);
  lastAngleTurned += dtheta;
  for(int i=0; i<numParticles; i++){
    predictParticle(particles[i], dx, dy, dtheta, motionParams);
  }
}
Exemplo n.º 30
0
void Scene::Render()
{
	const Uint32 w = m_renderer->GetWindow()->GetWidth();
	const Uint32 h = m_renderer->GetWindow()->GetHeight();

	//update some transforms in Graphics
	m_modelRenderSystem->update(m_entities, m_events, 0);

	m_renderer->SetAmbientColor(Color(0, 0, 0, 0));

	//this calls Scene::Render(camera)
	m_frameRenderSystem->update(m_entities, m_events, 0);

	//restore expectations
	m_renderer->SetViewport(0, 0, w, h);
	m_renderer->SetScissor(true, vector2f(0.f), vector2f(w, h));
}