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

fix translation and rotation in export

parent c23b0484
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ bool AABB_intersect(const AABB &fst_aabb, const AABB &snd_aabb, const node_ptr &
std::pair<std::size_t, std::size_t> get_pad_width_height_from_connector_count(const std::vector<connector_ptr> &connectors);
glm::vec3 convertToRoFICoordinates(const glm::vec3 &position);
glm::vec3 convertToRoFICoordinates(const glm::vec3 &position, const glm::vec3 &to_voxel_center);
glm::mat4 convertToRoFICoordinates(const glm::mat4 &matrix);
#endif
\ No newline at end of file
......@@ -109,16 +109,38 @@ std::pair<std::size_t, std::size_t> get_pad_width_height_from_connector_count(co
return { static_cast<std::size_t>(max_x_pos) + 1, static_cast<std::size_t>(max_y_pos) + 1 };
}
glm::vec3 convertToRoFICoordinates(const glm::vec3 &position)
glm::vec3 convertToRoFICoordinates(const glm::vec3 &position, const glm::vec3 &to_voxel_center)
{
return glm::vec3(position.z, position.x, position.y);
const auto voxel_position = position + to_voxel_center * 0.5f;
return glm::vec3(voxel_position.z, voxel_position.x, voxel_position.y);
}
glm::mat4 convertToRoFICoordinates(const glm::mat4 &matrix)
{
auto m = glm::toMat4(glm::angleAxis(glm::radians(90.0f), glm::vec3(0.0f, 0.0f, 1.0f)))
* glm::toMat4(glm::angleAxis(glm::radians(90.0f), glm::vec3(1.0f, 0.0f, 0.0f)))
* matrix;
// E -> E'
// auto m = // glm::toMat4(glm::angleAxis(glm::radians(90.0f), glm::vec3(0.0f, 0.0f, -1.0f)))
// glm::toMat4(glm::angleAxis(glm::radians(90.0f), glm::vec3(0.0f, -1.0f, 0.0f)))
// * glm::toMat4(glm::angleAxis(glm::radians(90.0f), glm::vec3(-1.0f, 0.0f, 0.0f)))
// // * matrix
// // * r_matrix;
// * corrected_matrix;
const auto A_neg_X_local_correction_matrix = glm::mat4(0, 0, 1, 0, // col X
0, -1, 0, 0, // col Y
1, 0, 0, 0, // col Z
0, 0, 0, 1 // col W
);
const auto corrected_component_matrix = matrix * A_neg_X_local_correction_matrix;
const auto magic_matrix = glm::mat4(0, 1, 0, 0, // col X
0, 0, 1, 0, // col Y
1, 0, 0, 0, // col Z
0, 0, 0, 1 // col W
);
auto m = magic_matrix * corrected_component_matrix;
m[3] = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
return m;
......
......@@ -142,8 +142,7 @@ void export_spaceJoint(boost::json::array &spaceJoints_array, const rofiworld_pt
void export_spaceJoint_point(boost::json::object &spaceJoint_object, const node_ptr node)
{
boost::json::array point_array;
const auto position = convertToRoFICoordinates(node->getPositionWorld());
// const auto position = node->getPositionWorld();
const auto position = convertToRoFICoordinates(node->getPositionWorld(), node->getRotationAxisZWorld());
for (int i = 0; i < 3; ++i)
point_array.emplace_back(position[i]);
......@@ -167,9 +166,7 @@ void export_spaceJoint_joint(boost::json::object &spaceJoint_object, const node_
void export_spaceJoint_joint_matrix(boost::json::object &joint_object, const node_ptr node)
{
auto component_coord_convert = glm::toMat4(glm::rotation(glm::vec3(0.0f, 0.0f, -1.0f), -node->getRotationAxisZWorld()));
// auto rotation_mat = convertToRoFICoordinates(component_coord_convert);
auto rotation_mat = component_coord_convert;
auto rotation_mat = convertToRoFICoordinates(node->getRotationMatWorld());
float epsilon = 0.00001f;
bool is_identity = true;
......
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