context in core
This commit is contained in:
@@ -77,13 +77,13 @@ public:
|
||||
* @brief Sets the box origin relative to its coordinate system.
|
||||
* @param v The origin position vector.
|
||||
*/
|
||||
inline void SetOrigin(const Vector3f &v) { m_LocalT.SetPosition(v); }
|
||||
void SetOrigin(const Vector3f &v) { m_LocalT.SetPosition(v); }
|
||||
|
||||
/**
|
||||
* @brief Gets the box origin relative to its coordinate system.
|
||||
* @return The origin position vector.
|
||||
*/
|
||||
inline Vector3f GetOrigin() const { return m_LocalT.GetPosition(); }
|
||||
Vector3f GetOrigin() const { return m_LocalT.GetPosition(); }
|
||||
|
||||
/**
|
||||
* @brief Sets the size of the box.
|
||||
@@ -101,7 +101,7 @@ public:
|
||||
* @brief Gets the current size (scale) of the box.
|
||||
* @return The size vector.
|
||||
*/
|
||||
inline Vector3f GetSize() const {
|
||||
Vector3f GetSize() const {
|
||||
Vector3f s = this->GetScale();
|
||||
Vector3f ls = m_LocalT.GetScale();
|
||||
return Vector3f(s(0) * ls(0), s(1) * ls(1), s(2) * ls(2));
|
||||
@@ -112,7 +112,7 @@ public:
|
||||
* @param first Index of the first axis (0=X, 1=Y, 2=Z).
|
||||
* @param second Index of the second axis (0=X, 1=Y, 2=Z).
|
||||
*/
|
||||
inline void FlipLocalAxes(int first, int second) {
|
||||
void FlipLocalAxes(int first, int second) {
|
||||
m_LocalT.FlipAxes(first, second);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public:
|
||||
* @param v The local point (4D homogeneous vector).
|
||||
* @return The transformed point in world space.
|
||||
*/
|
||||
inline Vector4f GetWorldPoint(const Vector4f &v) const {
|
||||
Vector4f GetWorldPoint(const Vector4f &v) const {
|
||||
return m_LocalT.GetWorldMatrix() * v;
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ public:
|
||||
* @param z Z coordinate in local space.
|
||||
* @return The transformed point in world space.
|
||||
*/
|
||||
inline Vector4f GetWorldPoint(const float x, const float y, const float z) {
|
||||
Vector4f GetWorldPoint(const float x, const float y, const float z) {
|
||||
return this->GetWorldPoint(Vector4f(x, y, z, 1));
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ public:
|
||||
* @param v The world point (4D homogeneous vector).
|
||||
* @return The transformed point in box-local space.
|
||||
*/
|
||||
inline Vector4f GetLocalPoint(const Vector4f &v) const {
|
||||
Vector4f GetLocalPoint(const Vector4f &v) const {
|
||||
return m_LocalT.GetWorldMatrix().inverse() * v;
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ public:
|
||||
* @param z Z coordinate in world space.
|
||||
* @return The transformed point in box-local space.
|
||||
*/
|
||||
inline Vector4f GetLocalPoint(const float x, const float y, const float z) {
|
||||
Vector4f GetLocalPoint(const float x, const float y, const float z) {
|
||||
return this->GetLocalPoint(Vector4f(x, y, z, 1));
|
||||
}
|
||||
|
||||
|
||||
@@ -81,12 +81,12 @@ public:
|
||||
|
||||
Eigen::Affine3f& GetTransform() { return m_T; }
|
||||
|
||||
inline AffineTransform *GetParent() const { return this->m_Parent; }
|
||||
AffineTransform *GetParent() const { return this->m_Parent; }
|
||||
|
||||
inline void SetParent(AffineTransform *name) { this->m_Parent = name; }
|
||||
void SetParent(AffineTransform *name) { this->m_Parent = name; }
|
||||
|
||||
inline void SetMatrix (Matrix4f mat) { m_T.matrix() = mat; }
|
||||
inline Matrix4f GetMatrix() const { return m_T.matrix(); }
|
||||
void SetMatrix (Matrix4f mat) { m_T.matrix() = mat; }
|
||||
Matrix4f GetMatrix() const { return m_T.matrix(); }
|
||||
|
||||
Matrix4f GetWorldMatrix() const
|
||||
{
|
||||
@@ -94,45 +94,45 @@ public:
|
||||
else return m_Parent->GetWorldMatrix() * m_T.matrix(); // T = B * A //
|
||||
}
|
||||
|
||||
inline void SetPosition(const Vector3f v) { this->m_T.translation() = v; }
|
||||
void SetPosition(const Vector3f v) { this->m_T.translation() = v; }
|
||||
|
||||
inline Vector3f GetPosition() const { return this->m_T.translation(); }
|
||||
Vector3f GetPosition() const { return this->m_T.translation(); }
|
||||
|
||||
inline void SetRotation(const Matrix3f m) { this->m_T.linear() = m; }
|
||||
void SetRotation(const Matrix3f m) { this->m_T.linear() = m; }
|
||||
|
||||
inline Matrix3f GetRotation() const { return this->m_T.rotation(); }
|
||||
Matrix3f GetRotation() const { return this->m_T.rotation(); }
|
||||
|
||||
inline void Translate(const Vector3f v) { this->m_T.pretranslate(v); }
|
||||
void Translate(const Vector3f v) { this->m_T.pretranslate(v); }
|
||||
|
||||
inline void Scale(const Vector3f v) { this->m_T.scale(v); }
|
||||
void Scale(const Vector3f v) { this->m_T.scale(v); }
|
||||
|
||||
inline Vector3f GetScale() const {
|
||||
Vector3f GetScale() const {
|
||||
return Vector3f(m_T.linear().col(0).norm(),
|
||||
m_T.linear().col(1).norm(),
|
||||
m_T.linear().col(2).norm());
|
||||
}
|
||||
|
||||
|
||||
inline void Rotate(const Matrix3f m) { this->m_T.rotate(m); }
|
||||
void Rotate(const Matrix3f m) { this->m_T.rotate(m); }
|
||||
|
||||
inline void Rotate(const float angle, Vector3f axis)
|
||||
void Rotate(const float angle, Vector3f axis)
|
||||
{
|
||||
axis.normalize(); // prehaps not necessary ( see eigens )
|
||||
Eigen::AngleAxisf ax(angle,axis);
|
||||
this->m_T.rotate(Eigen::Quaternion<float>(ax));
|
||||
}
|
||||
|
||||
inline void Rotate(const Vector3f euler_axis) {
|
||||
void Rotate(const Vector3f euler_axis) {
|
||||
float angle = euler_axis.norm();
|
||||
Rotate(angle,euler_axis);
|
||||
}
|
||||
|
||||
inline void PreRotate(const Matrix3f m) { this->m_T.prerotate(m); }
|
||||
void PreRotate(const Matrix3f m) { this->m_T.prerotate(m); }
|
||||
|
||||
inline void QuaternionRotate(const Vector4f q)
|
||||
void QuaternionRotate(const Vector4f q)
|
||||
{ this->m_T.rotate(Eigen::Quaternion<float>(q)); }
|
||||
|
||||
inline void EulerYZYRotate(const Vector3f e) {
|
||||
void EulerYZYRotate(const Vector3f e) {
|
||||
Matrix3f mat;
|
||||
mat = Eigen::AngleAxisf(e.x(), Vector3f::UnitY())
|
||||
* Eigen::AngleAxisf(e.y(), Vector3f::UnitZ())
|
||||
@@ -140,7 +140,7 @@ public:
|
||||
m_T.rotate(mat);
|
||||
}
|
||||
|
||||
inline void FlipAxes(int first, int second)
|
||||
void FlipAxes(int first, int second)
|
||||
{
|
||||
Matrix3f mat = Matrix3f::Identity();
|
||||
mat.col(first).swap(mat.col(second));
|
||||
|
||||
@@ -162,6 +162,35 @@ int main()
|
||||
|
||||
|
||||
|
||||
{ // test parent-child relationship
|
||||
ContainerBox Parent;
|
||||
Parent.SetOrigin(Vector3f(1,1,1));
|
||||
Parent.SetSize(Vector3f(2,2,2));
|
||||
|
||||
ContainerBox Child;
|
||||
Child.SetParent(&Parent);
|
||||
Child.SetOrigin(Vector3f(1,1,1));
|
||||
Child.SetSize(Vector3f(2,2,2));
|
||||
|
||||
HPoint3f pt = Child.GetLocalPoint(HPoint3f(0,0,0));
|
||||
HPoint3f wp = Child.GetWorldPoint(pt);
|
||||
TEST0( Vector4f0(wp - HPoint3f(0,0,0)) );
|
||||
|
||||
pt = HPoint3f(1,1,1);
|
||||
wp = Child.GetWorldPoint(pt);
|
||||
TEST0( Vector4f0(wp - HPoint3f(2,2,2)) );
|
||||
|
||||
pt = HPoint3f(1,2,3);
|
||||
wp = Child.GetWorldPoint(pt);
|
||||
std::cout << "Child.GetWorldPoint(HPoint3f(1,2,3)): " << wp << std::endl;
|
||||
TEST0( Vector4f0(wp - HPoint3f(2,3,4)) );
|
||||
|
||||
pt = HPoint3f(1,2,3);
|
||||
wp = Child.GetWorldPoint(pt);
|
||||
TEST0( Vector4f0(wp - HPoint3f(2,3,4)) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user