MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / InitShape

Method InitShape

Source/Objects/group.cpp:163–214  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163void Group::InitShape() {
164 if (children.empty()) {
165 return;
166 }
167
168 for (auto& i : children) {
169 Object* obj = i.direct_ptr;
170 if (obj && (obj->GetType() == _group || obj->GetType() == _prefab) && !obj->Selected()) {
171 Group* child_group = (Group*)obj;
172 child_group->InitShape();
173 }
174 }
175
176 // Get bounding box points of children
177 static const int MAX_POINTS = 800;
178 int num_points = 0;
179 vec3 points[MAX_POINTS];
180 for (auto& i : children) {
181 if (num_points <= MAX_POINTS - 8) {
182 Object* obj = i.direct_ptr;
183 if (obj) {
184 // int index = 0;
185 for (int j = 0; j < 8; ++j) {
186 points[num_points + j] = obj->GetTransform() * obj->box_.GetPoint(j);
187 }
188 num_points += 8;
189 }
190 }
191 }
192
193 // Get axis-aligned bounds of child bbox points
194 vec3 min(FLT_MAX), max(-FLT_MAX);
195 for (int i = 0; i < num_points; ++i) {
196 for (int j = 0; j < 3; ++j) {
197 min[j] = std::min(min[j], points[i][j]);
198 max[j] = std::max(max[j], points[i][j]);
199 }
200 }
201
202 // Set group shape to axis-aligned bbox
203 SetRotation(quaternion());
204 SetTranslation((min + max) * 0.5f);
205 vec3 scale = max - min;
206 // Inflate scale so nested groups are within each other instead of overlapping
207 // (if InitShape() is called in order from child to parent)
208 // Also avoids scale[i] == 0.0 which can cause divide-by-zero elsewhere
209 static const float SCALE_INFLATE = 0.01f;
210 for (int i = 0; i < 3; ++i) {
211 scale[i] += SCALE_INFLATE * ((scale[i] < 0.0f) ? -1.0f : 1.0f);
212 }
213 SetScale(scale);
214}
215
216void Group::PreDrawFrame(float curr_game_time) {
217 if (g_debug_runtime_disable_group_pre_draw_frame) {

Callers 4

GroupSelectedMethod · 0.45
PrefabSelectedMethod · 0.45

Calls 8

maxFunction · 0.85
SelectedMethod · 0.80
quaternionClass · 0.70
minFunction · 0.50
emptyMethod · 0.45
GetTypeMethod · 0.45
GetTransformMethod · 0.45
GetPointMethod · 0.45

Tested by

no test coverage detected