Changeset 147ac6d in opengl-game
- Timestamp:
- Mar 20, 2018, 1:24:24 AM (7 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 5c9d193
- Parents:
- df652d5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
new-game.cpp
rdf652d5 r147ac6d 28 28 struct SceneObject { 29 29 mat4 model_mat; 30 bool clicked;31 30 }; 32 31 … … 42 41 vec3 cam_pos; 43 42 44 int colors_i = 0;45 46 43 mat4 view_mat; 47 44 mat4 proj_mat; … … 49 46 vector<SceneObject> objects; 50 47 vector<ObjectFace> faces; 48 49 SceneObject* clickedObject = NULL; 50 SceneObject* selectedObject = NULL; 51 51 52 52 bool insideTriangle(vec3 p, ObjectFace* face); … … 198 198 if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) { 199 199 cout << "Mouse clicked (" << mouse_x << "," << mouse_y << ")" << endl; 200 selectedObject = NULL; 200 201 201 202 float x = (2.0f*mouse_x) / width - 1.0f; … … 273 274 printVector("Intersection", intersection); 274 275 275 obj->clicked = insideTriangle(intersection, face); 276 cout << (obj->clicked ? "true" : "false") << endl; 276 if (insideTriangle(intersection, face)) { 277 clickedObject = obj; 278 } 279 cout << (obj == clickedObject ? "true" : "false") << endl; 277 280 } 278 281 } … … 429 432 // triangle 430 433 objects.push_back(SceneObject()); 431 objects[0].clicked = false;432 434 433 435 /* … … 448 450 // square 449 451 objects.push_back(SceneObject()); 450 objects[1].clicked = false;451 452 452 453 // mat4 T_model2 = translate(mat4(), vec3(-1.0f, 0.0f, 0.0f)); … … 596 597 } 597 598 598 if (objects[0].clicked) { 599 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 600 601 if (colors_i == 0) { 602 glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors_new, GL_STATIC_DRAW); 603 colors_i = 1; 604 } else { 605 glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW); 606 colors_i = 0; 607 } 599 if (clickedObject == &objects[0]) { 600 selectedObject = &objects[0]; 601 } 602 603 // At some point, I should change this to only rebind the buffer once per click, not once per frame 604 glBindBuffer(GL_ARRAY_BUFFER, colors_vbo); 605 if (selectedObject == &objects[0]) { 606 glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors_new, GL_STATIC_DRAW); 607 } 608 else { 609 glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW); 608 610 } 609 611 … … 625 627 glDrawArrays(GL_TRIANGLES, 0, numPoints); 626 628 627 if ( objects[1].clicked) {629 if (clickedObject == &objects[1]) { 628 630 squareSelected = !squareSelected; 629 } 630 631 if (squareSelected) { 631 selectedObject = &objects[1]; 632 } 633 634 if (selectedObject == &objects[1]) { 632 635 glUseProgram(shader_program); 633 636 … … 651 654 glDrawArrays(GL_TRIANGLES, 0, numPoints2); 652 655 653 for (vector<SceneObject>::iterator it = objects.begin(); it != objects.end(); it++) { 654 it->clicked = false; 655 } 656 clickedObject = NULL; 656 657 657 658 glfwPollEvents();
Note:
See TracChangeset
for help on using the changeset viewer.