Base/Placement.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 #endif
00027
00028
00029 #include "Placement.h"
00030 #include "Rotation.h"
00031
00032 using namespace Base;
00033
00034 Placement::Placement()
00035 {
00036
00037 }
00038
00039 Placement::Placement(const Base::Matrix4D& matrix)
00040 {
00041 fromMatrix(matrix);
00042 }
00043
00044 Placement::Placement(const Placement& that)
00045 {
00046 this->_pos = that._pos;
00047 this->_rot = that._rot;
00048 }
00049
00050 Placement::Placement(const Vector3d& Pos, const Rotation &Rot)
00051 {
00052 this->_pos = Pos;
00053 this->_rot = Rot;
00054 }
00055
00056 Placement::Placement(const Vector3d& Pos, const Rotation &Rot, const Vector3d& Cnt)
00057 {
00058 Vector3d RotC = Cnt;
00059 Rot.multVec(RotC, RotC);
00060 this->_pos = Pos + Cnt - RotC;
00061 this->_rot = Rot;
00062 }
00063
00064 Base::Matrix4D Placement::toMatrix(void) const
00065 {
00066 Base::Matrix4D matrix;
00067 _rot.getValue(matrix);
00068 matrix[0][3] = this->_pos.x;
00069 matrix[1][3] = this->_pos.y;
00070 matrix[2][3] = this->_pos.z;
00071 return matrix;
00072 }
00073
00074 void Placement::fromMatrix(const Base::Matrix4D& matrix)
00075 {
00076 _rot.setValue(matrix);
00077 this->_pos.x = matrix[0][3];
00078 this->_pos.y = matrix[1][3];
00079 this->_pos.z = matrix[2][3];
00080 }
00081
00082 void Placement::invert()
00083 {
00084 this->_rot = this->_rot.inverse();
00085 this->_rot.multVec(this->_pos, this->_pos);
00086 this->_pos = -this->_pos;
00087 }
00088
00089 Placement Placement::inverse() const
00090 {
00091 Placement p(*this);
00092 p.invert();
00093 return p;
00094 }
00095
00096 void Placement::move(const Vector3d& MovVec)
00097 {
00098 _pos += MovVec;
00099 }
00100
00101 bool Placement::operator == (const Placement& that) const
00102 {
00103 return (this->_pos == that._pos) && (this->_rot == that._rot);
00104 }
00105
00106 bool Placement::operator != (const Placement& that) const
00107 {
00108 return !(*this == that);
00109 }
00110
00111 Placement & Placement::operator*=(const Placement & p)
00112 {
00113 Base::Vector3d tmp(p._pos);
00114 this->_rot.multVec(tmp, tmp);
00115 this->_pos += tmp;
00116 this->_rot *= p._rot;
00117 return *this;
00118 }
00119
00120 Placement Placement::operator*(const Placement & p) const
00121 {
00122 Placement plm(*this);
00123 plm *= p;
00124 return plm;
00125 }
00126
00127 Placement& Placement::operator = (const Placement& New)
00128 {
00129 this->_pos = New._pos;
00130 this->_rot = New._rot;
00131 return *this;
00132 }
00133
00134 void Placement::multVec(const Vector3d & src, Vector3d & dst) const
00135 {
00136 this->_rot.multVec(src, dst);
00137 dst += this->_pos;
00138 }
00139
00140 Placement Placement::slerp(const Placement & p0, const Placement & p1, double t)
00141 {
00142 Rotation rot = Rotation::slerp(p0.getRotation(), p1.getRotation(), t);
00143 Vector3d pos = p0.getPosition() * (1.0-t) + p1.getPosition() * t;
00144 return Placement(pos, rot);
00145 }