code refactoring

master
Vectozavr 2021-10-31 15:47:00 +07:00
parent 785850ec43
commit d2e34d6764
2 changed files with 9 additions and 1 deletions

View File

@ -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));
}

View File

@ -40,6 +40,13 @@ private:
std::map<ObjectNameTag, std::weak_ptr<Object>> _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: