Post

Replies

Boosts

Views

Activity

Reply to Dragging horizontally with DragGesture
I found this to be working... is there a simpler way to achieve this? This takes the translation3D we get from the drag gesture, records an initialOffset (otherwise my entity jumps upward, because it has its origin in the bottom center). then it rotates the translation vector around x such that y becomes 0. Finally it converts it into the coordinate system of the entity's parent. Phew... .gesture(DragGesture() .targetedToAnyEntity() .onChanged { value in if initialDragOffset == .zero { // Calculate the initial drag offset at the beginning of the drag let startLocation = value.convert(value.startLocation3D, from: .local, to: value.entity.parent!) initialDragOffset = value.entity.position - SIMD3<Float>(startLocation.x, startLocation.y, startLocation.z) } let translation3D = value.translation3D // Rotate the drag vector such that its y-component becomes zero let theta = atan2(translation3D.y, translation3D.z) let cosTheta = cos(theta) let sinTheta = sin(theta) let rotatedX = translation3D.x let rotatedY = 0 // Force y to be zero let rotatedZ = theta >= 0 ? translation3D.y * sinTheta + translation3D.z * cosTheta : translation3D.z * cosTheta - translation3D.y * sinTheta let rotatedVector = SIMD3<Float>(Float(rotatedX), 0, Float(rotatedZ)) var newLocation3D = value.startLocation3D newLocation3D.x += Double(rotatedVector.x) newLocation3D.y += Double(rotatedVector.y) newLocation3D.z += Double(rotatedVector.z) // Convert the 3D location of the drag gesture to the entity's parent coordinate space let dragLocation = value.convert(newLocation3D, from: .local, to: value.entity.parent!) var newPosition = SIMD3<Float>(dragLocation.x, dragLocation.y, dragLocation.z) + initialDragOffset // don't modify y coordinate so that model remains standing on ground newPosition.y = value.entity.position.y // Set the entity's position to the new position value.entity.position = newPosition } .onEnded({ value in initialDragOffset = .zero }))
Topic: App & System Services SubTopic: Core OS Tags:
Aug ’23
Reply to Charts: customising chartYAxis values
I found that instead of parsing the encapsulated AxisValue you can transform it into the orginal value. For an Int I am doing it so: .chartXAxis() { AxisMarks(values: .stride(by: 1)) { let month = $0.as(Int.self)! } } The .stride(by: 1) overrides the automatic selection of marks.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’22
Reply to Xcode 16 RC - failed to download Predictive Code Completion Model
Same for me, Mac Studio M2
Replies
Boosts
Views
Activity
Sep ’24
Reply to Dragging horizontally with DragGesture
I found this to be working... is there a simpler way to achieve this? This takes the translation3D we get from the drag gesture, records an initialOffset (otherwise my entity jumps upward, because it has its origin in the bottom center). then it rotates the translation vector around x such that y becomes 0. Finally it converts it into the coordinate system of the entity's parent. Phew... .gesture(DragGesture() .targetedToAnyEntity() .onChanged { value in if initialDragOffset == .zero { // Calculate the initial drag offset at the beginning of the drag let startLocation = value.convert(value.startLocation3D, from: .local, to: value.entity.parent!) initialDragOffset = value.entity.position - SIMD3<Float>(startLocation.x, startLocation.y, startLocation.z) } let translation3D = value.translation3D // Rotate the drag vector such that its y-component becomes zero let theta = atan2(translation3D.y, translation3D.z) let cosTheta = cos(theta) let sinTheta = sin(theta) let rotatedX = translation3D.x let rotatedY = 0 // Force y to be zero let rotatedZ = theta >= 0 ? translation3D.y * sinTheta + translation3D.z * cosTheta : translation3D.z * cosTheta - translation3D.y * sinTheta let rotatedVector = SIMD3<Float>(Float(rotatedX), 0, Float(rotatedZ)) var newLocation3D = value.startLocation3D newLocation3D.x += Double(rotatedVector.x) newLocation3D.y += Double(rotatedVector.y) newLocation3D.z += Double(rotatedVector.z) // Convert the 3D location of the drag gesture to the entity's parent coordinate space let dragLocation = value.convert(newLocation3D, from: .local, to: value.entity.parent!) var newPosition = SIMD3<Float>(dragLocation.x, dragLocation.y, dragLocation.z) + initialDragOffset // don't modify y coordinate so that model remains standing on ground newPosition.y = value.entity.position.y // Set the entity's position to the new position value.entity.position = newPosition } .onEnded({ value in initialDragOffset = .zero }))
Topic: App & System Services SubTopic: Core OS Tags:
Replies
Boosts
Views
Activity
Aug ’23
Reply to Scene understanding missing from visionOS simulator?
Also found this, and reported it as FB.
Topic: Spatial Computing SubTopic: ARKit Tags:
Replies
Boosts
Views
Activity
Aug ’23
Reply to SwiftCharts: How to clip data to specific range?
Another problem is that my AreaMarks also go out of the visible area. So my more general question is to Apple: how does one deal with marks that are outside of the desired chart ranges for the x and y axes?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to SwiftCharts: how to manage colors and groupings
I found that LineMark and AreaMark have a series parameter by which a series can be grouped. By doing that I can set a static foregroundStyle for my percentile area marks while using the data-based foreground styles for the actual data line marks.
Topic: UI Frameworks SubTopic: General Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to Charts: customising chartYAxis values
I found that instead of parsing the encapsulated AxisValue you can transform it into the orginal value. For an Int I am doing it so: .chartXAxis() { AxisMarks(values: .stride(by: 1)) { let month = $0.as(Int.self)! } } The .stride(by: 1) overrides the automatic selection of marks.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22