Example #1
0
void Planet::generate() {
	m_test_image.create(m_circumference / 2 + 1, m_circumference / 2 + 1, sf::Color(0, 0, 0, 0));

	noise::module::Perlin myModule;
	myModule.SetSeed(m_seed);
	noise::utils::NoiseMapBuilderPlane heightMapBuilder;
	heightMapBuilder.SetSourceModule (myModule);
	heightMapBuilder.SetDestNoiseMap (heightMap);
	heightMapBuilder.SetDestSize (m_circumference / 2, m_circumference / 2);
	heightMapBuilder.SetBounds (0.0, 2.0, 0.0, 2.0);
	heightMapBuilder.Build();

	for (int i = 0; i < m_circumference / 2; ++i) {
		for (int j = 0; j < m_circumference / 2; ++j) {
			float x = i - m_circumference / 4;
			float y = j - m_circumference / 4;
			if (distance(sf::Vector2f(x, y), sf::Vector2f(0, 0)) <= m_circumference / 4) {
				float height = heightMap.GetValue(i, j);
				m_test_image.setPixel(i, j, colorByHeight(height));
			}
		}
	}

	generatePlanetSprite();
	generateHeightImage(360);

	m_test_texture.loadFromImage(m_test_image, sf::IntRect(0, 0, (int)(m_circumference / 2), (int)(m_circumference /2)));
	m_test_sprite.setTexture(m_test_texture);

	m_font.loadFromFile("arial.ttf");
	text.setFont(m_font);
	text.setCharacterSize(15);
	text.setString(m_name);
}
Example #2
0
void Planet::alterWaterLevel(const float delta) {
	m_waterLevel += delta;

	generatePlanetSprite();
	generateHeightImage(360);

	m_planet_texture.loadFromImage(m_planet_image, sf::IntRect(0, 0, (int)(m_radius * 2), (int)(m_radius * 2)));
	m_planet_sprite.setTexture(m_planet_texture);
}
Example #3
0
int main(){
	const char* srcPath ="src.bmp";
	const char* regionPath ="region.bmp";
	const char* constraintPath ="constraint.bmp";
	const char* fPath ="f.bmp";
	const char* resultPath ="result.bmp";
	IplImage *srcImg=loadImageAs8U3C(srcPath);
	IplImage *regionImg=loadImageAs8U1C(regionPath);
	IplImage *constraintImg=loadImageAs8U3C(constraintPath);
	IplImage *fImg=loadImageAs32F1C(fPath);
	IplImage *resultImg=generateHeightImage(srcImg->width,srcImg->height);
	poissonSmoothGL(srcImg,regionImg,constraintImg,fImg,resultImg);
	cvSaveImage(resultPath,resultImg);
	return 0;
}
Example #4
0
void Planet::beginContact(Entity *entity) {
	int craterSize = 40;

	float a = 180 + angle(entity->getPosition(), m_position);
	sf::Vector2f pos = makeVector(a, m_circumference / 4);

	for (int i = 0; i < craterSize; ++i) {
		for (int j = 0; j < craterSize; ++j) {
			int x = i + pos.x - craterSize / 2 + m_circumference / 4;
			int y = j + pos.y - craterSize / 2 + m_circumference / 4;
			int x2 = i - craterSize / 2;
			int y2 = j - craterSize / 2;
			if (distance(sf::Vector2f(x2, y2), sf::Vector2f(0, 0)) <= craterSize) {
				int z = sqrt(pow((float)(craterSize / 2), 2) - pow((float)x2, 2) - pow((float)y2, 2));
				heightMap.SetValue(x, y, heightMap.GetValue(x, y) - 100);
			}
		}
	}

	generatePlanetSprite();
	generateHeightImage(360);
}