Changeset cf2d1e5 in opengl-game for new-game.cpp
- Timestamp:
- Jun 14, 2018, 3:02:51 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 885f0bb, 8d5e67b
- Parents:
- c8dc5c6
- git-author:
- Dmitry Portnoy <dmp1488@…> (06/14/18 02:58:13)
- git-committer:
- Dmitry Portnoy <dmp1488@…> (06/14/18 03:02:51)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
rc8dc5c6 rcf2d1e5 63 63 64 64 #define NUM_KEYS (512) 65 #define ONE_DEG_IN_RAD ( 2.0 * M_PI) / 360.0// 0.017444444 (maybe make this a const instead)65 #define ONE_DEG_IN_RAD ((2.0f * M_PI) / 360.0f) // 0.017444444 (maybe make this a const instead) 66 66 67 67 const int KEY_STATE_UNCHANGED = -1; … … 139 139 map<GLuint, unsigned int>& curShaderBase); 140 140 void renderSceneGui(); 141 142 void spawnAsteroid(vec3 pos, GLuint shader); 141 143 142 144 int main(int argc, char* argv[]) { … … 289 291 mat4 T_model, R_model; 290 292 293 /* 291 294 // triangle 292 295 obj = SceneObject(); … … 372 375 373 376 addObjectToScene(obj); 377 */ 374 378 375 379 // player ship … … 609 613 0.0f, 0.0f, 0.3f, 610 614 611 0.0f, 0.0f, 0.3f,612 0.0f, 0.0f, 0.3f,613 0.0f, 0.0f, 0.3f,614 615 0.0f, 0.0f, 0.3f,616 0.0f, 0.0f, 0.3f,617 0.0f, 0.0f, 0.3f,618 619 0.0f, 0.0f, 0.3f,620 0.0f, 0.0f, 0.3f,621 0.0f, 0.0f, 0.3f,622 0.0f, 0.0f, 0.3f,623 0.0f, 0.0f, 0.3f,624 0.0f, 0.0f, 0.3f,625 626 0.0f, 0.0f, 0.3f,627 0.0f, 0.0f, 0.3f,628 0.0f, 0.0f, 0.3f,629 0.0f, 0.0f, 0.3f,630 0.0f, 0.0f, 0.3f,631 0.0f, 0.0f, 0.3f,632 633 0.0f, 0.0f, 0.3f,634 0.0f, 0.0f, 0.3f,635 0.0f, 0.0f, 0.3f,636 0.0f, 0.0f, 0.3f,637 0.0f, 0.0f, 0.3f,638 0.0f, 0.0f, 0.3f,639 640 0.0f, 0.0f, 0.3f,641 0.0f, 0.0f, 0.3f,642 0.0f, 0.0f, 0.3f,643 0.0f, 0.0f, 0.3f,644 0.0f, 0.0f, 0.3f,645 0.0f, 0.0f, 0.3f,615 0.0f, 0.0f, 1.0f, 616 0.0f, 0.0f, 1.0f, 617 0.0f, 0.0f, 1.0f, 618 619 0.0f, 0.0f, 1.0f, 620 0.0f, 0.0f, 1.0f, 621 0.0f, 0.0f, 1.0f, 622 623 0.0f, 0.0f, 1.0f, 624 0.0f, 0.0f, 1.0f, 625 0.0f, 0.0f, 1.0f, 626 0.0f, 0.0f, 1.0f, 627 0.0f, 0.0f, 1.0f, 628 0.0f, 0.0f, 1.0f, 629 630 0.0f, 0.0f, 1.0f, 631 0.0f, 0.0f, 1.0f, 632 0.0f, 0.0f, 1.0f, 633 0.0f, 0.0f, 1.0f, 634 0.0f, 0.0f, 1.0f, 635 0.0f, 0.0f, 1.0f, 636 637 0.0f, 0.0f, 1.0f, 638 0.0f, 0.0f, 1.0f, 639 0.0f, 0.0f, 1.0f, 640 0.0f, 0.0f, 1.0f, 641 0.0f, 0.0f, 1.0f, 642 0.0f, 0.0f, 1.0f, 643 644 0.0f, 0.0f, 1.0f, 645 0.0f, 0.0f, 1.0f, 646 0.0f, 0.0f, 1.0f, 647 0.0f, 0.0f, 1.0f, 648 0.0f, 0.0f, 1.0f, 649 0.0f, 0.0f, 1.0f, 646 650 647 651 0.0f, 0.0f, 0.3f, … … 741 745 0.0f, 0.0f, 0.3f, 742 746 }; 743 obj.texcoords = { 744 1.0f, 1.0f, 745 0.0f, 1.0f, 746 0.0f, 0.0f, 747 1.0f, 1.0f, 748 0.0f, 0.0f, 749 1.0f, 0.0f, 750 751 1.0f, 1.0f, 752 0.0f, 1.0f, 753 0.0f, 0.0f, 754 1.0f, 1.0f, 755 0.0f, 0.0f, 756 1.0f, 0.0f, 757 758 1.0f, 1.0f, 759 0.0f, 1.0f, 760 0.0f, 0.0f, 761 1.0f, 1.0f, 762 0.0f, 0.0f, 763 1.0f, 0.0f, 764 765 1.0f, 1.0f, 766 0.0f, 1.0f, 767 0.0f, 0.0f, 768 1.0f, 1.0f, 769 0.0f, 0.0f, 770 1.0f, 0.0f, 771 772 1.0f, 1.0f, 773 0.0f, 1.0f, 774 0.0f, 0.0f, 775 1.0f, 1.0f, 776 0.0f, 0.0f, 777 1.0f, 0.0f, 778 779 1.0f, 1.0f, 780 0.0f, 1.0f, 781 0.0f, 0.0f, 782 783 1.0f, 1.0f, 784 0.0f, 1.0f, 785 0.0f, 0.0f, 786 787 1.0f, 1.0f, 788 0.0f, 1.0f, 789 0.0f, 0.0f, 790 1.0f, 1.0f, 791 0.0f, 0.0f, 792 1.0f, 0.0f, 793 794 1.0f, 1.0f, 795 0.0f, 1.0f, 796 0.0f, 0.0f, 797 1.0f, 1.0f, 798 0.0f, 0.0f, 799 1.0f, 0.0f, 800 801 1.0f, 1.0f, 802 0.0f, 1.0f, 803 0.0f, 0.0f, 804 1.0f, 1.0f, 805 0.0f, 0.0f, 806 1.0f, 0.0f, 807 808 1.0f, 1.0f, 809 0.0f, 1.0f, 810 0.0f, 0.0f, 811 1.0f, 1.0f, 812 0.0f, 0.0f, 813 1.0f, 0.0f, 814 815 1.0f, 1.0f, 816 0.0f, 1.0f, 817 0.0f, 0.0f, 818 819 1.0f, 1.0f, 820 0.0f, 1.0f, 821 0.0f, 0.0f, 822 823 1.0f, 1.0f, 824 0.0f, 1.0f, 825 0.0f, 0.0f, 826 1.0f, 1.0f, 827 0.0f, 0.0f, 828 1.0f, 0.0f, 829 830 1.0f, 1.0f, 831 0.0f, 1.0f, 832 0.0f, 0.0f, 833 1.0f, 1.0f, 834 0.0f, 0.0f, 835 1.0f, 0.0f, 836 837 1.0f, 1.0f, 838 0.0f, 1.0f, 839 0.0f, 0.0f, 840 1.0f, 1.0f, 841 0.0f, 0.0f, 842 1.0f, 0.0f, 843 844 1.0f, 1.0f, 845 0.0f, 1.0f, 846 0.0f, 0.0f, 847 1.0f, 1.0f, 848 0.0f, 0.0f, 849 1.0f, 0.0f, 850 851 1.0f, 1.0f, 852 0.0f, 1.0f, 853 0.0f, 0.0f, 854 855 1.0f, 1.0f, 856 0.0f, 1.0f, 857 0.0f, 0.0f, 858 859 1.0f, 1.0f, 860 0.0f, 1.0f, 861 0.0f, 0.0f, 862 863 1.0f, 1.0f, 864 0.0f, 1.0f, 865 0.0f, 0.0f, 866 867 1.0f, 1.0f, 868 0.0f, 1.0f, 869 0.0f, 0.0f, 870 1.0f, 1.0f, 871 0.0f, 0.0f, 872 1.0f, 0.0f, 873 874 1.0f, 1.0f, 875 0.0f, 1.0f, 876 0.0f, 0.0f, 877 1.0f, 1.0f, 878 0.0f, 0.0f, 879 1.0f, 0.0f, 880 881 1.0f, 1.0f, 882 0.0f, 1.0f, 883 0.0f, 0.0f, 884 1.0f, 1.0f, 885 0.0f, 0.0f, 886 1.0f, 0.0f, 887 888 1.0f, 1.0f, 889 0.0f, 1.0f, 890 0.0f, 0.0f, 891 1.0f, 1.0f, 892 0.0f, 0.0f, 893 1.0f, 0.0f, 894 895 1.0f, 1.0f, 896 0.0f, 1.0f, 897 0.0f, 0.0f, 898 899 1.0f, 1.0f, 900 0.0f, 1.0f, 901 0.0f, 0.0f, 902 903 1.0f, 1.0f, 904 0.0f, 1.0f, 905 0.0f, 0.0f, 906 907 1.0f, 1.0f, 908 0.0f, 1.0f, 909 0.0f, 0.0f, 910 }; 911 obj.selected_colors = { 912 0.0f, 1.0f, 0.0f, 913 0.0f, 1.0f, 0.0f, 914 0.0f, 1.0f, 0.0f, 915 0.0f, 1.0f, 0.0f, 916 0.0f, 1.0f, 0.0f, 917 0.0f, 1.0f, 0.0f, 918 }; 919 920 T_model = translate(mat4(), vec3(0.0f, -0.9f, 0.0f)); 921 R_model = rotate(mat4(), 0.6f, vec3(1.0f, 0.0f, 0.0f)); 922 obj.model_base = T_model * R_model * scale(mat4(), vec3(0.3f, 0.3f, 0.3f));; 747 obj.texcoords = { 0.0f }; 748 obj.selected_colors = { 0.0f }; 749 750 T_model = translate(mat4(), vec3(0.0f, -1.2f, 0.0f)); 751 R_model = rotate(mat4(), 20.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 0.0f, 0.0f)); 752 R_model = mat4(); 753 obj.model_base = T_model * R_model * scale(mat4(), vec3(0.3f, 0.3f, 0.3f)); 923 754 924 755 addObjectToScene(obj); 756 757 spawnAsteroid(vec3(0.0f, -1.2f, -11.5f), color_sp); 758 spawnAsteroid(vec3(1.0f, -1.2f, -11.5f), color_sp); 759 spawnAsteroid(vec3(-0.5f, -0.7f, -10.8f), color_sp); 925 760 926 761 vector<SceneObject>::iterator obj_it; … … 1078 913 // reset the all key states to KEY_STATE_UNCHANGED (something the GLFW key callback can never return) 1079 914 // so that GLFW_PRESS and GLFW_RELEASE are only detected once 1080 // TODO: Change this if we ever need to act on GLFW_REPEAT (which is when a key is held down continuously) 915 // TODO: Change this if we ever need to act on GLFW_REPEAT (which is when a key is held down 916 // continuously for a period of time) 1081 917 fill(key_state, key_state + NUM_KEYS, KEY_STATE_UNCHANGED); 1082 918 … … 1099 935 1100 936 if (curState == STATE_GAME) { 937 /* 1101 938 if (clickedObject == &objects[0]) { 1102 939 selectedObject = &objects[0]; … … 1105 942 selectedObject = &objects[1]; 1106 943 } 944 */ 1107 945 1108 946 /* … … 1117 955 } 1118 956 */ 957 958 if (key_pressed[GLFW_KEY_RIGHT]) { 959 transformObject(objects[0], translate(mat4(), vec3(0.01f, 0.0f, 0.0f)), ubo); 960 } 961 if (key_pressed[GLFW_KEY_LEFT]) { 962 transformObject(objects[0], translate(mat4(), vec3(-0.01f, 0.0f, 0.0f)), ubo); 963 } 964 965 if (key_pressed[GLFW_KEY_DOWN]) { 966 transformObject(objects[1], translate(mat4(), vec3(0.0f, 0.0f, 0.17f)), ubo); 967 transformObject(objects[2], translate(mat4(), vec3(0.0f, 0.0f, 0.06f)), ubo); 968 transformObject(objects[3], translate(mat4(), vec3(0.0f, 0.0f, 0.11f)), ubo); 969 } 1119 970 } 1120 971 … … 1171 1022 cam_moved = true; 1172 1023 } 1024 /* 1173 1025 if (glfwGetKey(window, GLFW_KEY_LEFT)) { 1174 1026 cam_yaw += cam_yaw_speed * elapsed_seconds; … … 1187 1039 cam_moved = true; 1188 1040 } 1041 */ 1189 1042 if (cam_moved) { 1190 1043 T = translate(mat4(), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z)); … … 1700 1553 ImGui_ImplGlfwGL3_RenderDrawData(ImGui::GetDrawData()); 1701 1554 } 1555 1556 void spawnAsteroid(vec3 pos, GLuint shader) { 1557 SceneObject obj = SceneObject(); 1558 obj.shader_program = shader; 1559 1560 obj.points = { 1561 // front 1562 1.0f, 1.0f, 1.0f, 1563 -1.0f, 1.0f, 1.0f, 1564 -1.0f, -1.0f, 1.0f, 1565 1.0f, 1.0f, 1.0f, 1566 -1.0f, -1.0f, 1.0f, 1567 1.0f, -1.0f, 1.0f, 1568 1569 // top 1570 1.0f, 1.0f, -1.0f, 1571 -1.0f, 1.0f, -1.0f, 1572 -1.0f, 1.0f, 1.0f, 1573 1.0f, 1.0f, -1.0f, 1574 -1.0f, 1.0f, 1.0f, 1575 1.0f, 1.0f, 1.0f, 1576 1577 // bottom 1578 1.0f, -1.0f, 1.0f, 1579 -1.0f, -1.0f, 1.0f, 1580 -1.0f, -1.0f, -1.0f, 1581 1.0f, -1.0f, 1.0f, 1582 -1.0f, -1.0f, -1.0f, 1583 1.0f, -1.0f, -1.0f, 1584 1585 // back 1586 1.0f, 1.0f, -1.0f, 1587 -1.0f, -1.0f, -1.0f, 1588 -1.0f, 1.0f, -1.0f, 1589 1.0f, 1.0f, -1.0f, 1590 1.0f, -1.0f, -1.0f, 1591 -1.0f, -1.0f, -1.0f, 1592 1593 // right 1594 1.0f, 1.0f, -1.0f, 1595 1.0f, 1.0f, 1.0f, 1596 1.0f, -1.0f, 1.0f, 1597 1.0f, 1.0f, -1.0f, 1598 1.0f, -1.0f, 1.0f, 1599 1.0f, -1.0f, -1.0f, 1600 1601 // left 1602 -1.0f, 1.0f, 1.0f, 1603 -1.0f, 1.0f, -1.0f, 1604 -1.0f, -1.0f, -1.0f, 1605 -1.0f, 1.0f, 1.0f, 1606 -1.0f, -1.0f, -1.0f, 1607 -1.0f, -1.0f, 1.0f, 1608 }; 1609 obj.colors = { 1610 // front 1611 0.8f, 0.0f, 0.0f, 1612 0.8f, 0.0f, 0.0f, 1613 0.8f, 0.0f, 0.0f, 1614 0.8f, 0.0f, 0.0f, 1615 0.8f, 0.0f, 0.0f, 1616 0.8f, 0.0f, 0.0f, 1617 1618 // top 1619 0.8f, 0.0f, 0.0f, 1620 0.8f, 0.0f, 0.0f, 1621 0.8f, 0.0f, 0.0f, 1622 0.8f, 0.0f, 0.0f, 1623 0.8f, 0.0f, 0.0f, 1624 0.8f, 0.0f, 0.0f, 1625 1626 // bottom 1627 0.8f, 0.0f, 0.0f, 1628 0.8f, 0.0f, 0.0f, 1629 0.8f, 0.0f, 0.0f, 1630 0.8f, 0.0f, 0.0f, 1631 0.8f, 0.0f, 0.0f, 1632 0.8f, 0.0f, 0.0f, 1633 1634 // back 1635 0.8f, 0.0f, 0.0f, 1636 0.8f, 0.0f, 0.0f, 1637 0.8f, 0.0f, 0.0f, 1638 0.8f, 0.0f, 0.0f, 1639 0.8f, 0.0f, 0.0f, 1640 0.8f, 0.0f, 0.0f, 1641 1642 // right 1643 0.8f, 0.0f, 0.0f, 1644 0.8f, 0.0f, 0.0f, 1645 0.8f, 0.0f, 0.0f, 1646 0.8f, 0.0f, 0.0f, 1647 0.8f, 0.0f, 0.0f, 1648 0.8f, 0.0f, 0.0f, 1649 1650 // left 1651 0.8f, 0.0f, 0.0f, 1652 0.8f, 0.0f, 0.0f, 1653 0.8f, 0.0f, 0.0f, 1654 0.8f, 0.0f, 0.0f, 1655 0.8f, 0.0f, 0.0f, 1656 0.8f, 0.0f, 0.0f, 1657 }; 1658 obj.texcoords = { 0.0f }; 1659 obj.selected_colors = { 0.0f }; 1660 1661 mat4 T = translate(mat4(), pos); 1662 mat4 R = rotate(mat4(), 60.0f * (float)ONE_DEG_IN_RAD, vec3(1.0f, 1.0f, -1.0f)); 1663 obj.model_base = T * R * scale(mat4(), vec3(0.2f, 0.2f, 0.2f)); 1664 1665 addObjectToScene(obj); 1666 }
Note:
See TracChangeset
for help on using the changeset viewer.