diff --git a/src/gfx/src/obj_control.cpp b/src/gfx/src/obj_control.cpp index 0a3680265b33f2fb3f0e5dc5772d7a54fb1bc013..95bc68bb97f26396bb29247482396227bff1abe3 100644 --- a/src/gfx/src/obj_control.cpp +++ b/src/gfx/src/obj_control.cpp @@ -2,7 +2,7 @@ void ObjectController::mouseRotate(const osi::Mouse &mouse) { - // check for start at object? + // TO DO: check for start at object? if (!mouse.down().contains("MouseLeft")) return; @@ -44,9 +44,9 @@ void ObjectController::mouseHorizontalMove(const glm::vec3 &ray_position, const void ObjectController::mouseElevationMove(const glm::vec3 &ray_position, const glm::vec3 &ray_direction, const glm::quat &camera_rotation, glm::vec3 &prev_plane_intersect, bool &object_moving) { - Frame atObjectVerticalPlane(bound_frame->getPosition(), camera_rotation); + Frame at_object_vertical_plane(bound_frame->getPosition(), camera_rotation); - auto normal = glm::normalize(glm::cross(atObjectVerticalPlane.getRotationAxisX(), glm::vec3(0.0f, 1.0f, 0.0f))); + auto normal = glm::normalize(glm::cross(at_object_vertical_plane.getRotationAxisX(), glm::vec3(0.0f, 1.0f, 0.0f))); auto d = glm::dot(normal, glm::vec3(0, 0, 0) - bound_frame->getPosition()) / glm::length(normal); float t = -(glm::dot(normal, ray_position) + d) / glm::dot(normal, ray_direction); diff --git a/src/studio/src/simulator.cpp b/src/studio/src/simulator.cpp index 7f0da7ab07cf100a8f34a23dae8defb884ecacee..3fd4ea81465b5bde44a12bdba32ac6a56ca8b880 100644 --- a/src/studio/src/simulator.cpp +++ b/src/studio/src/simulator.cpp @@ -77,27 +77,6 @@ std::vector<float> lit_cube_normals = 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, -1.0f }; -std::vector<float> get_normals(std::vector<unsigned int> &indices, std::vector<float> &vertices) -{ - std::vector<float> normals; - for (int i = 0; i < indices.size(); i += 3) - { - glm::vec3 v1(vertices[indices[i]*3], vertices[indices[i]*3+1], vertices[indices[i]*3+2]); - glm::vec3 v2(vertices[indices[i+1]*3], vertices[indices[i+1]*3+1], vertices[indices[i+1]*3+2]); - glm::vec3 v3(vertices[indices[i+2]*3], vertices[indices[i+2]*3+1], vertices[indices[i+2]*3+2]); - - glm::vec3 normal = glm::normalize(glm::cross(v2 - v1, v3 - v1)); - - for (int j = 0; j < 3; j++) - { - normals.push_back(normal.x); - normals.push_back(normal.y); - normals.push_back(normal.z); - } - } - return normals; -} - // Triangle std::vector<float> triangle_vertices = { 0, -0.2f, 0.5f, 0.7f, 0.3f, 0, -0.5f, 0.5f, 1 }; std::vector<unsigned int> triangle_indices = { 0, 1, 2 }; @@ -388,7 +367,6 @@ void Simulator::addPreAddAABB(node_ptr node, Frame position) obj_bbox.setDrawMode(GL_LINES); scene.back()->addObject(std::make_shared<Object>(std::move(obj_bbox))); } - scene.erase(scene.end() - 2); } std::pair<glm::vec3, glm::vec3> Simulator::getPickRay() @@ -531,8 +509,6 @@ void Simulator::addObject() if (!selection || !(mouse().just_released().contains("MouseLeft") || mouse().down().contains("MouseLeft"))) return; - removeNode(pre_add_AABB); - glm::vec3 position = selection->getFrame()->getPosition(); glm::quat rotation = selection->getFrame()->getRotation(); glm::vec3 scale = selection->getFrame()->getScale(); @@ -543,21 +519,28 @@ void Simulator::addObject() auto new_item_pos = ray_position + distance * ray_direction; Frame new_item_frame(new_item_pos, rotation, scale); + Node selection_copy(std::make_shared<Frame>(new_item_frame)); + + // TO DO: rewrite ifs in this method - ugly + if ((!pre_add_AABB && mouse().down().contains("MouseLeft")) + || mouse().just_released().contains("MouseLeft")) + { + for (auto &object : selection->getObjects()) + selection_copy.addObject(object); + } - scene.emplace_back(std::make_shared<Node>(std::make_shared<Frame>(new_item_frame))); - for (auto &object : selection->getObjects()) - scene.back()->addObject(object); - - if (mouse().just_released().contains("MouseLeft")) + if (!pre_add_AABB && mouse().down().contains("MouseLeft")) + addPreAddAABB(std::make_shared<Node>(std::move(selection_copy)), new_item_frame); + else if (mouse().down().contains("MouseLeft")) + pre_add_AABB->setFrame(std::make_shared<Frame>(new_item_frame)); + else if (mouse().just_released().contains("MouseLeft")) { + scene.emplace_back(std::make_shared<Node>(std::move(selection_copy))); selection = scene.back(); manageSelection(selection); removeNode(pre_add_AABB); - } - else if (mouse().down().contains("MouseLeft")) - { - addPreAddAABB(scene.back(), new_item_frame); + pre_add_AABB = nullptr; } } @@ -652,4 +635,26 @@ node_ptr find_intersection(std::vector<node_ptr> scene, glm::vec3 ray_position, return nearest_node; } +/* UNUSED */ +std::vector<float> get_normals(std::vector<unsigned int> &indices, std::vector<float> &vertices) +{ + std::vector<float> normals; + for (int i = 0; i < indices.size(); i += 3) + { + glm::vec3 v1(vertices[indices[i]*3], vertices[indices[i]*3+1], vertices[indices[i]*3+2]); + glm::vec3 v2(vertices[indices[i+1]*3], vertices[indices[i+1]*3+1], vertices[indices[i+1]*3+2]); + glm::vec3 v3(vertices[indices[i+2]*3], vertices[indices[i+2]*3+1], vertices[indices[i+2]*3+2]); + + glm::vec3 normal = glm::normalize(glm::cross(v2 - v1, v3 - v1)); + + for (int j = 0; j < 3; j++) + { + normals.push_back(normal.x); + normals.push_back(normal.y); + normals.push_back(normal.z); + } + } + return normals; +} + }