コード例 #1
0
ファイル: terrainfunction.cpp プロジェクト: highfestiva/life
void TerrainFunction::AddFunction(TerrainPatch& patch) const {
	// Read all frequently used data from pGrid.
	const vec2& world_south_west(patch.GetSouthWest());
	const vec2& world_north_east(patch.GetNorthEast());
	const int vertex_count_x = patch.GetVertexRes();
	const int vertex_count_y = patch.GetVertexRes();
	const float grid_width = patch.GetPatchSize();
	const float grid_height = patch.GetPatchSize();

	float a;

	// Calculate start X vertex index.
	int vertex_minimum_x;
	a = position_.x-outer_radius_;
	if (a <= world_south_west.x) {
		vertex_minimum_x = 0;
	} else {
		vertex_minimum_x = (int)::floor((a-world_south_west.x) * vertex_count_x / grid_width);
	}

	// Calculate end X vertex index.
	int vertex_maximum_x;
	a = position_.x+outer_radius_;
	if (a >= world_north_east.x) {
		vertex_maximum_x = vertex_count_x;
	} else {
		vertex_maximum_x = (int)::ceil((a-world_south_west.x) * vertex_count_x / grid_width);
	}

	// Calculate start Y vertex index.
	int vertex_minimum_y;
	a = position_.y-outer_radius_;
	if (a <= world_south_west.y) {
		vertex_minimum_y = 0;
	} else {
		vertex_minimum_y = (int)::floor((a-world_south_west.y) * vertex_count_y / grid_height);
	}

	// Calculate end Y vertex index.
	int vertex_maximum_y;
	a = position_.y+outer_radius_;
	if (a >= world_north_east.y) {
		vertex_maximum_y = vertex_count_y;
	} else {
		vertex_maximum_y = (int)::ceil((a-world_south_west.y) * vertex_count_y / grid_height);
	}

	patch.IterateOverPatch(*this, vertex_minimum_x, vertex_maximum_x, vertex_minimum_y, vertex_maximum_y);
}
コード例 #2
0
ファイル: terrainfunction.cpp プロジェクト: highfestiva/life
void TerrainFunctionGroup::AddFunctions(TerrainPatch& patch) const {
	// No optimizations like the ones in TerrainFunction are possible.
	patch.IterateOverPatch(*this, 0, patch.GetVertexRes(), 0, patch.GetVertexRes());
}