mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-05 18:30:49 +08:00
comments and floating type adaptation
This commit is contained in:
parent
438e462d11
commit
dcf83706a1
@ -117,9 +117,15 @@ void TransformationMatrix::translate(double x, double y, double z)
|
|||||||
this->applyLeft(mat);
|
this->applyLeft(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransformationMatrix::translateXY(Slic3r::Pointf position)
|
void TransformationMatrix::translate(Vectorf3 vector)
|
||||||
{
|
{
|
||||||
TransformationMatrix mat = mat_translation(position.x, position.y, 0.0);
|
TransformationMatrix mat = mat_translation(x, y, z);
|
||||||
|
this->applyLeft(mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TransformationMatrix::translateXY(Vectorf vector)
|
||||||
|
{
|
||||||
|
TransformationMatrix mat = mat_translation(vector.x, vector.y, 0.0);
|
||||||
this->applyLeft(mat);
|
this->applyLeft(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +146,7 @@ void TransformationMatrix::mirror(const Axis &axis)
|
|||||||
this->applyLeft(mat);
|
this->applyLeft(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransformationMatrix::mirror(const Pointf3 & normal)
|
void TransformationMatrix::mirror(const Vectorf3 & normal)
|
||||||
{
|
{
|
||||||
TransformationMatrix mat = mat_mirror(normal);
|
TransformationMatrix mat = mat_mirror(normal);
|
||||||
this->applyLeft(mat);
|
this->applyLeft(mat);
|
||||||
@ -152,7 +158,7 @@ void TransformationMatrix::rotate(double angle_rad, const Axis & axis)
|
|||||||
this->applyLeft(mat);
|
this->applyLeft(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransformationMatrix::rotate(double angle_rad, const Pointf3 & axis)
|
void TransformationMatrix::rotate(double angle_rad, const Vectorf3 & axis)
|
||||||
{
|
{
|
||||||
TransformationMatrix mat = mat_rotation(angle_rad, axis);
|
TransformationMatrix mat = mat_rotation(angle_rad, axis);
|
||||||
this->applyLeft(mat);
|
this->applyLeft(mat);
|
||||||
@ -285,7 +291,7 @@ TransformationMatrix TransformationMatrix::mat_rotation(double q1, double q2, do
|
|||||||
2.0 * (q1*q3 - q2*q4), 2.0 * (q2*q3 + q1*q4), 1.0 - 2.0 * (q1*q1 + q2*q2), 0.0);
|
2.0 * (q1*q3 - q2*q4), 2.0 * (q2*q3 + q1*q4), 1.0 - 2.0 * (q1*q1 + q2*q2), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TransformationMatrix TransformationMatrix::mat_rotation(double angle_rad, const Pointf3 &axis)
|
TransformationMatrix TransformationMatrix::mat_rotation(double angle_rad, const Vectorf3 &axis)
|
||||||
{
|
{
|
||||||
double s, factor, q1, q2, q3, q4;
|
double s, factor, q1, q2, q3, q4;
|
||||||
s = sin(angle_rad/2);
|
s = sin(angle_rad/2);
|
||||||
@ -298,7 +304,7 @@ TransformationMatrix TransformationMatrix::mat_rotation(double angle_rad, const
|
|||||||
return mat_rotation(q1, q2, q3, q4);
|
return mat_rotation(q1, q2, q3, q4);
|
||||||
}
|
}
|
||||||
|
|
||||||
TransformationMatrix TransformationMatrix::mat_rotation(Pointf3 origin, Pointf3 target)
|
TransformationMatrix TransformationMatrix::mat_rotation(Vectorf3 origin, Vectorf3 target)
|
||||||
{
|
{
|
||||||
// TODO: there is a lot of float <-> double conversion going on here
|
// TODO: there is a lot of float <-> double conversion going on here
|
||||||
|
|
||||||
@ -322,7 +328,7 @@ TransformationMatrix TransformationMatrix::mat_rotation(Pointf3 origin, Pointf3
|
|||||||
rec_length = 1.0 / sqrt(length_sq);
|
rec_length = 1.0 / sqrt(length_sq);
|
||||||
target.scale(rec_length);
|
target.scale(rec_length);
|
||||||
|
|
||||||
Pointf3 cross;
|
Vectorf3 cross;
|
||||||
cross.x = origin.y*target.z - origin.z*target.y;
|
cross.x = origin.y*target.z - origin.z*target.y;
|
||||||
cross.y = origin.z*target.x - origin.x*target.z;
|
cross.y = origin.z*target.x - origin.x*target.z;
|
||||||
cross.z = origin.x*target.y - origin.y*target.x;
|
cross.z = origin.x*target.y - origin.y*target.x;
|
||||||
@ -336,20 +342,20 @@ TransformationMatrix TransformationMatrix::mat_rotation(Pointf3 origin, Pointf3
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Pointf3 help;
|
Vectorf3 help;
|
||||||
// make help garanteed not colinear
|
// make help garanteed not colinear
|
||||||
if (abs(abs(origin.x) - 1) < 0.02)
|
if (abs(abs(origin.x) - 1) < 0.02)
|
||||||
help.z = 1.0; // origin mainly in x direction
|
help.z = 1.0; // origin mainly in x direction
|
||||||
else
|
else
|
||||||
help.x = 1.0;
|
help.x = 1.0;
|
||||||
|
|
||||||
Pointf3 proj = Pointf3(origin);
|
Vectorf3 proj = origin;
|
||||||
// projection of axis onto unit vector origin
|
// projection of axis onto unit vector origin
|
||||||
dot = origin.x*help.x + origin.y*help.y + origin.z*help.z;
|
dot = origin.x*help.x + origin.y*help.y + origin.z*help.z;
|
||||||
proj.scale(dot);
|
proj.scale(dot);
|
||||||
|
|
||||||
// help - proj is normal to origin -> rotation axis
|
// help - proj is normal to origin -> rotation axis
|
||||||
Pointf3 axis = (Pointf3)proj.vector_to(help);
|
Vectorf3 axis = ((Pointf3)proj).vector_to((Pointf3)help);
|
||||||
|
|
||||||
// axis is not unit length -> gets normalized in called function
|
// axis is not unit length -> gets normalized in called function
|
||||||
return mat_rotation(PI, axis);
|
return mat_rotation(PI, axis);
|
||||||
@ -387,7 +393,7 @@ TransformationMatrix TransformationMatrix::mat_mirror(const Axis &axis)
|
|||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
TransformationMatrix TransformationMatrix::mat_mirror(const Pointf3 &normal)
|
TransformationMatrix TransformationMatrix::mat_mirror(const Vectorf3 &normal)
|
||||||
{
|
{
|
||||||
// Kov<6F>cs, E. Rotation about arbitrary axis and reflection through an arbitrary plane, Annales Mathematicae
|
// Kov<6F>cs, E. Rotation about arbitrary axis and reflection through an arbitrary plane, Annales Mathematicae
|
||||||
// et Informaticae, Vol 40 (2012) pp 175-186
|
// et Informaticae, Vol 40 (2012) pp 175-186
|
||||||
|
@ -25,85 +25,86 @@ public:
|
|||||||
/// matrix entries
|
/// matrix entries
|
||||||
double m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34;
|
double m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34;
|
||||||
|
|
||||||
/// Return the row-major form of the represented transformation matrix
|
/// return the row-major form of the represented transformation matrix
|
||||||
/// for admesh transform
|
/// for admesh transform
|
||||||
std::vector<double> matrix3x4f() const;
|
std::vector<double> matrix3x4f() const;
|
||||||
|
|
||||||
/// Return the determinante of the matrix
|
/// return the determinante of the matrix
|
||||||
double determinante() const;
|
double determinante() const;
|
||||||
|
|
||||||
/// Returns the inverse of the matrix
|
/// returns the inverse of the matrix
|
||||||
bool inverse(TransformationMatrix &inverse) const;
|
bool inverse(TransformationMatrix &inverse) const;
|
||||||
|
|
||||||
/// Perform Translation
|
/// performs translation
|
||||||
void translate(double x, double y, double z);
|
void translate(double x, double y, double z);
|
||||||
void translateXY(Slic3r::Pointf position);
|
void translate(Vectorf3 vector);
|
||||||
|
void translateXY(Vectorf vector);
|
||||||
|
|
||||||
/// Perform uniform scale
|
/// performs uniform scale
|
||||||
void scale(double factor);
|
void scale(double factor);
|
||||||
|
|
||||||
/// Perform per-axis scale
|
/// performs per-axis scale
|
||||||
void scale(double x, double y, double z);
|
void scale(double x, double y, double z);
|
||||||
|
|
||||||
/// Perform mirroring along given axis
|
/// performs mirroring along given axis
|
||||||
void mirror(const Axis &axis);
|
void mirror(const Axis &axis);
|
||||||
|
|
||||||
/// Perform mirroring along given axis
|
/// performs mirroring along given axis
|
||||||
void mirror(const Pointf3 &normal);
|
void mirror(const Vectorf3 &normal);
|
||||||
|
|
||||||
/// Perform rotation around given axis
|
/// performs rotation around given axis
|
||||||
void rotate(double angle_rad, const Axis &axis);
|
void rotate(double angle_rad, const Axis &axis);
|
||||||
|
|
||||||
/// Perform rotation around arbitrary axis
|
/// performs rotation around arbitrary axis
|
||||||
void rotate(double angle_rad, const Pointf3 &axis);
|
void rotate(double angle_rad, const Vectorf3 &axis);
|
||||||
|
|
||||||
/// Perform rotation defined by unit quaternion
|
/// performs rotation defined by unit quaternion
|
||||||
void rotate(double q1, double q2, double q3, double q4);
|
void rotate(double q1, double q2, double q3, double q4);
|
||||||
|
|
||||||
/// Multiplies the Parameter-Matrix from the left (this=left*this)
|
/// multiplies the parameter-matrix from the left (this=left*this)
|
||||||
void applyLeft(const TransformationMatrix &left);
|
void applyLeft(const TransformationMatrix &left);
|
||||||
|
|
||||||
/// Multiplies the Parameter-Matrix from the left (out=left*this)
|
/// multiplies the parameter-matrix from the left (out=left*this)
|
||||||
TransformationMatrix multiplyLeft(const TransformationMatrix &left);
|
TransformationMatrix multiplyLeft(const TransformationMatrix &left);
|
||||||
|
|
||||||
/// Multiplies the Parameter-Matrix from the right (this=this*right)
|
/// multiplies the parameter-matrix from the right (this=this*right)
|
||||||
void applyRight(const TransformationMatrix &right);
|
void applyRight(const TransformationMatrix &right);
|
||||||
|
|
||||||
/// Multiplies the Parameter-Matrix from the right (out=this*right)
|
/// multiplies the parameter-matrix from the right (out=this*right)
|
||||||
TransformationMatrix multiplyRight(const TransformationMatrix &right);
|
TransformationMatrix multiplyRight(const TransformationMatrix &right);
|
||||||
|
|
||||||
/// Generate an eye matrix.
|
/// generates an eye matrix.
|
||||||
static TransformationMatrix mat_eye();
|
static TransformationMatrix mat_eye();
|
||||||
|
|
||||||
/// Generate a per axis scaling matrix
|
/// generates a per axis scaling matrix
|
||||||
static TransformationMatrix mat_scale(double x, double y, double z);
|
static TransformationMatrix mat_scale(double x, double y, double z);
|
||||||
|
|
||||||
/// Generate a uniform scaling matrix
|
/// generates an uniform scaling matrix
|
||||||
static TransformationMatrix mat_scale(double scale);
|
static TransformationMatrix mat_scale(double scale);
|
||||||
|
|
||||||
/// Generate a reflection matrix by coordinate axis
|
/// generates a reflection matrix by coordinate axis
|
||||||
static TransformationMatrix mat_mirror(const Axis &axis);
|
static TransformationMatrix mat_mirror(const Axis &axis);
|
||||||
|
|
||||||
/// Generate a reflection matrix by arbitrary vector
|
/// generates a reflection matrix by arbitrary vector
|
||||||
static TransformationMatrix mat_mirror(const Pointf3 &normal);
|
static TransformationMatrix mat_mirror(const Vectorf3 &normal);
|
||||||
|
|
||||||
/// Generate a translation matrix
|
/// generates a translation matrix
|
||||||
static TransformationMatrix mat_translation(double x, double y, double z);
|
static TransformationMatrix mat_translation(double x, double y, double z);
|
||||||
|
|
||||||
/// Generate a rotation matrix around coodinate axis
|
/// generates a rotation matrix around coodinate axis
|
||||||
static TransformationMatrix mat_rotation(double angle_rad, const Axis &axis);
|
static TransformationMatrix mat_rotation(double angle_rad, const Axis &axis);
|
||||||
|
|
||||||
/// Generate a rotation matrix defined by unit quaternion q1*i + q2*j + q3*k + q4
|
/// generates a rotation matrix defined by unit quaternion q1*i + q2*j + q3*k + q4
|
||||||
static TransformationMatrix mat_rotation(double q1, double q2, double q3, double q4);
|
static TransformationMatrix mat_rotation(double q1, double q2, double q3, double q4);
|
||||||
|
|
||||||
/// Generate a rotation matrix around arbitrary axis
|
/// generates a rotation matrix around arbitrary axis
|
||||||
static TransformationMatrix mat_rotation(double angle_rad, const Pointf3 &axis);
|
static TransformationMatrix mat_rotation(double angle_rad, const Vectorf3 &axis);
|
||||||
|
|
||||||
/// Generate a rotation matrix by specifying a vector (origin) that is to be rotated
|
/// generates a rotation matrix by specifying a vector (origin) that is to be rotated
|
||||||
/// to be colinear with another vector (target)
|
/// to be colinear with another vector (target)
|
||||||
static TransformationMatrix mat_rotation(Pointf3 origin, Pointf3 target);
|
static TransformationMatrix mat_rotation(Vectorf3 origin, Vectorf3 target);
|
||||||
|
|
||||||
/// Performs a matrix multiplication
|
/// performs a matrix multiplication
|
||||||
static TransformationMatrix multiply(const TransformationMatrix &left, const TransformationMatrix &right);
|
static TransformationMatrix multiply(const TransformationMatrix &left, const TransformationMatrix &right);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user