fix(editor): unsink dragged objects
This commit is contained in:
parent
375d6c89b9
commit
18985e6f86
2 changed files with 9 additions and 4 deletions
|
@ -51,3 +51,7 @@ namespace Data {
|
|||
bool operator ==(Data::Vector3) const;
|
||||
};
|
||||
}
|
||||
|
||||
inline void printVec(Data::Vector3 vec) {
|
||||
printf("(%f, %f, %f)\n", vec.X(), vec.Y(), vec.Z());
|
||||
}
|
|
@ -141,17 +141,18 @@ void MainGLWidget::handleObjectDrag(QMouseEvent* evt) {
|
|||
Data::CFrame targetFrame = partFromBody(rayHit->body)->cframe;
|
||||
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
|
||||
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
|
||||
localFrame = snapCFrame(localFrame);
|
||||
Data::CFrame newFrame = targetFrame * localFrame;
|
||||
|
||||
// Unsink the object
|
||||
// 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 + vec + partOffset;
|
||||
draggingObject->lock()->cframe = newFrame + unsinkOffset;
|
||||
|
||||
syncPartPhysics(draggingObject->lock());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue