void DetachFromParent()
{
if (_parent)
{
// 부모의 자식 Transform 목록에서 제거
auto it = std::find(_parent->_children.begin(), _parent->_children.end(), shared_from_this());
if (it != _parent->_children.end())
_parent->_children.erase(it);
// 월드 변환 유지하면서 로컬 변환 갱신
_localPosition = GetWorldPosition();
_qtLocalRotation = Quaternion::CreateFromRotationMatrix(GetWorldMatrix());
_localScale = GetWorldScale();
_parent = nullptr;
}
UpdateTransform();
}
void Transform::RotateAround(const Vec3& center, const Vec3& axis, float angle)
{
// 1. 현재 월드 위치 저장
Vec3 worldPos = GetWorldPosition();
// 2. 중심점 기준 회전 행렬 생성
Matrix toOrigin = Matrix::CreateTranslation(-center);
Matrix rotation = Matrix::CreateFromAxisAngle(axis, XMConvertToRadians(angle));
Matrix fromOrigin = Matrix::CreateTranslation(center);
// 3. 위치에 회전 적용
Matrix transform = toOrigin * rotation * fromOrigin;
Vec3 newWorldPos = Vec3::Transform(worldPos, transform);
// 4. 새로운 위치를 로컬 공간으로 변환
if (HasParent())
{
Matrix parentInverse = _parent->GetWorldMatrix().Invert();
_localPosition = Vec3::Transform(newWorldPos, parentInverse);
}
else
{
_localPosition = newWorldPos; // 부모가 없으면 월드 위치가 곧 로컬 위치
}
// 5. Transform 업데이트
UpdateTransform();
}