float PluginAudioProcessor::getParameter (int index)
{
	switch (index) {
		case noteLengthParam: 
			return getLerp (sequencer->getNoteLength(), 0, sequencer->getMaxNoteLength(), 0, 1.0);
		case swingTicksParam: 
			return getLerp (sequencer->getSwingTicks(), 0, sequencer->getMaxSwingTicks(), 0, 1.0);
		default:        return 0.0f;
	}
}
void PluginAudioProcessor::setParameter (int index, float newValue)
{
	switch (index) {
		case noteLengthParam: 
			newValue = getLerp (newValue, 0, 1.0, 0, sequencer->getMaxNoteLength());
			sequencer->setNoteLength (newValue); break;
		case swingTicksParam: 
			newValue = getLerp (newValue, 0, 1.0, 0, sequencer->getMaxSwingTicks());
			sequencer->setSwingTicks (newValue); break;
		default:        break;
	}	
}
Example #3
0
float MapgenCarpathian::terrainLevelAtPoint(s16 x, s16 z)
{
	float ground = NoisePerlin2D(&noise_base->np, x, z, seed);
	float height1 = NoisePerlin2D(&noise_height1->np, x, z, seed);
	float height2 = NoisePerlin2D(&noise_height2->np, x, z, seed);
	float height3 = NoisePerlin2D(&noise_height3->np, x, z, seed);
	float height4 = NoisePerlin2D(&noise_height4->np, x, z, seed);
	float hter = NoisePerlin2D(&noise_hills_terrain->np, x, z, seed);
	float rter = NoisePerlin2D(&noise_ridge_terrain->np, x, z, seed);
	float ster = NoisePerlin2D(&noise_step_terrain->np, x, z, seed);
	float n_hills = NoisePerlin2D(&noise_hills->np, x, z, seed);
	float n_ridge_mnt = NoisePerlin2D(&noise_ridge_mnt->np, x, z, seed);
	float n_step_mnt = NoisePerlin2D(&noise_step_mnt->np, x, z, seed);

	int height = -MAX_MAP_GENERATION_LIMIT;

	for (s16 y = 1; y <= 30; y++) {
		float mnt_var = NoisePerlin3D(&noise_mnt_var->np, x, y, z, seed);

		// Gradient & shallow seabed
		s32 grad = (y < water_level) ? grad_wl + (water_level - y) * 3 : 1 - y;

		// Hill/Mountain height (hilliness)
		float hill1 = getLerp(height1, height2, mnt_var);
		float hill2 = getLerp(height3, height4, mnt_var);
		float hill3 = getLerp(height3, height2, mnt_var);
		float hill4 = getLerp(height1, height4, mnt_var);
		float hilliness = std::fmax(std::fmin(hill1, hill2), std::fmin(hill3, hill4));

		// Rolling hills
		float hill_mnt = hilliness * pow(n_hills, 2.f);
		float hills = pow(hter, 3.f) * hill_mnt;

		// Ridged mountains
		float ridge_mnt = hilliness * (1.f - fabs(n_ridge_mnt));
		float ridged_mountains = pow(rter, 3.f) * ridge_mnt;

		// Step (terraced) mountains
		float step_mnt = hilliness * getSteps(n_step_mnt);
		float step_mountains = pow(ster, 3.f) * step_mnt;

		// Final terrain level
		float mountains = hills + ridged_mountains + step_mountains;
		float surface_level = ground + mountains + grad;

		if (y > surface_level && height < 0)
			height = y;
	}

	return height;
}
Example #4
0
int MapgenCarpathian::generateTerrain()
{
	MapNode mn_air(CONTENT_AIR);
	MapNode mn_stone(c_stone);
	MapNode mn_water(c_water_source);

	s16 stone_surface_max_y = -MAX_MAP_GENERATION_LIMIT;
	u32 index2d = 0;
	u32 index3d = 0;

	// Calculate noise for terrain generation
	noise_base->perlinMap2D(node_min.X, node_min.Z);
	noise_height1->perlinMap2D(node_min.X, node_min.Z);
	noise_height2->perlinMap2D(node_min.X, node_min.Z);
	noise_height3->perlinMap2D(node_min.X, node_min.Z);
	noise_height4->perlinMap2D(node_min.X, node_min.Z);
	noise_hills_terrain->perlinMap2D(node_min.X, node_min.Z);
	noise_ridge_terrain->perlinMap2D(node_min.X, node_min.Z);
	noise_step_terrain->perlinMap2D(node_min.X, node_min.Z);
	noise_hills->perlinMap2D(node_min.X, node_min.Z);
	noise_ridge_mnt->perlinMap2D(node_min.X, node_min.Z);
	noise_step_mnt->perlinMap2D(node_min.X, node_min.Z);
	noise_mnt_var->perlinMap3D(node_min.X, node_min.Y - 1, node_min.Z);

	//// Place nodes
	for (s16 z = node_min.Z; z <= node_max.Z; z++) {
		for (s16 y = node_min.Y - 1; y <= node_max.Y + 1; y++) {
			u32 vi = vm->m_area.index(node_min.X, y, z);
			for (s16 x = node_min.X; x <= node_max.X;
					x++, vi++, index2d++, index3d++) {
				if (vm->m_data[vi].getContent() != CONTENT_IGNORE)
					continue;

				// Base terrain
				float ground = noise_base->result[index2d];

				// Gradient & shallow seabed
				s32 grad = (y < water_level) ? grad_wl + (water_level - y) * 3 : 1 - y;

				// Hill/Mountain height (hilliness)
				float height1 = noise_height1->result[index2d];
				float height2 = noise_height2->result[index2d];
				float height3 = noise_height3->result[index2d];
				float height4 = noise_height4->result[index2d];
				float mnt_var = noise_mnt_var->result[index3d];
				// Combine height noises and apply 3D variation
				float hill1 = getLerp(height1, height2, mnt_var);
				float hill2 = getLerp(height3, height4, mnt_var);
				float hill3 = getLerp(height3, height2, mnt_var);
				float hill4 = getLerp(height1, height4, mnt_var);
				// 'hilliness' determines whether hills/mountains are
				// small or large
				float hilliness = std::fmax(std::fmin(hill1, hill2), std::fmin(hill3, hill4));

				// Rolling hills
				float hter = noise_hills_terrain->result[index2d];
				float n_hills = noise_hills->result[index2d];
				float hill_mnt = hilliness * pow(n_hills, 2.f);
				float hills = pow(fabs(hter), 3.f) * hill_mnt;

				// Ridged mountains
				float rter = noise_ridge_terrain->result[index2d];
				float n_ridge_mnt = noise_ridge_mnt->result[index2d];
				float ridge_mnt = hilliness * (1.f - fabs(n_ridge_mnt));
				float ridged_mountains = pow(fabs(rter), 3.f) * ridge_mnt;

				// Step (terraced) mountains
				float ster = noise_step_terrain->result[index2d];
				float n_step_mnt = noise_step_mnt->result[index2d];
				float step_mnt = hilliness * getSteps(n_step_mnt);
				float step_mountains = pow(fabs(ster), 3.f) * step_mnt;

				// Final terrain level
				float mountains = hills + ridged_mountains + step_mountains;
				float surface_level = ground + mountains + grad;

				if (y < surface_level) {
					vm->m_data[vi] = mn_stone; // Stone
					if (y > stone_surface_max_y)
						stone_surface_max_y = y;
				} else if (y <= water_level) {
					vm->m_data[vi] = mn_water; // Sea water
				} else {
					vm->m_data[vi] = mn_air; // Air
				}
			}
			index2d -= ystride;
		}
		index2d += ystride;
	}

	return stone_surface_max_y;
}