Changeset 5c403fe in opengl-game
- Timestamp:
- Jun 10, 2018, 10:17:10 PM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 809ce16
- Parents:
- f7d35da
- git-author:
- Dmitry Portnoy <dmp1488@…> (06/10/18 22:17:05)
- git-committer:
- Dmitry Portnoy <dmp1488@…> (06/10/18 22:17:10)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
rf7d35da r5c403fe 39 39 struct SceneObject { 40 40 unsigned int id; 41 mat4 model_mat ;41 mat4 model_mat, model_base, model_transform; 42 42 GLuint shader_program; 43 43 unsigned int num_points; 44 44 GLint vertex_vbo_offset; 45 GLint ubo_offset; 45 46 vector<GLfloat> points; 46 47 vector<GLfloat> colors; … … 123 124 map<GLuint, unsigned int>& shaderCounts, 124 125 map<GLuint, unsigned int>& curShaderBase); 126 127 void transformObject(SceneObject& obj, const mat4& transform, GLuint ubo); 125 128 126 129 void renderMainMenu(); … … 324 327 T_model = translate(mat4(), vec3(0.45f, 0.0f, 0.0f)); 325 328 R_model = rotate(mat4(), 0.0f, vec3(0.0f, 1.0f, 0.0f)); 326 obj.model_ mat= T_model*R_model;329 obj.model_base = T_model*R_model; 327 330 328 331 addObjectToScene(obj); … … 366 369 T_model = translate(mat4(), vec3(-0.5f, 0.0f, -1.00f)); 367 370 R_model = rotate(mat4(), 0.5f, vec3(0.0f, 1.0f, 0.0f)); 368 obj.model_ mat= T_model*R_model;371 obj.model_base = T_model*R_model; 369 372 370 373 addObjectToScene(obj); … … 408 411 T_model = translate(mat4(), vec3(0.0f, -0.9f, 0.0f)); 409 412 R_model = rotate(mat4(), -1.0f, vec3(1.0f, 0.0f, 0.0f)); 410 obj.model_ mat= T_model; //T_model * R_model;413 obj.model_base = T_model; //T_model * R_model; 411 414 412 415 addObjectToScene(obj); … … 480 483 481 484 mat4 T = translate(mat4(), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z)); 482 mat4 R = rotate(mat4(), -cam_yaw, vec3(0.0f, 1.0f, 0.0f));485 mat4 R = mat4(); 483 486 view_mat = R*T; 484 487 … … 593 596 /* 594 597 if (key_state[GLFW_KEY_SPACE] == GLFW_PRESS) { 595 //transformObject(objects[1], translate(mat4(), vec3(0.3f, 0.0f, 0.0f)), ubo);598 transformObject(objects[1], translate(mat4(), vec3(0.3f, 0.0f, 0.0f)), ubo); 596 599 } 597 600 if (key_pressed[GLFW_KEY_RIGHT]) { … … 885 888 obj.id = objects.size(); // currently unused 886 889 obj.num_points = obj.points.size() / 3; 890 obj.model_transform = mat4(); 887 891 888 892 obj.normals.reserve(obj.points.size()); … … 1009 1013 glBufferData(GL_ARRAY_BUFFER, model_mat_idx_buffer_size, NULL, GL_DYNAMIC_DRAW); 1010 1014 1011 GLint vertex_ubo_offset;1012 1015 for (it = objects.begin(); it != objects.end(); it++) { 1013 1016 it->vertex_vbo_offset = curShaderBase[it->shader_program] + curShaderOffset[it->shader_program]; 1014 vertex_ubo_offset = curShaderUboBase[it->shader_program] + curShaderUboOffset[it->shader_program];1017 it->ubo_offset = curShaderUboBase[it->shader_program] + curShaderUboOffset[it->shader_program]; 1015 1018 1016 1019 glBindBuffer(GL_ARRAY_BUFFER, *points_vbo); … … 1031 1034 glBindBuffer(GL_ARRAY_BUFFER, *model_mat_idx_vbo); 1032 1035 for (int i = 0; i < it->num_points; i++) { 1033 glBufferSubData(GL_ARRAY_BUFFER, (it->vertex_vbo_offset + i) * sizeof(GLuint), sizeof(GLuint), & vertex_ubo_offset);1036 glBufferSubData(GL_ARRAY_BUFFER, (it->vertex_vbo_offset + i) * sizeof(GLuint), sizeof(GLuint), &it->ubo_offset); 1034 1037 } 1035 1038 1036 1039 curShaderOffset[it->shader_program] += it->num_points; 1037 1040 1041 it->model_mat = it->model_base * it->model_transform; 1038 1042 glBindBuffer(GL_UNIFORM_BUFFER, *ubo); 1039 glBufferSubData(GL_UNIFORM_BUFFER, vertex_ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(it->model_mat));1043 glBufferSubData(GL_UNIFORM_BUFFER, it->ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(it->model_mat)); 1040 1044 1041 1045 curShaderUboOffset[it->shader_program]++; 1042 1046 } 1047 } 1048 1049 void transformObject(SceneObject& obj, const mat4& transform, GLuint ubo) { 1050 obj.model_transform = obj.model_transform * transform; 1051 obj.model_mat = obj.model_transform * obj.model_base; 1052 1053 glBindBuffer(GL_UNIFORM_BUFFER, ubo); 1054 glBufferSubData(GL_UNIFORM_BUFFER, obj.ubo_offset * sizeof(mat4), sizeof(mat4), value_ptr(obj.model_mat)); 1043 1055 } 1044 1056
Note:
See TracChangeset
for help on using the changeset viewer.