Use radians everywhere, including ModelInstance::rotation

This commit is contained in:
Alessandro Ranellucci 2015-05-03 18:40:00 +02:00
parent 79ce094e3a
commit 0d01348acc
4 changed files with 10 additions and 10 deletions

View File

@ -704,14 +704,14 @@ sub rotate {
$self->stop_background_process; $self->stop_background_process;
if ($axis == Z) { if ($axis == Z) {
my $new_angle = $model_instance->rotation + $angle; my $new_angle = $model_instance->rotation + deg2rad($angle);
$_->set_rotation($new_angle) for @{ $model_object->instances }; $_->set_rotation($new_angle) for @{ $model_object->instances };
$object->transform_thumbnail($self->{model}, $obj_idx); $object->transform_thumbnail($self->{model}, $obj_idx);
} else { } else {
# rotation around X and Y needs to be performed on mesh # rotation around X and Y needs to be performed on mesh
# so we first apply any Z rotation # so we first apply any Z rotation
if ($model_instance->rotation != 0) { if ($model_instance->rotation != 0) {
$model_object->rotate(deg2rad($model_instance->rotation), Z); $model_object->rotate($model_instance->rotation, Z);
$_->set_rotation(0) for @{ $model_object->instances }; $_->set_rotation(0) for @{ $model_object->instances };
} }
$model_object->rotate(deg2rad($angle), $axis); $model_object->rotate(deg2rad($angle), $axis);
@ -741,7 +741,7 @@ sub flip {
# apply Z rotation before flipping # apply Z rotation before flipping
if ($model_instance->rotation != 0) { if ($model_instance->rotation != 0) {
$model_object->rotate(deg2rad($model_instance->rotation), Z); $model_object->rotate($model_instance->rotation, Z);
$_->set_rotation(0) for @{ $model_object->instances }; $_->set_rotation(0) for @{ $model_object->instances };
} }
@ -780,7 +780,7 @@ sub changescale {
# apply Z rotation before scaling # apply Z rotation before scaling
if ($model_instance->rotation != 0) { if ($model_instance->rotation != 0) {
$model_object->rotate(deg2rad($model_instance->rotation), Z); $model_object->rotate($model_instance->rotation, Z);
$_->set_rotation(0) for @{ $model_object->instances }; $_->set_rotation(0) for @{ $model_object->instances };
} }
@ -1730,7 +1730,7 @@ sub transform_thumbnail {
# the order of these transformations MUST be the same everywhere, including # the order of these transformations MUST be the same everywhere, including
# in Slic3r::Print->add_model_object() # in Slic3r::Print->add_model_object()
my $t = $self->thumbnail->clone; my $t = $self->thumbnail->clone;
$t->rotate(deg2rad($model_instance->rotation), Slic3r::Point->new(0,0)); $t->rotate($model_instance->rotation, Slic3r::Point->new(0,0));
$t->scale($model_instance->scaling_factor); $t->scale($model_instance->scaling_factor);
$self->transformed_thumbnail($t); $self->transformed_thumbnail($t);

View File

@ -485,7 +485,7 @@ ModelObject::center_around_origin()
// apply rotation and scaling to vector as well before translating instance, // apply rotation and scaling to vector as well before translating instance,
// in order to leave final position unaltered // in order to leave final position unaltered
Vectorf3 v = vector.negative(); Vectorf3 v = vector.negative();
v.rotate(Slic3r::Geometry::deg2rad((*i)->rotation), (*i)->offset); v.rotate((*i)->rotation, (*i)->offset);
v.scale((*i)->scaling_factor); v.scale((*i)->scaling_factor);
(*i)->offset.translate(v.x, v.y); (*i)->offset.translate(v.x, v.y);
} }
@ -523,9 +523,6 @@ ModelObject::scale(const Pointf3 &versor)
void void
ModelObject::rotate(float angle, const Axis &axis) 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) { for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
(*v)->mesh.rotate(angle, axis); (*v)->mesh.rotate(angle, axis);
} }

View File

@ -177,7 +177,7 @@ class ModelInstance
{ {
friend class ModelObject; friend class ModelObject;
public: public:
double rotation; // around mesh center point double rotation; // in radians around mesh center point
double scaling_factor; double scaling_factor;
Pointf offset; // in unscaled coordinates Pointf offset; // in unscaled coordinates

View File

@ -202,6 +202,9 @@ void TriangleMesh::translate(float x, float y, float z)
void TriangleMesh::rotate(float angle, const Axis &axis) void TriangleMesh::rotate(float angle, const Axis &axis)
{ {
// admesh uses degrees
angle = Slic3r::Geometry::rad2deg(angle);
if (axis == X) { if (axis == X) {
stl_rotate_x(&(this->stl), angle); stl_rotate_x(&(this->stl), angle);
} else if (axis == Y) { } else if (axis == Y) {