MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ generate_rectangle()

std::vector< glm::vec3 > MayaFlux::Kinesis::generate_rectangle ( const glm::vec3 &  center,
float  width,
float  height,
const glm::vec3 &  normal = glm::vec3(0, 0, 1) 
)

Generate vertices of an axis-aligned rectangular path.

Parameters
centerRectangle centroid
widthExtent along local X axis
heightExtent along local Y axis
normalRectangle plane normal
Returns
5 vertices (closed rectangular path for LINE_STRIP)

Definition at line 90 of file GeometryPrimitives.cpp.

95{
96 glm::vec3 n = glm::normalize(normal);
97 glm::vec3 u;
98
99 if (std::abs(n.z) < 0.9F) {
100 u = glm::normalize(glm::cross(n, glm::vec3(0, 0, 1)));
101 } else {
102 u = glm::normalize(glm::cross(n, glm::vec3(1, 0, 0)));
103 }
104
105 glm::vec3 v = glm::cross(n, u);
106
107 float half_width = width * 0.5F;
108 float half_height = height * 0.5F;
109
110 std::vector<glm::vec3> vertices;
111 vertices.reserve(5);
112
113 vertices.push_back(center - half_width * u - half_height * v);
114
115 vertices.push_back(center + half_width * u - half_height * v);
116
117 vertices.push_back(center + half_width * u + half_height * v);
118
119 vertices.push_back(center - half_width * u + half_height * v);
120
121 vertices.push_back(vertices[0]);
122
123 return vertices;
124}