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

add debug camera axes

parent bf49d308
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,8 @@ private:
bool camera_axes_enabled = false;
node_ptr camera_axes;
node_ptr camera_axes_debug;
node_ptr grid;
std::vector<light_ptr> lights;
......@@ -123,6 +125,7 @@ public:
void addRotationAxis(glm::vec3 axis_direction, node_ptr selected_node);
void addObjectAxes(node_ptr node);
void createCameraAxes();
void createCameraAxesDebug();
bool containsMesh(node_ptr node, mesh_ptr mesh);
void findLights(const std::vector<node_ptr> &nodes);
......@@ -139,7 +142,9 @@ public:
void manageSecondaryHighlights(std::vector<std::pair<glm::vec3, node_ptr>> hit_node_pairs);
void manageCameraAxes(bool enabled);
void manageCameraAxesDebug(bool enabled);
void updateCameraAxesPosition();
void updateCameraAxesDebugPosition();
void toggleVisibility(node_ptr node, bool visible);
};
......
......@@ -423,14 +423,44 @@ void Scene::createCameraAxes()
rofi_y_axis->setDrawMode(GL_LINES);
rofi_z_axis->setDrawMode(GL_LINES);
// ordered due to disabled depth test
camera_axes->addObject(rofi_z_axis);
camera_axes->addObject(rofi_x_axis);
camera_axes->addObject(rofi_y_axis);
camera_axes->addObject(rofi_z_axis);
ASSUMPTION(!active_cameras.empty());
active_cameras.front().lock()->getNode()->addChild(camera_axes);
}
void Scene::createCameraAxesDebug()
{
camera_axes_debug = Node::create();
mesh_ptr debug_x_axis = std::make_shared<Mesh>(shapes::debug_axis_x_vertices, std::vector<float>{}, shapes::debug_axis_indices);
mesh_ptr debug_y_axis = std::make_shared<Mesh>(shapes::debug_axis_y_vertices, std::vector<float>{}, shapes::debug_axis_indices);
mesh_ptr debug_z_axis = std::make_shared<Mesh>(shapes::debug_axis_z_vertices, std::vector<float>{}, shapes::debug_axis_indices);
debug_x_axis->setMaterial(Material(color::red));
debug_y_axis->setMaterial(Material(color::green));
debug_z_axis->setMaterial(Material(color::blue));
debug_x_axis->setShaderType("interface");
debug_y_axis->setShaderType("interface");
debug_z_axis->setShaderType("interface");
debug_x_axis->setDrawMode(GL_LINES);
debug_y_axis->setDrawMode(GL_LINES);
debug_z_axis->setDrawMode(GL_LINES);
// ordered due to disabled depth test
camera_axes_debug->addObject(debug_y_axis);
camera_axes_debug->addObject(debug_z_axis);
camera_axes_debug->addObject(debug_x_axis);
ASSUMPTION(!active_cameras.empty());
active_cameras.front().lock()->getNode()->addChild(camera_axes_debug);
}
bool Scene::containsMesh(node_ptr node, mesh_ptr mesh)
{
auto node_mesh = getNodeMesh(node);
......@@ -601,6 +631,24 @@ void Scene::manageCameraAxes(bool enabled)
addNode(camera_axes);
}
camera_axes_enabled = enabled;
// TO DO: remove
manageCameraAxesDebug(enabled);
}
void Scene::manageCameraAxesDebug(bool enabled)
{
if (!enabled)
{
removeNode(camera_axes_debug);
}
else
{
if (!camera_axes_debug)
createCameraAxesDebug();
addNode(camera_axes_debug);
}
}
void Scene::updateCameraAxesPosition()
......@@ -619,6 +667,27 @@ void Scene::updateCameraAxesPosition()
const auto camera_rotation = active_cameras.front().lock()->getNode()->getRotationMatWorld();
camera_axes->setRotationQuat(glm::inverse(camera_rotation));
// TO DO: remove
updateCameraAxesDebugPosition();
}
void Scene::updateCameraAxesDebugPosition()
{
if (!camera_axes_enabled)
return;
ASSUMPTION(!active_cameras.empty());
const auto active_cam = active_cameras.front().lock();
const auto window_size = active_cam->getWindowSize();
const auto ratio = window_size.x / window_size.y;
const auto screen_offset = 0.06f;
const auto x_compensation = -0.01f;
camera_axes_debug->setPosVec(glm::vec3(screen_offset * ratio + (x_compensation * ratio), screen_offset, -0.15f));
const auto camera_rotation = active_cameras.front().lock()->getNode()->getRotationMatWorld();
camera_axes_debug->setRotationQuat(glm::inverse(camera_rotation));
}
void Scene::toggleVisibility(node_ptr node, bool visible)
......
......@@ -138,6 +138,14 @@ static std::vector<float> rofi_axis_z_vertices = { 0.0f, 0.0f, 0.0f,
static std::vector<float> rofi_axis_x_vertices = { 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.01f, };
static std::vector<unsigned int> rofi_axis_indices = { 0, 1, 2 };
static std::vector<float> debug_axis_x_vertices = { 0.0f, 0.0f, 0.0f,
0.01f, 0.0f, 0.0f, };
static std::vector<float> debug_axis_y_vertices = { 0.0f, 0.0f, 0.0f,
0.0f, 0.01f, 0.0f, };
static std::vector<float> debug_axis_z_vertices = { 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.01f, };
static std::vector<unsigned int> debug_axis_indices = { 0, 1, 2 };
}
#endif
\ No newline at end of file
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