Changeset 3d06b4e in opengl-game for new-game.cpp
- Timestamp:
- Jun 28, 2018, 3:14:22 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 58088c0
- Parents:
- dba67b2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
rdba67b2 r3d06b4e 47 47 vector<GLfloat> selected_colors; 48 48 bool deleted; 49 vec3 bounding_center; 50 GLfloat bounding_radius; 49 51 }; 50 52 … … 94 96 GLuint model_mat_idx_vbo); 95 97 void removeObjectFromScene(int objectId, GLuint ubo); 98 99 void calculateObjectBoundingBox(SceneObject& obj); 96 100 97 101 void initializeBuffers( … … 420 424 obj.points = { 421 425 //back 422 -0.5f, 0.3f,0.0f,423 -0.5f, 0.0f,0.0f,424 0.5f, 0.0f,0.0f,425 -0.5f, 0.3f,0.0f,426 0.5f, 0.0f,0.0f,427 0.5f, 0.3f,0.0f,426 -0.5f, 0.3f, 0.0f, 427 -0.5f, 0.0f, 0.0f, 428 0.5f, 0.0f, 0.0f, 429 -0.5f, 0.3f, 0.0f, 430 0.5f, 0.0f, 0.0f, 431 0.5f, 0.3f, 0.0f, 428 432 429 433 // left back 430 -0.5f, 0.3f,-2.0f,431 -0.5f, 0.0f,-2.0f,432 -0.5f, 0.0f,0.0f,433 -0.5f, 0.3f,-2.0f,434 -0.5f, 0.0f,0.0f,435 -0.5f, 0.3f,0.0f,434 -0.5f, 0.3f, -2.0f, 435 -0.5f, 0.0f, -2.0f, 436 -0.5f, 0.0f, 0.0f, 437 -0.5f, 0.3f, -2.0f, 438 -0.5f, 0.0f, 0.0f, 439 -0.5f, 0.3f, 0.0f, 436 440 437 441 // right back 438 0.5f, 0.3f,0.0f,439 0.5f, 0.0f,0.0f,440 0.5f, 0.0f,-2.0f,441 0.5f, 0.3f,0.0f,442 0.5f, 0.0f,-2.0f,443 0.5f, 0.3f,-2.0f,442 0.5f, 0.3f, 0.0f, 443 0.5f, 0.0f, 0.0f, 444 0.5f, 0.0f, -2.0f, 445 0.5f, 0.3f, 0.0f, 446 0.5f, 0.0f, -2.0f, 447 0.5f, 0.3f, -2.0f, 444 448 445 449 // left mid 446 -0.25f, 0.3f,-3.0f,447 -0.25f, 0.0f,-3.0f,448 -0.5f, 0.0f,-2.0f,449 -0.25f, 0.3f,-3.0f,450 -0.5f, 0.0f,-2.0f,451 -0.5f, 0.3f,-2.0f,450 -0.25f, 0.3f, -3.0f, 451 -0.25f, 0.0f, -3.0f, 452 -0.5f, 0.0f, -2.0f, 453 -0.25f, 0.3f, -3.0f, 454 -0.5f, 0.0f, -2.0f, 455 -0.5f, 0.3f, -2.0f, 452 456 453 457 // right mid 454 0.5f, 0.3f,-2.0f,455 0.5f, 0.0f,-2.0f,456 0.25f, 0.0f,-3.0f,457 0.5f, 0.3f,-2.0f,458 0.25f, 0.0f,-3.0f,459 0.25f, 0.3f,-3.0f,458 0.5f, 0.3f, -2.0f, 459 0.5f, 0.0f, -2.0f, 460 0.25f, 0.0f, -3.0f, 461 0.5f, 0.3f, -2.0f, 462 0.25f, 0.0f, -3.0f, 463 0.25f, 0.3f, -3.0f, 460 464 461 465 // left front 462 0.0f, 0.0f,-3.5f,463 -0.25f, 0.0f,-3.0f,464 -0.25f, 0.3f,-3.0f,466 0.0f, 0.0f, -3.5f, 467 -0.25f, 0.0f, -3.0f, 468 -0.25f, 0.3f, -3.0f, 465 469 466 470 // right front 467 0.25f, 0.3f,-3.0f,468 0.25f, 0.0f,-3.0f,469 0.0f, 0.0f,-3.5f,471 0.25f, 0.3f, -3.0f, 472 0.25f, 0.0f, -3.0f, 473 0.0f, 0.0f, -3.5f, 470 474 471 475 // top back 472 -0.5f, 0.3f,-2.0f,473 -0.5f, 0.3f,0.0f,474 0.5f, 0.3f,0.0f,475 -0.5f, 0.3f,-2.0f,476 0.5f, 0.3f,0.0f,477 0.5f, 0.3f,-2.0f,476 -0.5f, 0.3f, -2.0f, 477 -0.5f, 0.3f, 0.0f, 478 0.5f, 0.3f, 0.0f, 479 -0.5f, 0.3f, -2.0f, 480 0.5f, 0.3f, 0.0f, 481 0.5f, 0.3f, -2.0f, 478 482 479 483 // bottom back 480 -0.5f, 0.0f,0.0f,481 -0.5f, 0.0f,-2.0f,482 0.5f, 0.0f,0.0f,483 0.5f, 0.0f,0.0f,484 -0.5f, 0.0f,-2.0f,485 0.5f, 0.0f,-2.0f,484 -0.5f, 0.0f, 0.0f, 485 -0.5f, 0.0f, -2.0f, 486 0.5f, 0.0f, 0.0f, 487 0.5f, 0.0f, 0.0f, 488 -0.5f, 0.0f, -2.0f, 489 0.5f, 0.0f, -2.0f, 486 490 487 491 // top mid 488 -0.25f, 0.3f,-3.0f,489 -0.5f, 0.3f,-2.0f,490 0.5f, 0.3f,-2.0f,491 -0.25f, 0.3f,-3.0f,492 0.5f, 0.3f,-2.0f,493 0.25f, 0.3f,-3.0f,492 -0.25f, 0.3f, -3.0f, 493 -0.5f, 0.3f, -2.0f, 494 0.5f, 0.3f, -2.0f, 495 -0.25f, 0.3f, -3.0f, 496 0.5f, 0.3f, -2.0f, 497 0.25f, 0.3f, -3.0f, 494 498 495 499 // bottom mid 496 -0.5f, 0.0f,-2.0f,497 -0.25f, 0.0f,-3.0f,498 0.5f, 0.0f,-2.0f,499 0.5f, 0.0f,-2.0f,500 -0.25f, 0.0f,-3.0f,501 0.25f, 0.0f,-3.0f,500 -0.5f, 0.0f, -2.0f, 501 -0.25f, 0.0f, -3.0f, 502 0.5f, 0.0f, -2.0f, 503 0.5f, 0.0f, -2.0f, 504 -0.25f, 0.0f, -3.0f, 505 0.25f, 0.0f, -3.0f, 502 506 503 507 // top front 504 -0.25f, 0.3f,-3.0f,505 0.25f, 0.3f,-3.0f,506 0.0f, 0.0f,-3.5f,508 -0.25f, 0.3f, -3.0f, 509 0.25f, 0.3f, -3.0f, 510 0.0f, 0.0f, -3.5f, 507 511 508 512 // bottom front 509 0.25f, 0.0f,-3.0f,510 -0.25f, 0.0f,-3.0f,511 0.0f, 0.0f,-3.5f,513 0.25f, 0.0f, -3.0f, 514 -0.25f, 0.0f, -3.0f, 515 0.0f, 0.0f, -3.5f, 512 516 513 517 // left wing start back 514 -1.5f, 0.3f,0.0f,515 -1.5f, 0.0f,0.0f,516 -0.5f, 0.0f,0.0f,517 -1.5f, 0.3f,0.0f,518 -0.5f, 0.0f,0.0f,519 -0.5f, 0.3f,0.0f,518 -1.5f, 0.3f, 0.0f, 519 -1.5f, 0.0f, 0.0f, 520 -0.5f, 0.0f, 0.0f, 521 -1.5f, 0.3f, 0.0f, 522 -0.5f, 0.0f, 0.0f, 523 -0.5f, 0.3f, 0.0f, 520 524 521 525 // left wing start top 522 -0.5f, 0.3f,-0.3f,523 -1.3f, 0.3f,-0.3f,524 -1.5f, 0.3f,0.0f,525 -0.5f, 0.3f,-0.3f,526 -1.5f, 0.3f,0.0f,527 -0.5f, 0.3f,0.0f,526 -0.5f, 0.3f, -0.3f, 527 -1.3f, 0.3f, -0.3f, 528 -1.5f, 0.3f, 0.0f, 529 -0.5f, 0.3f, -0.3f, 530 -1.5f, 0.3f, 0.0f, 531 -0.5f, 0.3f, 0.0f, 528 532 529 533 // left wing start front 530 -0.5f, 0.3f,-0.3f,531 -0.5f, 0.0f,-0.3f,532 -1.3f, 0.0f,-0.3f,533 -0.5f, 0.3f,-0.3f,534 -1.3f, 0.0f,-0.3f,535 -1.3f, 0.3f,-0.3f,534 -0.5f, 0.3f, -0.3f, 535 -0.5f, 0.0f, -0.3f, 536 -1.3f, 0.0f, -0.3f, 537 -0.5f, 0.3f, -0.3f, 538 -1.3f, 0.0f, -0.3f, 539 -1.3f, 0.3f, -0.3f, 536 540 537 541 // left wing start bottom 538 -0.5f, 0.0f,0.0f,539 -1.5f, 0.0f,0.0f,540 -1.3f, 0.0f,-0.3f,541 -0.5f, 0.0f,0.0f,542 -1.3f, 0.0f,-0.3f,543 -0.5f, 0.0f,-0.3f,542 -0.5f, 0.0f, 0.0f, 543 -1.5f, 0.0f, 0.0f, 544 -1.3f, 0.0f, -0.3f, 545 -0.5f, 0.0f, 0.0f, 546 -1.3f, 0.0f, -0.3f, 547 -0.5f, 0.0f, -0.3f, 544 548 545 549 // left wing end outside 546 -1.5f, 0.3f,0.0f,547 -2.2f, 0.15f,-0.8f,548 -1.5f, 0.0f,0.0f,550 -1.5f, 0.3f, 0.0f, 551 -2.2f, 0.15f, -0.8f, 552 -1.5f, 0.0f, 0.0f, 549 553 550 554 // left wing end top 551 -1.3f, 0.3f,-0.3f,552 -2.2f, 0.15f,-0.8f,553 -1.5f, 0.3f,0.0f,555 -1.3f, 0.3f, -0.3f, 556 -2.2f, 0.15f, -0.8f, 557 -1.5f, 0.3f, 0.0f, 554 558 555 559 // left wing end front 556 -1.3f, 0.0f,-0.3f,557 -2.2f, 0.15f,-0.8f,558 -1.3f, 0.3f,-0.3f,560 -1.3f, 0.0f, -0.3f, 561 -2.2f, 0.15f, -0.8f, 562 -1.3f, 0.3f, -0.3f, 559 563 560 564 // left wing end bottom 561 -1.5f, 0.0f,0.0f,562 -2.2f, 0.15f,-0.8f,563 -1.3f, 0.0f,-0.3f,565 -1.5f, 0.0f, 0.0f, 566 -2.2f, 0.15f, -0.8f, 567 -1.3f, 0.0f, -0.3f, 564 568 565 569 // right wing start back 566 1.5f, 0.0f,0.0f,567 1.5f, 0.3f,0.0f,568 0.5f, 0.0f,0.0f,569 0.5f, 0.0f,0.0f,570 1.5f, 0.3f,0.0f,571 0.5f, 0.3f,0.0f,570 1.5f, 0.0f, 0.0f, 571 1.5f, 0.3f, 0.0f, 572 0.5f, 0.0f, 0.0f, 573 0.5f, 0.0f, 0.0f, 574 1.5f, 0.3f, 0.0f, 575 0.5f, 0.3f, 0.0f, 572 576 573 577 // right wing start top 574 1.3f, 0.3f,-0.3f,575 0.5f, 0.3f,-0.3f,576 1.5f, 0.3f,0.0f,577 1.5f, 0.3f,0.0f,578 0.5f, 0.3f,-0.3f,579 0.5f, 0.3f,0.0f,578 1.3f, 0.3f, -0.3f, 579 0.5f, 0.3f, -0.3f, 580 1.5f, 0.3f, 0.0f, 581 1.5f, 0.3f, 0.0f, 582 0.5f, 0.3f, -0.3f, 583 0.5f, 0.3f, 0.0f, 580 584 581 585 // right wing start front 582 0.5f, 0.0f,-0.3f,583 0.5f, 0.3f,-0.3f,584 1.3f, 0.0f,-0.3f,585 1.3f, 0.0f,-0.3f,586 0.5f, 0.3f,-0.3f,587 1.3f, 0.3f,-0.3f,586 0.5f, 0.0f, -0.3f, 587 0.5f, 0.3f, -0.3f, 588 1.3f, 0.0f, -0.3f, 589 1.3f, 0.0f, -0.3f, 590 0.5f, 0.3f, -0.3f, 591 1.3f, 0.3f, -0.3f, 588 592 589 593 // right wing start bottom 590 1.5f, 0.0f,0.0f,591 0.5f, 0.0f,0.0f,592 1.3f, 0.0f,-0.3f,593 1.3f, 0.0f,-0.3f,594 0.5f, 0.0f,0.0f,595 0.5f, 0.0f,-0.3f,594 1.5f, 0.0f, 0.0f, 595 0.5f, 0.0f, 0.0f, 596 1.3f, 0.0f, -0.3f, 597 1.3f, 0.0f, -0.3f, 598 0.5f, 0.0f, 0.0f, 599 0.5f, 0.0f, -0.3f, 596 600 597 601 // right wing end outside 598 2.2f, 0.15f,-0.8f,599 1.5f, 0.3f,0.0f,600 1.5f, 0.0f,0.0f,602 2.2f, 0.15f, -0.8f, 603 1.5f, 0.3f, 0.0f, 604 1.5f, 0.0f, 0.0f, 601 605 602 606 // right wing end top 603 2.2f, 0.15f,-0.8f,604 1.3f, 0.3f,-0.3f,605 1.5f, 0.3f,0.0f,607 2.2f, 0.15f, -0.8f, 608 1.3f, 0.3f, -0.3f, 609 1.5f, 0.3f, 0.0f, 606 610 607 611 // right wing end front 608 2.2f, 0.15f,-0.8f,609 1.3f, 0.0f,-0.3f,610 1.3f, 0.3f,-0.3f,612 2.2f, 0.15f, -0.8f, 613 1.3f, 0.0f, -0.3f, 614 1.3f, 0.3f, -0.3f, 611 615 612 616 // right wing end bottom 613 2.2f, 0.15f,-0.8f,614 1.5f, 0.0f,0.0f,615 1.3f, 0.0f,-0.3f,617 2.2f, 0.15f, -0.8f, 618 1.5f, 0.0f, 0.0f, 619 1.3f, 0.0f, -0.3f, 616 620 }; 617 621 obj.colors = { … … 816 820 ubo, 817 821 model_mat_idx_vbo); 818 819 /*820 spawnAsteroid(vec3(0.0f, -1.2f, -21.5f), color_sp,821 shaderBufferInfo,822 points_vbo,823 colors_vbo,824 selected_colors_vbo,825 texcoords_vbo,826 normals_vbo,827 ubo,828 model_mat_idx_vbo);829 spawnAsteroid(vec3(1.0f, -1.2f, -21.5f), color_sp,830 shaderBufferInfo,831 points_vbo,832 colors_vbo,833 selected_colors_vbo,834 texcoords_vbo,835 normals_vbo,836 ubo,837 model_mat_idx_vbo);838 spawnAsteroid(vec3(-0.5f, -1.2f, -20.8f), color_sp,839 shaderBufferInfo,840 points_vbo,841 colors_vbo,842 selected_colors_vbo,843 texcoords_vbo,844 normals_vbo,845 ubo,846 model_mat_idx_vbo);847 spawnAsteroid(vec3(-0.3f, -1.2f, -20.8f), color_sp,848 shaderBufferInfo,849 points_vbo,850 colors_vbo,851 selected_colors_vbo,852 texcoords_vbo,853 normals_vbo,854 ubo,855 model_mat_idx_vbo);856 spawnAsteroid(vec3(-0.1f, -1.2f, -20.8f), color_sp,857 shaderBufferInfo,858 points_vbo,859 colors_vbo,860 selected_colors_vbo,861 texcoords_vbo,862 normals_vbo,863 ubo,864 model_mat_idx_vbo);865 */866 822 867 823 GLuint vao = 0; … … 1373 1329 1374 1330 void addObjectToSceneDuringInit(SceneObject& obj) { 1331 // Each objects must have at least 3 points, so the size of 1332 // the points array must be a positive multiple of 9 1333 if (obj.points.size() == 0 || (obj.points.size() % 9) != 0) { 1334 return; 1335 } 1336 1375 1337 obj.id = objects.size(); // currently unused 1376 1338 obj.num_points = obj.points.size() / 3; … … 1393 1355 } 1394 1356 } 1357 1358 calculateObjectBoundingBox(obj); 1395 1359 1396 1360 objects.push_back(obj); … … 1410 1374 BufferInfo* bufferInfo = &shaderBufferInfo[obj.shader_program]; 1411 1375 1412 // Check if the buffers aren't large enough to fit the new object and, if so, print an error and quit.1413 // This is a temporary sanity check to make sure things are working as expected1376 // Check if the buffers aren't large enough to fit the new object and, if so, call 1377 // populateBuffers() to resize and repopupulate them 1414 1378 if (bufferInfo->vbo_capacity < (bufferInfo->ubo_offset + obj.num_points) || 1415 1379 bufferInfo->ubo_capacity < (bufferInfo->ubo_offset + 1)) { … … 1445 1409 } 1446 1410 1411 void calculateObjectBoundingBox(SceneObject& obj) { 1412 GLfloat min_x = obj.points[0]; 1413 GLfloat max_x = obj.points[0]; 1414 GLfloat min_y = obj.points[1]; 1415 GLfloat max_y = obj.points[1]; 1416 GLfloat min_z = obj.points[2]; 1417 GLfloat max_z = obj.points[2]; 1418 1419 // start from the second point 1420 for (int i = 3; i < obj.points.size(); i += 3) { 1421 if (min_x > obj.points[i]) { 1422 min_x = obj.points[i]; 1423 } 1424 else if (max_x < obj.points[i]) { 1425 max_x = obj.points[i]; 1426 } 1427 1428 if (min_y > obj.points[i + 1]) { 1429 min_y = obj.points[i + 1]; 1430 } 1431 else if (max_y < obj.points[i + 1]) { 1432 max_y = obj.points[i + 1]; 1433 } 1434 1435 if (min_z > obj.points[i + 2]) { 1436 min_z = obj.points[i + 2]; 1437 } 1438 else if (max_z < obj.points[i + 2]) { 1439 max_z = obj.points[i + 2]; 1440 } 1441 } 1442 1443 obj.bounding_center = vec3((min_x + max_x) / 2.0f, (min_y + max_y) / 2.0f, (min_z + max_z) / 2.0f); 1444 1445 GLfloat radius_x = max_x - obj.bounding_center.x; 1446 GLfloat radius_y = max_y - obj.bounding_center.y; 1447 GLfloat radius_z = max_z - obj.bounding_center.z; 1448 1449 obj.bounding_radius = radius_x; 1450 if (obj.bounding_radius < radius_y) 1451 obj.bounding_radius = radius_y; 1452 if (obj.bounding_radius < radius_z) 1453 obj.bounding_radius = radius_z; 1454 1455 for (int i = 0; i < obj.points.size(); i += 3) { 1456 obj.points[i] -= obj.bounding_center.x; 1457 obj.points[i + 1] -= obj.bounding_center.y; 1458 obj.points[i + 2] -= obj.bounding_center.z; 1459 } 1460 1461 obj.bounding_center = vec3(0.0f, 0.0f, 0.0f); 1462 } 1463 1447 1464 void initializeBuffers( 1448 1465 GLuint* points_vbo, … … 1626 1643 } 1627 1644 1628 obj.model_mat = obj.model_ base * obj.model_transform;1645 obj.model_mat = obj.model_transform * obj.model_base; 1629 1646 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 1630 1647 glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(obj.model_mat)); … … 1635 1652 1636 1653 void transformObject(SceneObject& obj, const mat4& transform, GLuint ubo) { 1637 obj.model_transform = obj.model_transform *transform;1654 obj.model_transform = transform * obj.model_transform; 1638 1655 obj.model_mat = obj.model_transform * obj.model_base; 1639 1656
Note:
See TracChangeset
for help on using the changeset viewer.