Changeset 1268 for trunk/orbital/mesh.h
 Timestamp:
 Apr 22, 2012, 2:31:52 AM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/orbital/mesh.h
r1267 r1268 4 4 // Copyright: (c) 2012 Various People 5 5 // 6 7 /* TODO for this file: 8 *  rename "AppendQuadVert" to "AddVertex" or something; it has nothing 9 * to do with quads. 10 */ 6 11 7 12 #if !defined __MESH_H__ … … 19 24 { 20 25 m_vert_cursor = m_vert.Count(); 21 ComputeQuadNormals(m_quadidx_cursor,22 m_quadidx.Count()  m_quadidx_cursor);23 26 m_quadidx_cursor = m_quadidx.Count(); 24 ComputeTriNormals(m_triidx_cursor,25 m_triidx.Count()  m_triidx_cursor);26 27 m_triidx_cursor = m_triidx.Count(); 27 28 } … … 213 214 void AppendTriangle(int i1, int i2, int i3, int base) 214 215 { 215 m_ quadidx += base + i1;216 m_ quadidx += base + i2;217 m_ quadidx += base + i3;216 m_triidx += base + i1; 217 m_triidx += base + i2; 218 m_triidx += base + i3; 218 219 } 219 220 220 221 void AppendTriangleDuplicateVerts(int i1, int i2, int i3, int base) 221 222 { 222 m_ quadidx += m_vert.Count(); AppendDuplicateQuadVert(base + i1);223 m_ quadidx += m_vert.Count(); AppendDuplicateQuadVert(base + i2);224 m_ quadidx += m_vert.Count(); AppendDuplicateQuadVert(base + i3);223 m_triidx += m_vert.Count(); AppendDuplicateQuadVert(base + i1); 224 m_triidx += m_vert.Count(); AppendDuplicateQuadVert(base + i2); 225 m_triidx += m_vert.Count(); AppendDuplicateQuadVert(base + i3); 225 226 } 226 227 … … 244 245 for (int i = 0; i < vcount; i += 3) 245 246 { 246 vec3 v0 = m_vert[m_ quadidx[start + i + 2]].m1247  m_vert[m_ quadidx[start + i + 0]].m1;248 vec3 v1 = m_vert[m_ quadidx[start + i + 1]].m1249  m_vert[m_ quadidx[start + i + 0]].m1;247 vec3 v0 = m_vert[m_triidx[start + i + 2]].m1 248  m_vert[m_triidx[start + i + 0]].m1; 249 vec3 v1 = m_vert[m_triidx[start + i + 1]].m1 250  m_vert[m_triidx[start + i + 0]].m1; 250 251 vec3 n = normalize(cross(v1, v0)); 251 252 252 253 for (int j = 0; j < 3; j++) 253 m_vert[m_ quadidx[start + i + j]].m2 = n;254 m_vert[m_triidx[start + i + j]].m2 = n; 254 255 } 255 256 } … … 409 410 void AppendBox(vec3 const &size) 410 411 { 411 AppendBox(size, 0.f); 412 } 413 414 void AppendBox(vec3 const &size, float chamf) 415 { 416 int ibase = m_quadidx.Count(); 412 AppendBox(size, 0.f, false); 413 } 414 415 void AppendSmoothChamfBox(vec3 const &size, float chamf) 416 { 417 AppendBox(size, chamf, true); 418 } 419 420 void AppendFlatChamfBox(vec3 const &size, float chamf) 421 { 422 AppendBox(size, chamf, false); 423 } 424 425 void AppendBox(vec3 const &size, float chamf, bool smooth) 426 { 417 427 int vbase = m_vert.Count(); 428 int qibase = m_quadidx.Count(); 429 int tibase = m_triidx.Count(); 418 430 419 431 vec3 d = size * 0.5f; … … 449 461 AppendQuadVert(vec3(+d.x, +d.y + chamf, d.z)); 450 462 451 AppendQuad(0, 1, 2, 3, vbase); 452 AppendQuad(4, 5, 6, 7, vbase); 453 AppendQuad(8, 9, 10, 11, vbase); 454 AppendQuad(12, 13, 14, 15, vbase); 455 AppendQuad(16, 17, 18, 19, vbase); 456 AppendQuad(20, 21, 22, 23, vbase); 457 458 ComputeQuadNormals(ibase, m_quadidx.Count()  ibase); 459 } 463 /* The 6 quads on each side of the box */ 464 for (int i = 0; i < 24; i += 4) 465 AppendQuad(i, i + 1, i + 2, i + 3, vbase); 466 467 ComputeQuadNormals(qibase, m_quadidx.Count()  qibase); 468 qibase = m_quadidx.Count(); 469 470 if (chamf) 471 { 472 /* The 8 quads at each edge of the box */ 473 static int const quadlist[48] = 474 { 475 0, 3, 18, 17, 4, 7, 17, 16, 8, 11, 16, 19, 12, 15, 19, 18, 476 2, 1, 20, 23, 6, 5, 21, 20, 10, 9, 22, 21, 14, 13, 23, 22, 477 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, 3, 2, 478 }; 479 480 for (int i = 0; i < 48; i += 4) 481 { 482 if (smooth) 483 AppendQuad(quadlist[i], quadlist[i + 1], 484 quadlist[i + 2], quadlist[i + 3], vbase); 485 else 486 AppendQuadDuplicateVerts(quadlist[i], quadlist[i + 1], 487 quadlist[i + 2], quadlist[i + 3], vbase); 488 } 489 490 /* The 8 triangles at each corner of the box */ 491 static int const trilist[24] = 492 { 493 3, 12, 18, 15, 8, 19, 11, 4, 16, 7, 0, 17, 494 2, 23, 13, 14, 22, 9, 10, 21, 5, 6, 20, 1, 495 }; 496 497 for (int i = 0; i < 24; i += 3) 498 { 499 if (smooth) 500 AppendTriangle(trilist[i], trilist[i + 1], 501 trilist[i + 2], vbase); 502 else 503 AppendTriangleDuplicateVerts(trilist[i], trilist[i + 1], 504 trilist[i + 2], vbase); 505 } 506 } 507 508 if (!smooth) 509 { 510 ComputeQuadNormals(qibase, m_quadidx.Count()  qibase); 511 ComputeTriNormals(tibase, m_triidx.Count()  tibase); 512 } 513 } 514 515 void AppendStar(int nbranches, float r1, float r2) 516 { 517 AppendStar(nbranches, r1, r2, 0, 0); 518 } 519 520 void AppendStar(int nbranches, float r1, float r2, int fade) 521 { 522 AppendStar(nbranches, r1, r2, fade, 0); 523 } 524 525 void AppendStar(int nbranches, float r1, float r2, int fade, int fade2) 526 { 527 int vbase = m_vert.Count(); 528 529 AppendQuadVert(vec3(0.f, 0.f, 0.f)); 530 531 /* FIXME: use mat3 instead of mat4 when it's working */ 532 mat3 rotmat(mat4::rotate(180.0f / nbranches, 0.f, 1.f, 0.f)); 533 vec3 p1(r1, 0.f, 0.f), p2(r2, 0.f, 0.f); 534 535 p2 = rotmat * p2; 536 rotmat = rotmat * rotmat; 537 538 for (int i = 0; i < nbranches; i++) 539 { 540 AppendQuadVert(p1); 541 if (fade2) 542 SetCurVertColor(m_color2); 543 544 AppendQuadVert(p2); 545 if (fade) 546 SetCurVertColor(m_color2); 547 548 AppendQuad(0, (2 * i + 3) % (2 * nbranches), 549 2 * i + 2, 2 * i + 1, vbase); 550 551 p1 = rotmat * p1; 552 p2 = rotmat * p2; 553 } 554 } 555 556 void AppendExpandedStar() {} /* TODO */ 557 void AppendDisc() {} /* TODO */ 558 void AppendSimpleTriangle() {} /* TODO */ 559 void AppendSimpleQuad() {} /* TODO */ 560 void AppendCog() {} /* TODO */ 460 561 461 562 private:
Note: See TracChangeset
for help on using the changeset viewer.