1 #include "Prism.h" 2 3 #include "radiant_i18n.h" 4 5 #include "gtkutil/dialog.h" 6 7 namespace brushconstruct 8 { getName() const9 const std::string Prism::getName () const 10 { 11 return "brushPrism"; 12 } 13 generate(Brush & brush,const AABB & bounds,std::size_t sides,const TextureProjection & projection,const std::string & shader)14 void Prism::generate (Brush& brush, const AABB& bounds, std::size_t sides, const TextureProjection& projection, 15 const std::string& shader) 16 { 17 if (sides < _minSides) { 18 gtkutil::errorDialog(_("Too few sides for constructing the prism, minimum is 3")); 19 return; 20 } 21 if (sides > _maxSides) { 22 gtkutil::errorDialog(_("Too many sides for constructing the prism")); 23 return; 24 } 25 26 brush.clear(); 27 brush.reserve(sides + 2); 28 29 Vector3 mins(bounds.origin - bounds.extents); 30 Vector3 maxs(bounds.origin + bounds.extents); 31 32 int axis = getViewAxis(); 33 float radius = getMaxExtent2D(bounds.extents, axis); 34 const Vector3& mid = bounds.origin; 35 Vector3 planepts[3]; 36 37 planepts[2][(axis + 1) % 3] = mins[(axis + 1) % 3]; 38 planepts[2][(axis + 2) % 3] = mins[(axis + 2) % 3]; 39 planepts[2][axis] = maxs[axis]; 40 planepts[1][(axis + 1) % 3] = maxs[(axis + 1) % 3]; 41 planepts[1][(axis + 2) % 3] = mins[(axis + 2) % 3]; 42 planepts[1][axis] = maxs[axis]; 43 planepts[0][(axis + 1) % 3] = maxs[(axis + 1) % 3]; 44 planepts[0][(axis + 2) % 3] = maxs[(axis + 2) % 3]; 45 planepts[0][axis] = maxs[axis]; 46 47 brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection); 48 49 planepts[0][(axis + 1) % 3] = mins[(axis + 1) % 3]; 50 planepts[0][(axis + 2) % 3] = mins[(axis + 2) % 3]; 51 planepts[0][axis] = mins[axis]; 52 planepts[1][(axis + 1) % 3] = maxs[(axis + 1) % 3]; 53 planepts[1][(axis + 2) % 3] = mins[(axis + 2) % 3]; 54 planepts[1][axis] = mins[axis]; 55 planepts[2][(axis + 1) % 3] = maxs[(axis + 1) % 3]; 56 planepts[2][(axis + 2) % 3] = maxs[(axis + 2) % 3]; 57 planepts[2][axis] = mins[axis]; 58 59 brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection); 60 61 for (std::size_t i = 0; i < sides; ++i) { 62 const double v = i * (M_PI * 2 / sides); 63 const double sv = sin(v); 64 const double cv = cos(v); 65 66 planepts[0][(axis + 1) % 3] = static_cast<float> (floor(mid[(axis + 1) % 3] + radius * cv + 0.5)); 67 planepts[0][(axis + 2) % 3] = static_cast<float> (floor(mid[(axis + 2) % 3] + radius * sv + 0.5)); 68 planepts[0][axis] = mins[axis]; 69 70 planepts[1][(axis + 1) % 3] = planepts[0][(axis + 1) % 3]; 71 planepts[1][(axis + 2) % 3] = planepts[0][(axis + 2) % 3]; 72 planepts[1][axis] = maxs[axis]; 73 74 planepts[2][(axis + 1) % 3] = static_cast<float> (floor(planepts[0][(axis + 1) % 3] - radius * sv + 0.5)); 75 planepts[2][(axis + 2) % 3] = static_cast<float> (floor(planepts[0][(axis + 2) % 3] + radius * cv + 0.5)); 76 planepts[2][axis] = maxs[axis]; 77 78 brush.addPlane(planepts[0], planepts[1], planepts[2], shader, projection); 79 } 80 } 81 } 82