diff --git a/engine/Object.cpp b/engine/Object.cpp index bf72bea..0c6f525 100644 --- a/engine/Object.cpp +++ b/engine/Object.cpp @@ -50,7 +50,6 @@ void Object::scale(const Vec3D &s) { void Object::rotate(const Vec3D &r) { _angle = _angle + r; - // TODO: when you rotate body _angle is changed only for this body but all attached objects have incorrect _angle Matrix4x4 rotationMatrix = Matrix4x4::RotationZ(r.z()) * Matrix4x4::RotationY(r.y()) * Matrix4x4::RotationX(r.z()); transform(rotationMatrix); } @@ -60,6 +59,8 @@ void Object::rotate(const Vec3D &v, double rv) { } void Object::rotateRelativePoint(const Vec3D &s, const Vec3D &r) { + _angle = _angle + r; + transformRelativePoint(s, Matrix4x4::Rotation(r)); } diff --git a/engine/Object.h b/engine/Object.h index cdf4f1f..2a38649 100644 --- a/engine/Object.h +++ b/engine/Object.h @@ -40,6 +40,13 @@ private: std::map> _attachedObjects; Vec3D _position{0, 0, 0}; + + /* + * Take into account when you rotate body, + * you change '_angle' only for this particular body, + * but not for attached objects! This way during rotation + * '_angle' stays the same for all attached objects. + */ Vec3D _angle{0, 0, 0}; Vec3D _angleLeftUpLookAt{0, 0, 0}; public: