ldtypes.cpp

changeset 63
aa40ce18f869
parent 62
915fc477cb6a
child 64
ada4679d5bce
equal deleted inserted replaced
62:915fc477cb6a 63:aa40ce18f869
189 // ============================================================================= 189 // =============================================================================
190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 190 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
191 // ============================================================================= 191 // =============================================================================
192 void LDQuad::splitToTriangles () { 192 void LDQuad::splitToTriangles () {
193 // Find the index of this quad 193 // Find the index of this quad
194 ulong ulIndex; 194 long lIndex = getIndex (g_CurrentFile);
195 for (ulIndex = 0; ulIndex < g_CurrentFile->objects.size(); ++ulIndex) 195
196 if (g_CurrentFile->objects[ulIndex] == this) 196 if (lIndex == -1) {
197 break;
198
199 if (ulIndex >= g_CurrentFile->objects.size()) {
200 // couldn't find it? 197 // couldn't find it?
201 logf (LOG_Error, "LDQuad::splitToTriangles: Couldn't find quad %p in " 198 logf (LOG_Error, "LDQuad::splitToTriangles: Couldn't find quad %p in "
202 "current object list!!\n", this); 199 "current object list!!\n", this);
203 return; 200 return;
204 } 201 }
224 // The triangles also inherit the quad's color 221 // The triangles also inherit the quad's color
225 tri1->dColor = tri2->dColor = dColor; 222 tri1->dColor = tri2->dColor = dColor;
226 223
227 // Replace the quad with the first triangle and add the second triangle 224 // Replace the quad with the first triangle and add the second triangle
228 // after the first one. 225 // after the first one.
229 g_CurrentFile->objects[ulIndex] = tri1; 226 g_CurrentFile->objects[lIndex] = tri1;
230 g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + ulIndex + 1, tri2); 227 g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + lIndex + 1, tri2);
231 228
232 // Delete this quad now, it has been split. 229 // Delete this quad now, it has been split.
233 delete this; 230 delete this;
234 } 231 }
235 232
278 275
279 // ============================================================================= 276 // =============================================================================
280 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 277 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
281 // ============================================================================= 278 // =============================================================================
282 static uint g_uTabs = 0; 279 static uint g_uTabs = 0;
283 vector<LDObject*> LDSubfile::inlineContents (double* matrix, vertex pos, bool bCache) { 280 vector<LDObject*> LDSubfile::inlineContents (bool bDeepInline, double* matrix, vertex pos, bool bCache) {
284 // If we have this cached, just return that. 281 // If we have this cached, just return that.
285 if (objCache.size ()) 282 if (bDeepInline && objCache.size ())
286 return objCache; 283 return objCache;
287 284
288 vector<LDObject*> objs; 285 vector<LDObject*> objs;
289 286
290 for (ulong i = 0; i < pFile->objects.size(); ++i) { 287 for (ulong i = 0; i < pFile->objects.size(); ++i) {
302 ADD_TYPE (Triangle, 3) 299 ADD_TYPE (Triangle, 3)
303 ADD_TYPE (Quad, 4) 300 ADD_TYPE (Quad, 4)
304 ADD_TYPE (CondLine, 4) 301 ADD_TYPE (CondLine, 4)
305 302
306 case OBJ_Subfile: 303 case OBJ_Subfile:
307 // Got another sub-file reference, inline it. 304 {
308 LDSubfile* ref = static_cast<LDSubfile*> (obj); 305 LDSubfile* ref = static_cast<LDSubfile*> (obj);
306
307 // Got another sub-file reference, inline it if we're deep-inlining. If not,
308 // just add it into the objects normally.
309 if (bDeepInline) {
310 double faNewMatrix[9];
311
312 for (short i = 0; i < 9; ++i)
313 faNewMatrix[i] = matrix[i] * ref->faMatrix[i];
314
315 vertex vNewPos = ref->vPosition;
316 vNewPos.transform (matrix, pos);
317
318 // Only cache immediate subfiles, this is not one. Yay recursion!
319 g_uTabs++;
320 vector<LDObject*> otherobjs = ref->inlineContents (true, faNewMatrix, vNewPos, false);
321 g_uTabs--;
322
323 for (ulong i = 0; i < otherobjs.size(); ++i)
324 objs.push_back (otherobjs[i]);
325 } else {
326 LDSubfile* clone = ref->makeClone ();
327 clone->vPosition.transform (matrix, pos);
328
329 for (short i = 0; i < 9; ++i)
330 clone->faMatrix[i] *= matrix[i];
331
332 objs.push_back (clone);
333 }
334 }
309 335
310 double faNewMatrix[9];
311
312 for (short i = 0; i < 9; ++i)
313 faNewMatrix[i] = matrix[i] * ref->faMatrix[i];
314
315 vertex vNewPos = ref->vPosition;
316 vNewPos.transform (matrix, pos);
317
318 // Only cache immediate subfiles, this is not one. Yay recursion!
319 g_uTabs++;
320 vector<LDObject*> otherobjs = ref->inlineContents (faNewMatrix, vNewPos, false);
321 g_uTabs--;
322
323 for (ulong i = 0; i < otherobjs.size(); ++i)
324 objs.push_back (otherobjs[i]);
325 break; 336 break;
326 } 337 }
327 } 338 }
328 339
329 // If we cache this stuff, keep it around 340 // If we cache this stuff, keep it around
330 if (bCache) 341 if (bCache)
331 objCache = objs; 342 objCache = objs;
332 343
333 return objs; 344 return objs;
334 } 345 }
346
347 // =============================================================================
348 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
349 // =============================================================================
350 long LDObject::getIndex (OpenFile* pFile) {
351 long lIndex;
352
353 for (lIndex = 0; lIndex < (long)pFile->objects.size(); ++lIndex)
354 if (pFile->objects[lIndex] == this)
355 return lIndex;
356
357 return -1;
358 }

mercurial