Beispiel #1
0
void Plane::recalculateForPositionAndTime(glm::vec3 position, float time) {
	// We center plane at given position so there's always
	// water around us

	auto center = position;
	center.y = 0;

	glm::vec2 segmentSize(this->size.x / this->segments,
		this->size.y / this->segments);

	// Minimal coordinates water corner
	auto start = center - glm::vec3(this->size.x * 0.5f, 0, -this->size.y * 0.5f);

	// Variables to provide access to vertices array
	Vertex* allVertices = this->vertices.get();
	Vertex* p = 0;

	// Variables to store temporary vertex data
	glm::vec3 vertexPosition;
	glm::vec3 normal;
	glm::vec2 texcoord;

	for(int xpoint = 0; xpoint <= this->segments; ++xpoint) {
		for(int zpoint = 0; zpoint <= this->segments; ++zpoint) {
			// Get vertex pointer within the array
			p = allVertices + this->vertexIndex(xpoint, zpoint);

			// Calculate vertex position and normal
			vertexPosition = start + glm::vec3(xpoint * segmentSize.x, 0, -zpoint * segmentSize.y);
			vertexPosition.y = this->heightAtPositionAndTime(&vertexPosition, time);
			normal = this->normalAtPositionAndTime(&vertexPosition, time);
			texcoord = this->texcoordAtPositionAndTime(vertexPosition, time);

			// Copy to buffer
			memcpy(p->position, glm::value_ptr(vertexPosition), 3 * sizeof(float));
			memcpy(p->normal, glm::value_ptr(normal), 3 * sizeof(float));
			memcpy(p->texcoord, glm::value_ptr(texcoord), 2 * sizeof(float));
		}
	}
}
void EditorScreen::DrawSelectedSegment(sf::RenderWindow &Window, int segment, sf::Color color)
{
	sf::Rect<float> dRect;

	dRect.left = map->mapSeg[segment]->position.x - (scroll.x * map->layers[map->mapSeg[segment]->layer]->scale);
	dRect.top = map->mapSeg[segment]->position.y - (scroll.y * map->layers[map->mapSeg[segment]->layer]->scale);
	dRect.width = (float)map->segDef[map->mapSeg[segment]->segmentIndex]->width * map->mapSeg[segment]->scale.x;
	dRect.height = (float)map->segDef[map->mapSeg[segment]->segmentIndex]->height * map->mapSeg[segment]->scale.y;


	sf::RectangleShape segmentShape;
	segmentShape.setPosition(dRect.left, dRect.top);
	segmentShape.setRotation(map->mapSeg[segment]->rotation);
	segmentShape.setOrigin(dRect.width / 2, dRect.height / 2);
	
	sf::Vector2<float> segmentSize(dRect.width, dRect.height);
	
	segmentShape.setSize(segmentSize);
	segmentShape.setFillColor(sf::Color::Transparent);
	segmentShape.setOutlineColor(color);
	segmentShape.setOutlineThickness(1);
	Window.draw(segmentShape);
}
void EditorScreen::DrawToolBar(sf::RenderWindow &Window)
{
	sf::RectangleShape segmentShape;
	segmentShape.setPosition(0, 0);
	sf::Vector2<float> segmentSize(1280, 40);
	segmentShape.setSize(segmentSize);
	segmentShape.setFillColor(sf::Color(0,0,0,180));
	Window.draw(segmentShape);

	sf::Sprite toolbarSpacer;
	toolbarSpacer.setTexture(toolbarIconsTex);
	toolbarSpacer.setTextureRect(sf::Rect<int>(0, 2, 2, 30));

	int x = 5;

	if (DrawButton(Window, x, 5 , 0)) // New Map
		ResetMap();

	x = x + 35;
	if (DrawButton(Window, x, 5 , 2)) // Save Map
		SaveMap();

	x = x + 35;
	if (DrawButton(Window, x, 5 , 1)) // Load Map
		LoadMap();

	x = x + 35;
	if (DrawButton(Window, x, 5 , 3)) // Layer change
	{
		layerPane->minimized = !layerPane->minimized;
	}

	/*x = x + 35;
	if (DrawButton(Window, x, 5 , 4)) // Zoom out
	{
		map->zoomScale -= 0.05f;
		if (map->zoomScale < 0.1f) map->zoomScale = 0.1f;
	}

	x = x + 35;
	if (DrawButton(Window, x, 5 , 5)) // Zoom in
	{
		map->zoomScale += 0.05;
		if (map->zoomScale > 2.0f) map->zoomScale = 2.0f;
	}*/

	x = x + 40;
	toolbarSpacer.setPosition(x, 5);
	Window.draw(toolbarSpacer, sf::RenderStates::Default);
	
	x = x + 10;
	if (DrawButton(Window, x, 5 , 6)) // Segment drawing mode
	{
		drawingMode = (drawingMode_t)SEGMENT_SELECTION;
		ledgePane->minimized = true;
	}

	x = x + 35;
	if (DrawButton(Window, x, 5 , 7)) // Ledge drawing mode
	{
		drawingMode = (drawingMode_t)LEDGES;
		segmentPane->minimized = true;
		ledgePane->minimized = false;
	}

	x = x + 35;
	if (DrawButton(Window, x, 5 , 8)) // Collision drawing mode
	{
		
	}

	x = x + 40;
	toolbarSpacer.setPosition(x, 5);
	Window.draw(toolbarSpacer, sf::RenderStates::Default);

	x = x + 10;
	if (DrawButton(Window, x, 5 , 9)) // Test map
	{
		PlayTestScreen *screen = new PlayTestScreen;
		screen->SetMapData(map);
		ScreenManager::GetInstance().AddScreen(screen);
	}

}