fix(editor): unsink dragged objects

This commit is contained in:
maelstrom 2025-03-31 21:48:27 +02:00
parent 375d6c89b9
commit 18985e6f86
2 changed files with 9 additions and 4 deletions

View file

@ -51,3 +51,7 @@ namespace Data {
bool operator ==(Data::Vector3) const; bool operator ==(Data::Vector3) const;
}; };
} }
inline void printVec(Data::Vector3 vec) {
printf("(%f, %f, %f)\n", vec.X(), vec.Y(), vec.Z());
}

View file

@ -141,17 +141,18 @@ void MainGLWidget::handleObjectDrag(QMouseEvent* evt) {
Data::CFrame targetFrame = partFromBody(rayHit->body)->cframe; Data::CFrame targetFrame = partFromBody(rayHit->body)->cframe;
Data::Vector3 surfaceNormal = targetFrame.Inverse().Rotation() * rayHit->worldNormal; Data::Vector3 surfaceNormal = targetFrame.Inverse().Rotation() * rayHit->worldNormal;
// The part being dragged's frame local to the hit target's frame, but without its position component // The part being dragged's frame local to the hit target's frame, but without its position component
Data::CFrame localFrame = (targetFrame.Inverse() * draggingObject->lock()->cframe).Rotation(); // To find a world vector local to the new frame, use newFrame, not localFrame, as localFrame is localFrame is local to targetFrame in itself
Data::CFrame localFrame = (targetFrame.Inverse() * (draggingObject->lock()->cframe.Rotation() + vec));
// Snap axis // Snap axis
localFrame = snapCFrame(localFrame); localFrame = snapCFrame(localFrame);
Data::CFrame newFrame = targetFrame * localFrame;
// Unsink the object // Unsink the object
// Get the normal of the surface relative to the part's frame, and get the size along that vector // Get the normal of the surface relative to the part's frame, and get the size along that vector
Data::Vector3 partOffset = localFrame * ((localFrame.Inverse() * rayHit->worldNormal) * draggingObject->lock()->size / 2); Data::Vector3 unsinkOffset = newFrame.Rotation() * ((newFrame.Rotation().Inverse() * rayHit->worldNormal) * draggingObject->lock()->size / 2);
Data::CFrame newFrame = targetFrame.Rotation() * localFrame; draggingObject->lock()->cframe = newFrame + unsinkOffset;
draggingObject->lock()->cframe = newFrame + vec + partOffset;
syncPartPhysics(draggingObject->lock()); syncPartPhysics(draggingObject->lock());
} }