I try to rotate Model3D for Apple Vision Pro with a DragGesture.
To do it I just add degrees to an Angle object, and it works fine but it only rotate left or right not both.
So I’ve been able to detect left / right gesture and add or remove degrees to the angle.
But since there the rotation isn’t working well and direction may change to right while I’m still dragging left.
@State var rotation: Angle = .zero
@State var previousLocation: CGPoint = .zero
var rotateGesture: some Gesture {
DragGesture()
.targetedToAnyEntity()
.onChanged { value in
if (previousLocation == .zero) {
previousLocation = value.location
}
if (previousLocation.x > value.location.x) {
rotation.degrees -= 1.0
} else {
rotation.degrees += 1.0
}
previousLocation = value.location
}
}
Rotation is apply to 3d model like this
.gesture(rotateGesture)
.rotation3DEffect(rotation, axis: .y)
Does anyone knows what’s wrong or what I missed ?