コード例 #1
0
ファイル: ButtonRendering.cpp プロジェクト: Novarisk/openwar
void ButtonRendering::RenderButtonIcon(const glm::mat4& transform, glm::vec2 position, ButtonIcon* buttonIcon, bool disabled)
{
	if (buttonIcon != nullptr)
	{
		bounds2f b = bounds2f(position).grow(buttonIcon->size * buttonIcon->scale / 2.0f);
		RenderTextureRect(transform, buttonIcon->_texture, b, buttonIcon->bounds, disabled ? 0.5 : 1);
	}
}
コード例 #2
0
ファイル: BattleGesture.cpp プロジェクト: Novarisk/openwar
bounds2f BattleGesture::GetUnitModifierBounds(Unit* unit)
{
	switch (unit->state.unitMode)
	{
		case UnitMode_Standing: return _battleView->GetUnitCurrentFacingMarkerBounds(unit).grow(12);
		case UnitMode_Moving: return _battleView->GetUnitFutureFacingMarkerBounds(unit).grow(12);
		default: return bounds2f();
	}
}
コード例 #3
0
ファイル: TiledGroundMap.cpp プロジェクト: openwar/openwar
TiledGroundMap::TiledGroundMap(bounds2f bounds, glm::ivec2 size) :
_heightMap(nullptr),
_bounds(bounds),
_size(size)
{
	_heightMap = new HeightMap(bounds2f(0, 0, 1024, 1024));
	_tiles = new Tile[size.x * size.y];
	_patch = new bspline_patch(glm::ivec2(size.x + 1, size.y + 1));
}
コード例 #4
0
ファイル: OpenWarSurface.cpp プロジェクト: Novarisk/openwar
void OpenWarSurface::OnFrameChanged()
{
    Surface::OnFrameChanged();

    bounds2f viewport = bounds2f(0, 0, GetSize());
    _battleLayer->SetFrame(viewport);
    _buttonsTopLeft->SetFrame(viewport);
    _buttonsTopRight->SetFrame(viewport);
}
コード例 #5
0
ファイル: SmoothGroundMap.cpp プロジェクト: openwar/openwar
bounds2f SmoothGroundMap::Paint(TerrainFeature feature, glm::vec2 position, float pressure, float radius)
{
	glm::vec2 scale = _bounds.size() / glm::vec2(_image->size());
	float abs_pressure = glm::abs(pressure);

	glm::ivec2 center = ToGroundmapCoordinate(position);

	float value = pressure > 0 ? 1 : 0;
	float delta = pressure > 0 ? -0.015f : 0.015f;

	for (int x = -10; x <= 10; ++x)
		for (int y = -10; y <= 10; ++y)
		{
			glm::ivec2 p = center + glm::ivec2(x, y);
			float d = glm::distance(position, scale * glm::vec2(p)) / radius;
			float k = 1.0f - d * d;
			if (k > 0)
			{
				glm::vec4 c = _image->GetPixel(p.x, p.y);
				switch (feature)
				{
					case TerrainFeature::Hills:
						c.a = glm::mix(c.a, c.a + delta, k * abs_pressure);
						break;
					case TerrainFeature::Trees:
						c.g = glm::mix(c.g, value, k * abs_pressure);
						break;
					case TerrainFeature::Water:
						c.b = glm::mix(c.b, value, k * abs_pressure);
						break;
					case TerrainFeature::Fords:
						c.r = glm::mix(c.r, value, k * abs_pressure);
						break;
				}
				_image->SetPixel(p.x, p.y, c);
			}
		}

	UpdateHeightMap();

	return bounds2f(position).add_radius(radius + 1);
}
コード例 #6
0
ファイル: SmoothGroundMap.cpp プロジェクト: openwar/openwar
bounds2f SmoothGroundMap::Paint(TerrainFeature feature, glm::vec2 position, float pressure, const Image& brush)
{
	glm::vec2 scale = _bounds.size() / glm::vec2(_image->size());
	glm::ivec2 size = brush.size();
	glm::ivec2 center = ToGroundmapCoordinate(position);
	glm::ivec2 origin = center - size / 2;
	float radius = size.x / 2.0f;

	for (int x = 0; x < size.x; ++x)
		for (int y = 0; y < size.y; ++y)
		{
			glm::ivec2 p = origin + glm::ivec2(x, y);
			float d = glm::distance(position, scale * glm::vec2(p)) / radius;
			float k = 1.0f - d * d;
			if (k > 0)
			{
				glm::vec4 b = brush.GetPixel(x, y);
				glm::vec4 c = _image->GetPixel(p.x, p.y);
				switch (feature)
				{
					case TerrainFeature::Hills:
						c.a = glm::mix(c.a, b.a, k * pressure);
						break;
					case TerrainFeature::Trees:
						c.g = glm::mix(c.g, b.g, k * pressure);
						break;
					case TerrainFeature::Water:
						c.b = glm::mix(c.b, b.b, k * pressure);
						break;
					case TerrainFeature::Fords:
						c.r = glm::mix(c.r, b.r, k * pressure);
						break;
				}
				_image->SetPixel(p.x, p.y, c);
			}
		}

	UpdateHeightMap();

	return bounds2f(position).add_radius(radius + 1);
}
コード例 #7
0
ファイル: main.cpp プロジェクト: openwar/openwar
static BattleScenario* CreateBattleScenario()
{
	Resource res("Maps/Practice.png");
	if (!res.load())
		return nullptr;

	auto smoothMap = std::unique_ptr<Image>(new Image());
	smoothMap->LoadFromResource(res);

	SmoothGroundMap* groundMap = new SmoothGroundMap(bounds2f(0, 0, 1024, 1024), std::move(smoothMap));
	BattleMap* battleMap = new BasicBattleMap(groundMap->GetHeightMap(), groundMap);

	BattleSimulator* battleSimulator = new BattleSimulator_v1_0_0(battleMap);

	BattleScenario* battleScenario = new BattleScenario(battleSimulator, 0);
	battleScenario->SetPractice(true);
	battleScenario->SetBattleScript(new PracticeScript(battleScenario));
    BattleCommander* player = battleScenario->AddCommander("1", 1, BattleCommanderType::Player);
    battleScenario->AddCommander("2", 2, BattleCommanderType::Script);

	glm::vec2 center(512, 512);

    battleSimulator->AddUnit(player, "SAM-BOW", 80, center + glm::vec2(-50, 0), 0);
    battleSimulator->AddUnit(player, "SAM-ARQ", 80, center + glm::vec2(  0, 0), 0);
    battleSimulator->AddUnit(player, "SAM-BOW", 80, center + glm::vec2( 50, 0), 0);
    battleSimulator->AddUnit(player, "SAM-YARI", 80, center + glm::vec2(-25, -30), 0);
    battleSimulator->AddUnit(player, "SAM-YARI", 80, center + glm::vec2( 25, -30), 0);
    battleSimulator->AddUnit(player, "SAM-KATA", 80, center + glm::vec2(-50, -60), 0);
    battleSimulator->AddUnit(player, "GEN-KATA", 40, center + glm::vec2(  0, -60), 0);
    battleSimulator->AddUnit(player, "SAM-KATA", 80, center + glm::vec2( 50, -60), 0);
    battleSimulator->AddUnit(player, "CAV-YARI", 40, center + glm::vec2(-70, -100), 0);
    battleSimulator->AddUnit(player, "SAM-NAGI", 80, center + glm::vec2(  0, -90), 0);
    battleSimulator->AddUnit(player, "CAV-BOW",  40, center + glm::vec2( 70, -100), 0);

	return battleScenario;
}
コード例 #8
0
ファイル: ButtonRendering.cpp プロジェクト: Novarisk/openwar
void ButtonRendering::RenderCornerButton(const glm::mat4& transform, texture* texturex, bounds2f bounds, float radius)
{
	vertexbuffer<texture_vertex> shape;
	shape._mode = GL_TRIANGLES;

	bounds2f outer = bounds;
	bounds2f inner = outer.grow(-radius);

	AddRect(shape, bounds2f(outer.min.x, outer.min.y, inner.min.x, inner.min.y), bounds2f(0.0, 0.0, 0.5, 0.5));
	AddRect(shape, bounds2f(inner.min.x, outer.min.y, inner.max.x, inner.min.y), bounds2f(0.5, 0.0, 0.5, 0.5));
	AddRect(shape, bounds2f(inner.max.x, outer.min.y, outer.max.x, inner.min.y), bounds2f(0.5, 0.0, 1.0, 0.5));

	AddRect(shape, bounds2f(outer.min.x, inner.min.y, inner.min.x, inner.max.y), bounds2f(0.0, 0.5, 0.5, 0.5));
	AddRect(shape, bounds2f(inner.min.x, inner.min.y, inner.max.x, inner.max.y), bounds2f(0.5, 0.5, 0.5, 0.5));
	AddRect(shape, bounds2f(inner.max.x, inner.min.y, outer.max.x, inner.max.y), bounds2f(0.5, 0.5, 1.0, 0.5));

	AddRect(shape, bounds2f(outer.min.x, inner.max.y, inner.min.x, outer.max.y), bounds2f(0.0, 0.5, 0.5, 1.0));
	AddRect(shape, bounds2f(inner.min.x, inner.max.y, inner.max.x, outer.max.y), bounds2f(0.5, 0.5, 0.5, 1.0));
	AddRect(shape, bounds2f(inner.max.x, inner.max.y, outer.max.x, outer.max.y), bounds2f(0.5, 0.5, 1.0, 1.0));

	_renderers->_texture_renderer->get_uniform<glm::mat4>("transform").set_value(transform);
	_renderers->_texture_renderer->get_uniform<const texture*>("texture").set_value(texturex);
	_renderers->_texture_renderer->render(shape);
}
コード例 #9
0
ファイル: ButtonRendering.cpp プロジェクト: Novarisk/openwar
void ButtonRendering::RenderHighlight(const glm::mat4& transform, bounds2f bounds)
{
	RenderTextureRect(transform, _textureButtonHighlight, bounds, bounds2f(0, 0, 1, 1));
}
コード例 #10
0
ファイル: ButtonRendering.cpp プロジェクト: Novarisk/openwar
ButtonRendering::ButtonRendering(renderers* r, float pixelDensity) :
_renderers(r)
{
	_textureButtonBackground = new texture(resource("Textures/ButtonNormal.png"));
	_textureButtonHighlight = new texture(resource("Textures/ButtonHighlight.png"));
	_textureButtonSelected = new texture(resource("Textures/ButtonSelected.png"));
	_textureButtonIcons = new texture(resource("Textures/ButtonIcons.png"));

	_string_font = new stringfont(true, 18, pixelDensity);
	_string_shape = new stringshape(_string_font);

	_textureEditorTools = new texture(resource("Textures/EditorTools.png"));

	buttonIconPlay = new ButtonIcon(_textureButtonIcons, glm::vec2(25, 32), bounds2f(0, 0, 25, 32) / glm::vec2(128, 32));
	buttonIconPause = new ButtonIcon(_textureButtonIcons, glm::vec2(25, 32), bounds2f(25, 0, 50, 32) / glm::vec2(128, 32));
	buttonIconRewind = new ButtonIcon(_textureButtonIcons, glm::vec2(25, 32), bounds2f(50, 0, 75, 32) / glm::vec2(128, 32));
	buttonIconHelp = new ButtonIcon(_textureButtonIcons, glm::vec2(25, 32), bounds2f(75, 0, 100, 32) / glm::vec2(128, 32));
	buttonIconChat = new ButtonIcon(_textureButtonIcons, glm::vec2(25, 32), bounds2f(100, 0, 125, 32) / glm::vec2(128, 32));

	buttonEditorToolHand = new ButtonIcon(_textureEditorTools, glm::vec2(32, 32), bounds2f(0.00, 0.0, 0.25, 0.5));
	buttonEditorToolPaint = new ButtonIcon(_textureEditorTools, glm::vec2(32, 32), bounds2f(0.25, 0.0, 0.50, 0.5));
	buttonEditorToolErase = new ButtonIcon(_textureEditorTools, glm::vec2(32, 32), bounds2f(0.50, 0.0, 0.75, 0.5));
	buttonEditorToolSmear = new ButtonIcon(_textureEditorTools, glm::vec2(32, 32), bounds2f(0.75, 0.0, 1.00, 0.5));
	buttonEditorToolHills = new ButtonIcon(_textureEditorTools, glm::vec2(32, 32), bounds2f(0.00, 0.5, 0.25, 1.0));
	buttonEditorToolTrees = new ButtonIcon(_textureEditorTools, glm::vec2(32, 32), bounds2f(0.25, 0.5, 0.50, 1.0));
	buttonEditorToolWater = new ButtonIcon(_textureEditorTools, glm::vec2(32, 32), bounds2f(0.50, 0.5, 0.75, 1.0));
	buttonEditorToolFords = new ButtonIcon(_textureEditorTools, glm::vec2(32, 32), bounds2f(0.75, 0.5, 1.00, 1.0));
}
コード例 #11
0
ファイル: ImageWidget.cpp プロジェクト: openwar/openwar
void ImageWidget::RenderVertices(std::vector<Vertex_2f_2f_4f_1f>& vertices)
{
	if (_textureImage == nullptr)
		return;

	bounds2f outer = _bounds;
	if (outer.empty())
		return;

	bounds2f inner(outer.min + _inset.min, outer.max - _inset.max);
	inner.min.x = std::min(inner.min.x, outer.max.x);
	inner.max.x = std::max(inner.max.x, outer.min.x);
	inner.min.y = std::min(inner.min.y, outer.max.y);
	inner.max.y = std::max(inner.max.y, outer.min.y);
	if (inner.min.x > inner.max.x)
		inner.min.x = inner.max.x = (inner.min.x + inner.max.x) / 2;
	if (inner.min.y > inner.max.y)
		inner.min.y = inner.max.y = (inner.min.y + inner.max.y) / 2;

	BorderBounds texture = _textureImage->GetCoords();

	bool min_x = outer.min.x < inner.min.x;
	bool max_x = inner.max.x < outer.max.x;
	bool min_y = outer.min.y < inner.min.y;
	bool max_y = inner.max.y < outer.max.y;

	if (min_x && min_y)
		AppendRectangle(vertices,
			bounds2f(outer.min.x, outer.min.y, inner.min.x, inner.min.y),
			bounds2f(texture.outer.min.x, texture.outer.max.y, texture.inner.min.x, texture.inner.max.y));

	if (min_x)
		AppendRectangle(vertices,
			bounds2f(outer.min.x, inner.min.y, inner.min.x, inner.max.y),
			bounds2f(texture.outer.min.x, texture.inner.max.y, texture.inner.min.x, texture.inner.min.y));

	if (min_x && max_y)
		AppendRectangle(vertices,
			bounds2f(outer.min.x, inner.max.y, inner.min.x, outer.max.y),
			bounds2f(texture.outer.min.x, texture.inner.min.y, texture.inner.min.x, texture.outer.min.y));

	if (min_y)
		AppendRectangle(vertices,
			bounds2f(inner.min.x, outer.min.y, inner.max.x, inner.min.y),
			bounds2f(texture.inner.min.x, texture.outer.max.y, texture.inner.max.x, texture.inner.max.y));

	if (!inner.empty())
		AppendRectangle(vertices,
			bounds2f(inner.min.x, inner.min.y, inner.max.x, inner.max.y),
			bounds2f(texture.inner.min.x, texture.inner.max.y, texture.inner.max.x, texture.inner.min.y));

	if (max_y)
		AppendRectangle(vertices,
			bounds2f(inner.min.x, inner.max.y, inner.max.x, outer.max.y),
			bounds2f(texture.inner.min.x, texture.inner.min.y, texture.inner.max.x, texture.outer.min.y));

	if (max_x && min_y)
		AppendRectangle(vertices,
			bounds2f(inner.max.x, outer.min.y, outer.max.x, inner.min.y),
			bounds2f(texture.inner.max.x, texture.outer.max.y, texture.outer.max.x, texture.inner.max.y));

	if (max_x)
		AppendRectangle(vertices,
			bounds2f(inner.max.x, inner.min.y, outer.max.x, inner.max.y),
			bounds2f(texture.inner.max.x, texture.inner.max.y, texture.outer.max.x, texture.inner.min.y));

	if (max_x && max_y)
		AppendRectangle(vertices,
			bounds2f(inner.max.x, inner.max.y, outer.max.x, outer.max.y),
			bounds2f(texture.inner.max.x, texture.inner.min.y, texture.outer.max.x, texture.outer.min.y));
}
コード例 #12
0
ファイル: ButtonRendering.cpp プロジェクト: clin4g/openwar
void ButtonRendering::RenderCornerButton(bounds2f viewport, texture* texture, bounds2f bounds, float radius)
{
	vertexbuffer<texture_vertex> shape;
	shape._mode = GL_TRIANGLES;

	bounds2f outer = bounds;
	bounds2f inner = outer.grow(-radius);

	AddRect(shape, bounds2f(outer.min.x, outer.min.y, inner.min.x, inner.min.y), bounds2f(0.0, 0.0, 0.5, 0.5));
	AddRect(shape, bounds2f(inner.min.x, outer.min.y, inner.max.x, inner.min.y), bounds2f(0.5, 0.0, 0.5, 0.5));
	AddRect(shape, bounds2f(inner.max.x, outer.min.y, outer.max.x, inner.min.y), bounds2f(0.5, 0.0, 1.0, 0.5));

	AddRect(shape, bounds2f(outer.min.x, inner.min.y, inner.min.x, inner.max.y), bounds2f(0.0, 0.5, 0.5, 0.5));
	AddRect(shape, bounds2f(inner.min.x, inner.min.y, inner.max.x, inner.max.y), bounds2f(0.5, 0.5, 0.5, 0.5));
	AddRect(shape, bounds2f(inner.max.x, inner.min.y, outer.max.x, inner.max.y), bounds2f(0.5, 0.5, 1.0, 0.5));

	AddRect(shape, bounds2f(outer.min.x, inner.max.y, inner.min.x, outer.max.y), bounds2f(0.0, 0.5, 0.5, 1.0));
	AddRect(shape, bounds2f(inner.min.x, inner.max.y, inner.max.x, outer.max.y), bounds2f(0.5, 0.5, 0.5, 1.0));
	AddRect(shape, bounds2f(inner.max.x, inner.max.y, outer.max.x, outer.max.y), bounds2f(0.5, 0.5, 1.0, 1.0));

	texture_uniforms uniforms;
	uniforms._transform = sprite_transform(viewport).transform();
	uniforms._texture = texture;

	_renderers->_texture_renderer->render(shape, uniforms);
}
コード例 #13
0
ファイル: ButtonRendering.cpp プロジェクト: clin4g/openwar
void ButtonRendering::RenderHighlight(bounds2f viewport, bounds2f bounds)
{
	RenderTextureRect(viewport, _textureButtonHighlight, bounds, bounds2f(0, 0, 1, 1));
	//RenderCornerButton(viewport, _texture_highlight, bounds.grow(10), 32);
}
コード例 #14
0
ファイル: textureshape.cpp プロジェクト: Novarisk/openwar
void textureglyph::generate(std::vector<vertex_type>& vertices)
{
	bool min_x = outer_xy.min.x < inner_xy.min.x;
	bool max_x = inner_xy.max.x < outer_xy.max.x;
	bool min_y = outer_xy.min.y < inner_xy.min.y;
	bool max_y = inner_xy.max.y < outer_xy.max.y;

	if (min_x && min_y)
		rectangle(vertices,
			bounds2f(outer_xy.min.x, outer_xy.min.y, inner_xy.min.x, inner_xy.min.y),
			bounds2f(outer_uv.min.x, outer_uv.max.y, inner_uv.min.x, inner_uv.max.y));

	if (min_x)
		rectangle(vertices,
			bounds2f(outer_xy.min.x, inner_xy.min.y, inner_xy.min.x, inner_xy.max.y),
			bounds2f(outer_uv.min.x, inner_uv.max.y, inner_uv.min.x, inner_uv.min.y));

	if (min_x && max_y)
		rectangle(vertices,
			bounds2f(outer_xy.min.x, inner_xy.max.y, inner_xy.min.x, outer_xy.max.y),
			bounds2f(outer_uv.min.x, inner_uv.min.y, inner_uv.min.x, outer_uv.min.y));

	if (min_y)
		rectangle(vertices,
			bounds2f(inner_xy.min.x, outer_xy.min.y, inner_xy.max.x, inner_xy.min.y),
			bounds2f(inner_uv.min.x, outer_uv.max.y, inner_uv.max.x, inner_uv.max.y));

	rectangle(vertices,
		bounds2f(inner_xy.min.x, inner_xy.min.y, inner_xy.max.x, inner_xy.max.y),
		bounds2f(inner_uv.min.x, inner_uv.max.y, inner_uv.max.x, inner_uv.min.y));

	if (max_y)
		rectangle(vertices,
			bounds2f(inner_xy.min.x, inner_xy.max.y, inner_xy.max.x, outer_xy.max.y),
			bounds2f(inner_uv.min.x, inner_uv.min.y, inner_uv.max.x, outer_uv.min.y));

	if (max_x && min_y)
		rectangle(vertices,
			bounds2f(inner_xy.max.x, outer_xy.min.y, outer_xy.max.x, inner_xy.min.y),
			bounds2f(inner_uv.max.x, outer_uv.max.y, outer_uv.max.x, inner_uv.max.y));

	if (max_x)
		rectangle(vertices,
			bounds2f(inner_xy.max.x, inner_xy.min.y, outer_xy.max.x, inner_xy.max.y),
			bounds2f(inner_uv.max.x, inner_uv.max.y, outer_uv.max.x, inner_uv.min.y));

	if (max_x && max_y)
		rectangle(vertices,
			bounds2f(inner_xy.max.x, inner_xy.max.y, outer_xy.max.x, outer_xy.max.y),
			bounds2f(inner_uv.max.x, inner_uv.min.y, outer_uv.max.x, outer_uv.min.y));

}
コード例 #15
0
ファイル: textureshape.cpp プロジェクト: Novarisk/openwar
texturetile textureatlas::tile(int u0, int v0, int size_u, int size_v, int inset_u, int inset_v)
{
	bounds2f outer = bounds2f(u0, v0, u0 + size_u, v0 + size_v) / glm::vec2(size.x, size.y);
	bounds2f inner = outer.grow(-(float)inset_u / size.x, -(float)inset_v / size.y);
	return texturetile(outer, inner);
}
コード例 #16
0
ファイル: Viewport.cpp プロジェクト: openwar/openwar
bounds2f ScrollerViewport::GetVisibleBounds() const
{
	bounds2i bounds = GetViewportBounds();
	return bounds2f(0, 0, bounds.x().size(), bounds.y().size()) + _contentOffset;
}