Changeset 95595de in opengl-game for new-game.cpp
- Timestamp:
- Jul 2, 2018, 2:48:01 AM (6 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- ebaa95c
- Parents:
- 58088c0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
r58088c0 r95595de 36 36 struct SceneObject { 37 37 unsigned int id; 38 39 // Currently, model_transform should only have translate, and rotation and scale need to be done in model_base since 40 // they need to be done when the object is at the origin. I should change this to have separate scale, rotate, and translate 41 // matrices for each object that can be updated independently and then applied to the object in that order. 38 42 mat4 model_mat, model_base, model_transform; 43 mat4 translate_mat; // beginning of doing what's mentioned above 39 44 GLuint shader_program; 40 45 unsigned int num_points; … … 95 100 GLuint ubo, 96 101 GLuint model_mat_idx_vbo); 97 void removeObjectFromScene( int objectId, GLuint ubo);102 void removeObjectFromScene(SceneObject& obj, GLuint ubo); 98 103 99 104 void calculateObjectBoundingBox(SceneObject& obj); … … 186 191 float FAR_CLIP = 100.0f; 187 192 188 // Should really have some array or struct of UI-related variables193 // TODO: Should really have some array or struct of UI-related variables 189 194 bool isRunning = true; 190 195 … … 795 800 obj.model_base = T_model * R_model * scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); 796 801 802 obj.translate_mat = T_model; 803 797 804 addObjectToSceneDuringInit(obj); 798 805 … … 951 958 952 959 frame_count++; 953 }954 955 elapsed_seconds_spawn += elapsed_seconds;956 if (elapsed_seconds_spawn > 0.5f) {957 spawnAsteroid(vec3(getRandomNum(-1.3f, 1.3f), getRandomNum(-3.0f, -1.0f), getRandomNum(-5.5f, -4.5f)), color_sp,958 shaderBufferInfo,959 points_vbo,960 colors_vbo,961 selected_colors_vbo,962 texcoords_vbo,963 normals_vbo,964 ubo,965 model_mat_idx_vbo);966 967 elapsed_seconds_spawn = 0.0f;968 960 } 969 961 … … 996 988 997 989 if (curState == STATE_GAME) { 990 991 elapsed_seconds_spawn += elapsed_seconds; 992 if (elapsed_seconds_spawn > 0.5f) { 993 spawnAsteroid(vec3(getRandomNum(-1.3f, 1.3f), getRandomNum(-3.0f, -1.0f), getRandomNum(-5.5f, -4.5f)), color_sp, 994 shaderBufferInfo, 995 points_vbo, 996 colors_vbo, 997 selected_colors_vbo, 998 texcoords_vbo, 999 normals_vbo, 1000 ubo, 1001 model_mat_idx_vbo); 1002 1003 elapsed_seconds_spawn -= 0.5f; 1004 } 1005 998 1006 /* 999 1007 if (clickedObject == &objects[0]) { … … 1027 1035 if (!objects[i].deleted) { 1028 1036 transformObject(objects[i], translate(mat4(1.0f), vec3(0.0f, 0.0f, 0.04f)), ubo); 1037 1038 // TODO: Should really compare against the near clipping plane, but also account for 1039 // the camera's translation and rotation 1040 if (objects[i].bounding_center.z - objects[i].bounding_radius > 3.0f) { 1041 removeObjectFromScene(objects[i], ubo); 1042 } 1029 1043 } 1030 1044 } 1031 1045 1032 1046 if (key_state[GLFW_KEY_SPACE] == GLFW_PRESS) { 1033 removeObjectFromScene( 0, ubo);1047 removeObjectFromScene(objects[0], ubo); 1034 1048 } 1035 1049 } … … 1357 1371 1358 1372 calculateObjectBoundingBox(obj); 1373 1374 obj.bounding_center = vec3(obj.translate_mat * vec4(obj.bounding_center, 1.0f)); 1359 1375 1360 1376 objects.push_back(obj); … … 1398 1414 } 1399 1415 1400 void removeObjectFromScene(int objectId, GLuint ubo) { 1401 SceneObject& obj = objects[objectId]; 1402 1416 void removeObjectFromScene(SceneObject& obj, GLuint ubo) { 1403 1417 if (!obj.deleted) { 1404 1418 // Move the object outside the render bounds of the scene so it doesn't get rendered … … 1447 1461 GLfloat radius_z = max_z - obj.bounding_center.z; 1448 1462 1463 // This actually underestimates the radius. Might need to be fixed at some point. 1449 1464 obj.bounding_radius = radius_x; 1450 1465 if (obj.bounding_radius < radius_y) … … 1655 1670 obj.model_mat = obj.model_transform * obj.model_base; 1656 1671 1672 obj.bounding_center = vec3(transform * vec4(obj.bounding_center, 1.0f)); 1673 1657 1674 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 1658 1675 glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(obj.model_mat)); … … 1896 1913 obj.model_base = T * R * scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f)); 1897 1914 1915 obj.translate_mat = T; 1916 1898 1917 addObjectToScene(obj, shaderBufferInfo, 1899 1918 points_vbo,
Note:
See TracChangeset
for help on using the changeset viewer.