Ported ModelObject::rotate() and ModelObject::flip() to XS, as well as axes constants

This commit is contained in:
Alessandro Ranellucci 2015-04-16 21:22:04 +02:00
parent be2f46ca68
commit 5eb3bc52ef
11 changed files with 84 additions and 46 deletions

View file

@ -1,4 +1,5 @@
#include "Model.hpp"
#include "Geometry.hpp"
namespace Slic3r {
@ -514,6 +515,29 @@ ModelObject::scale(const Pointf3 &versor)
this->invalidate_bounding_box();
}
void
ModelObject::rotate(float angle, const Axis &axis)
{
// we accept angle in radians but mesh currently uses degrees
angle = Slic3r::Geometry::rad2deg(angle);
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
(*v)->mesh.rotate(angle, axis);
}
this->origin_translation = Pointf3(0,0,0);
this->invalidate_bounding_box();
}
void
ModelObject::flip(const Axis &axis)
{
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
(*v)->mesh.flip(axis);
}
this->origin_translation = Pointf3(0,0,0);
this->invalidate_bounding_box();
}
size_t
ModelObject::materials_count() const
{

View file

@ -129,6 +129,8 @@ class ModelObject
void translate(const Vectorf3 &vector);
void translate(coordf_t x, coordf_t y, coordf_t z);
void scale(const Pointf3 &versor);
void rotate(float angle, const Axis &axis);
void flip(const Axis &axis);
size_t materials_count() const;
size_t facets_count() const;
bool needed_repair() const;

View file

@ -200,40 +200,58 @@ void TriangleMesh::translate(float x, float y, float z)
stl_invalidate_shared_vertices(&this->stl);
}
void TriangleMesh::rotate(float angle, const Axis &axis)
{
if (axis == X) {
stl_rotate_x(&(this->stl), angle);
} else if (axis == Y) {
stl_rotate_y(&(this->stl), angle);
} else if (axis == Z) {
stl_rotate_z(&(this->stl), angle);
}
stl_invalidate_shared_vertices(&this->stl);
}
void TriangleMesh::rotate_x(float angle)
{
stl_rotate_x(&(this->stl), angle);
stl_invalidate_shared_vertices(&this->stl);
this->rotate(angle, X);
}
void TriangleMesh::rotate_y(float angle)
{
stl_rotate_y(&(this->stl), angle);
stl_invalidate_shared_vertices(&this->stl);
this->rotate(angle, Y);
}
void TriangleMesh::rotate_z(float angle)
{
stl_rotate_z(&(this->stl), angle);
this->rotate(angle, Z);
}
void TriangleMesh::flip(const Axis &axis)
{
if (axis == X) {
stl_mirror_yz(&this->stl);
} else if (axis == Y) {
stl_mirror_xz(&this->stl);
} else if (axis == Z) {
stl_mirror_xy(&this->stl);
}
stl_invalidate_shared_vertices(&this->stl);
}
void TriangleMesh::flip_x()
{
stl_mirror_yz(&this->stl);
stl_invalidate_shared_vertices(&this->stl);
this->flip(X);
}
void TriangleMesh::flip_y()
{
stl_mirror_xz(&this->stl);
stl_invalidate_shared_vertices(&this->stl);
this->flip(Y);
}
void TriangleMesh::flip_z()
{
stl_mirror_xy(&this->stl);
stl_invalidate_shared_vertices(&this->stl);
this->flip(Z);
}
void TriangleMesh::align_to_origin()

View file

@ -32,9 +32,11 @@ class TriangleMesh
void scale(float factor);
void scale(const Pointf3 &versor);
void translate(float x, float y, float z);
void rotate(float angle, const Axis &axis);
void rotate_x(float angle);
void rotate_y(float angle);
void rotate_z(float angle);
void flip(const Axis &axis);
void flip_x();
void flip_y();
void flip_z();

View file

@ -17,7 +17,12 @@
typedef long coord_t;
typedef double coordf_t;
namespace Slic3r {}
namespace Slic3r {
// TODO: make sure X = 0
enum Axis { X, Y, Z };
}
using namespace Slic3r;
/* Implementation of CONFESS("foo"): */