Skip to content
Snippets Groups Projects
Commit 488f829c authored by Martin Štourač's avatar Martin Štourač
Browse files

objects add into active depth

parent ce608edd
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
#include <osi/window.hpp>
#include <utils/math.hpp>
#include <array>
#include <memory>
using ctrlhub_ptr = std::shared_ptr<ControlHub>;
......@@ -19,10 +20,29 @@ namespace edit
enum class state { select, move, rotate, plus };
class Level
{
std::array<float, 3> axes = {0.0f, 0.0f, 0.0f};
std::uint8_t active = 2;
public:
std::uint8_t getActiveIndex() const { return active; }
float getActive() const { return axes[active]; }
void setActiveX() { active = 0; }
void setActiveY() { active = 1; }
void setActiveZ() { active = 2; }
Level& operator++() { ++axes[active]; return *this; }
Level& operator--() { --axes[active]; return *this; }
};
class Editor
{
bool editor_running = false;
state control_state = state::select;
Level build_level;
bool object_moving = false;
glm::vec3 prev_plane_intersect;
......
......@@ -90,9 +90,16 @@ void Editor::addObject(scene_ptr scene, ctrlhub_ptr controls)
auto [ ray_position , ray_direction ] = get_pick_ray(scene, mouse, window);
float distance = glm::length(ray_position - position);
bool cam_is_perspective = scene->getActiveCameras()[0].lock()->isPerspective();
float distance = cam_is_perspective
? glm::length(ray_position - position)
: 1.0f;
auto new_item_pos = ray_position + distance * ray_direction;
if (!cam_is_perspective)
new_item_pos[build_level.getActiveIndex()] = build_level.getActive();
Frame new_item_frame(new_item_pos, rotation, scale);
Node selection_copy(std::make_shared<Frame>(new_item_frame));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment