+const std::size_t c_brushRock_minSides = 10;
+const std::size_t c_brushRock_maxSides = 1000;
+const char* const c_brushRock_name = "brushRock";
+
+void Brush_ConstructRock(Brush& brush, const AABB& bounds, std::size_t sides, const char* shader, const TextureProjection& projection)
+{
+ if(sides < c_brushRock_minSides)
+ {
+ globalErrorStream() << c_brushRock_name << ": sides " << Unsigned(sides) << ": too few sides, minimum is " << Unsigned(c_brushRock_minSides) << "\n";
+ return;
+ }
+ if(sides > c_brushRock_maxSides)
+ {
+ globalErrorStream() << c_brushRock_name << ": sides " << Unsigned(sides) << ": too many sides, maximum is " << Unsigned(c_brushRock_maxSides) << "\n";
+ return;
+ }
+
+ brush.clear();
+ brush.reserve(sides*sides);
+
+ float radius = max_extent(bounds.extents);
+ const Vector3& mid = bounds.origin;
+ Vector3 planepts[3];
+
+ for(std::size_t j=0;j < sides; j++)
+ {
+ planepts[0][0] = rand() - (RAND_MAX/2);
+ planepts[0][1] = rand() - (RAND_MAX/2);
+ planepts[0][2] = rand() - (RAND_MAX/2);
+ vector3_normalise(planepts[0]);
+
+ // find two vectors that are perpendicular to planepts[0]
+ ComputeAxisBase(planepts[0], planepts[1], planepts[2]);
+
+ planepts[0] = vector3_added(mid, vector3_scaled(planepts[0], radius));
+ planepts[1] = vector3_added(planepts[0], vector3_scaled(planepts[1], radius));
+ planepts[2] = vector3_added(planepts[0], vector3_scaled(planepts[2], radius));
+
+#if 0
+ // make sure the orientation is right
+ if(vector3_dot(vector3_subtracted(planepts[0], mid), vector3_cross(vector3_subtracted(planepts[1], mid), vector3_subtracted(planepts[2], mid))) > 0)
+ {
+ Vector3 h;
+ h = planepts[1];
+ planepts[1] = planepts[2];
+ planepts[2] = h;
+ globalOutputStream() << "flip\n";
+ }
+ else
+ globalOutputStream() << "no flip\n";
+#endif
+
+ brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection);
+ }
+}
+