replate-camera 0.1.26 → 0.1.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -205,39 +205,39 @@ class ReplateCameraView: UIView, ARSessionDelegate {
|
|
|
205
205
|
createFocusSphere()
|
|
206
206
|
|
|
207
207
|
//DEBUG MESHES
|
|
208
|
-
// let xAxis = MeshResource.generateBox(width: 2, height: 0.001, depth: 0.01)
|
|
209
|
-
// let xLineEntity = ModelEntity(mesh: xAxis)
|
|
210
|
-
// xLineEntity.setPosition(SIMD3<Float>(0, 0, 0), relativeTo: ReplateCameraView.anchorEntity)
|
|
211
|
-
// xLineEntity.model?.materials = [SimpleMaterial(color: .red, isMetallic: false)]
|
|
212
|
-
// ReplateCameraView.anchorEntity.addChild(xLineEntity)
|
|
213
|
-
// let xLineLeftSphere = MeshResource.generateSphere(radius: ReplateCameraView.sphereRadius * 5)
|
|
214
|
-
// let xLineLeftSphereEntity = ModelEntity(mesh: xLineLeftSphere)
|
|
215
|
-
// ReplateCameraView.anchorEntity.addChild(xLineLeftSphereEntity)
|
|
216
|
-
// xLineLeftSphereEntity.setPosition(SIMD3<Float>(-1, 0.002, 0), relativeTo: ReplateCameraView.anchorEntity)
|
|
217
|
-
// xLineLeftSphereEntity.model?.materials = [SimpleMaterial(color: .red, isMetallic: false)]
|
|
218
|
-
// let xLineRightSphere = MeshResource.generateSphere(radius: ReplateCameraView.sphereRadius * 5)
|
|
219
|
-
// let xLineRightSphereEntity = ModelEntity(mesh: xLineRightSphere)
|
|
220
|
-
// ReplateCameraView.anchorEntity.addChild(xLineRightSphereEntity)
|
|
221
|
-
// xLineRightSphereEntity.setPosition(SIMD3<Float>(1, 0.002, 0), relativeTo: ReplateCameraView.anchorEntity)
|
|
222
|
-
// xLineRightSphereEntity.model?.materials = [SimpleMaterial(color: .yellow, isMetallic: false)]
|
|
223
|
-
// let yAxis = MeshResource.generateBox(width: 0.01, height: 0.001, depth: 2)
|
|
224
|
-
// let yLineEntity = ModelEntity(mesh: yAxis)
|
|
225
|
-
// yLineEntity.setPosition(SIMD3<Float>(0, 0, 0), relativeTo: ReplateCameraView.anchorEntity)
|
|
226
|
-
// let yLineLeftSphere = MeshResource.generateSphere(radius: ReplateCameraView.sphereRadius * 5)
|
|
227
|
-
// let yLineLeftSphereEntity = ModelEntity(mesh: yLineLeftSphere)
|
|
228
|
-
// ReplateCameraView.anchorEntity.addChild(yLineLeftSphereEntity)
|
|
229
|
-
// yLineLeftSphereEntity.setPosition(SIMD3<Float>(0, 0.002, -1), relativeTo: ReplateCameraView.anchorEntity)
|
|
230
|
-
// yLineLeftSphereEntity.model?.materials = [SimpleMaterial(color: .systemPink, isMetallic: false)]
|
|
231
|
-
// let yLineRightSphere = MeshResource.generateSphere(radius: ReplateCameraView.sphereRadius * 5)
|
|
232
|
-
// let yLineRightSphereEntity = ModelEntity(mesh: yLineRightSphere)
|
|
233
|
-
// ReplateCameraView.anchorEntity.addChild(yLineRightSphereEntity)
|
|
234
|
-
// yLineRightSphereEntity.setPosition(SIMD3<Float>(0, 0.002, 1), relativeTo: ReplateCameraView.anchorEntity)
|
|
235
|
-
// yLineRightSphereEntity.model?.materials = [SimpleMaterial(color: .orange, isMetallic: false)]
|
|
236
|
-
// yLineEntity.model?.materials = [SimpleMaterial(color: .purple, isMetallic: false)]
|
|
237
|
-
// ReplateCameraView.anchorEntity.addChild(yLineEntity)
|
|
238
|
-
// let circleEntity = ModelEntity(mesh: MeshResource.generateBox(size: 2, cornerRadius: 1))
|
|
239
|
-
// circleEntity.setPosition(SIMD3<Float>(0, 0, 0), relativeTo: ReplateCameraView.anchorEntity)
|
|
240
|
-
// circleEntity.model?.materials = [SimpleMaterial(color: .yellow, isMetallic: false)]
|
|
208
|
+
// let xAxis = MeshResource.generateBox(width: 2, height: 0.001, depth: 0.01)
|
|
209
|
+
// let xLineEntity = ModelEntity(mesh: xAxis)
|
|
210
|
+
// xLineEntity.setPosition(SIMD3<Float>(0, 0, 0), relativeTo: ReplateCameraView.anchorEntity)
|
|
211
|
+
// xLineEntity.model?.materials = [SimpleMaterial(color: .red, isMetallic: false)]
|
|
212
|
+
// ReplateCameraView.anchorEntity.addChild(xLineEntity)
|
|
213
|
+
// let xLineLeftSphere = MeshResource.generateSphere(radius: ReplateCameraView.sphereRadius * 5)
|
|
214
|
+
// let xLineLeftSphereEntity = ModelEntity(mesh: xLineLeftSphere)
|
|
215
|
+
// ReplateCameraView.anchorEntity.addChild(xLineLeftSphereEntity)
|
|
216
|
+
// xLineLeftSphereEntity.setPosition(SIMD3<Float>(-1, 0.002, 0), relativeTo: ReplateCameraView.anchorEntity)
|
|
217
|
+
// xLineLeftSphereEntity.model?.materials = [SimpleMaterial(color: .red, isMetallic: false)]
|
|
218
|
+
// let xLineRightSphere = MeshResource.generateSphere(radius: ReplateCameraView.sphereRadius * 5)
|
|
219
|
+
// let xLineRightSphereEntity = ModelEntity(mesh: xLineRightSphere)
|
|
220
|
+
// ReplateCameraView.anchorEntity.addChild(xLineRightSphereEntity)
|
|
221
|
+
// xLineRightSphereEntity.setPosition(SIMD3<Float>(1, 0.002, 0), relativeTo: ReplateCameraView.anchorEntity)
|
|
222
|
+
// xLineRightSphereEntity.model?.materials = [SimpleMaterial(color: .yellow, isMetallic: false)]
|
|
223
|
+
// let yAxis = MeshResource.generateBox(width: 0.01, height: 0.001, depth: 2)
|
|
224
|
+
// let yLineEntity = ModelEntity(mesh: yAxis)
|
|
225
|
+
// yLineEntity.setPosition(SIMD3<Float>(0, 0, 0), relativeTo: ReplateCameraView.anchorEntity)
|
|
226
|
+
// let yLineLeftSphere = MeshResource.generateSphere(radius: ReplateCameraView.sphereRadius * 5)
|
|
227
|
+
// let yLineLeftSphereEntity = ModelEntity(mesh: yLineLeftSphere)
|
|
228
|
+
// ReplateCameraView.anchorEntity.addChild(yLineLeftSphereEntity)
|
|
229
|
+
// yLineLeftSphereEntity.setPosition(SIMD3<Float>(0, 0.002, -1), relativeTo: ReplateCameraView.anchorEntity)
|
|
230
|
+
// yLineLeftSphereEntity.model?.materials = [SimpleMaterial(color: .systemPink, isMetallic: false)]
|
|
231
|
+
// let yLineRightSphere = MeshResource.generateSphere(radius: ReplateCameraView.sphereRadius * 5)
|
|
232
|
+
// let yLineRightSphereEntity = ModelEntity(mesh: yLineRightSphere)
|
|
233
|
+
// ReplateCameraView.anchorEntity.addChild(yLineRightSphereEntity)
|
|
234
|
+
// yLineRightSphereEntity.setPosition(SIMD3<Float>(0, 0.002, 1), relativeTo: ReplateCameraView.anchorEntity)
|
|
235
|
+
// yLineRightSphereEntity.model?.materials = [SimpleMaterial(color: .orange, isMetallic: false)]
|
|
236
|
+
// yLineEntity.model?.materials = [SimpleMaterial(color: .purple, isMetallic: false)]
|
|
237
|
+
// ReplateCameraView.anchorEntity.addChild(yLineEntity)
|
|
238
|
+
// let circleEntity = ModelEntity(mesh: MeshResource.generateBox(size: 2, cornerRadius: 1))
|
|
239
|
+
// circleEntity.setPosition(SIMD3<Float>(0, 0, 0), relativeTo: ReplateCameraView.anchorEntity)
|
|
240
|
+
// circleEntity.model?.materials = [SimpleMaterial(color: .yellow, isMetallic: false)]
|
|
241
241
|
|
|
242
242
|
|
|
243
243
|
ReplateCameraView.arView.scene.anchors.append(ReplateCameraView.anchorEntity)
|
|
@@ -484,8 +484,10 @@ class ReplateCameraController: NSObject {
|
|
|
484
484
|
print("Point 1 position: \(point1) Point 2 position: \(point2)")
|
|
485
485
|
print("Angle to first: ", angleToFirstPoint, " Angle to second: ", angleToSecondPoint)
|
|
486
486
|
print("Threshold \(dynamicThreshold)")
|
|
487
|
-
let
|
|
488
|
-
let
|
|
487
|
+
let anchorTransform = anchorNode.transformMatrix(relativeTo: nil)
|
|
488
|
+
let relativePosition = anchorTransform.inverse * cameraTransform
|
|
489
|
+
let isPointingAtFirstPoint = angleToFirstPoint < dynamicThreshold && relativePosition.columns.3.y < ReplateCameraView.spheresHeight + (ReplateCameraView.distanceBetweenCircles / 2)
|
|
490
|
+
let isPointingAtSecondPoint = angleToSecondPoint < dynamicThreshold && relativePosition.columns.3.y >= ReplateCameraView.spheresHeight + (ReplateCameraView.distanceBetweenCircles / 2)
|
|
489
491
|
if (isPointingAtFirstPoint) {
|
|
490
492
|
deviceTargetInFocus = 0
|
|
491
493
|
} else if (isPointingAtSecondPoint) {
|
|
@@ -602,7 +604,7 @@ class ReplateCameraController: NSObject {
|
|
|
602
604
|
print("ANGLE: \(angleDegrees)")
|
|
603
605
|
// Convert angle to a 0-71 index range
|
|
604
606
|
// Ensure we floor the value so that we get a whole number for the index
|
|
605
|
-
let sphereIndex = max(Int(
|
|
607
|
+
let sphereIndex = max(Int(round(angleDegrees / 5.0 - 2.5)), 0) % 72 // Ensure sphereIndex stays within 0-71 bounds
|
|
606
608
|
print("---- METRICHE DA DEBUGGARE: -----")
|
|
607
609
|
print(sphereIndex)
|
|
608
610
|
print(anchorNode.position.y + ReplateCameraView.spheresHeight + (ReplateCameraView.distanceBetweenCircles / 2))
|
|
@@ -652,7 +654,6 @@ class ReplateCameraController: NSObject {
|
|
|
652
654
|
static func angleBetweenAnchorXAndCamera(anchor: AnchorEntity, cameraTransform: simd_float4x4) -> Float {
|
|
653
655
|
// Extract the position of the anchor and the camera from their transforms, ignoring the y-axis
|
|
654
656
|
let anchorPositionXZ = simd_float2(anchor.transform.translation.x, anchor.transform.translation.z)
|
|
655
|
-
|
|
656
657
|
// Transform the camera position to the anchor's local space
|
|
657
658
|
let anchorTransform = anchor.transformMatrix(relativeTo: nil)
|
|
658
659
|
let relativePosition = anchorTransform.inverse * cameraTransform
|
|
@@ -664,13 +665,18 @@ class ReplateCameraController: NSObject {
|
|
|
664
665
|
// Extract the x-axis of the anchor's transform in the XZ plane
|
|
665
666
|
let anchorXAxisXZ = simd_float2(anchorTransform.columns.0.x, anchorTransform.columns.0.z)
|
|
666
667
|
|
|
667
|
-
//
|
|
668
|
-
let
|
|
669
|
-
let angle = acos(cosineAngle)
|
|
668
|
+
// Use atan2 to calculate the angle between the anchor's x-axis and the direction vector in the XZ plane
|
|
669
|
+
let angle = atan2(directionXZ.y, directionXZ.x) - atan2(anchorXAxisXZ.y, anchorXAxisXZ.x)
|
|
670
670
|
|
|
671
|
-
//
|
|
672
|
-
|
|
673
|
-
|
|
671
|
+
// Convert the angle to degrees
|
|
672
|
+
var angleDegrees = angle * (180.0 / .pi)
|
|
673
|
+
|
|
674
|
+
// Ensure the angle is within the range [0, 360)
|
|
675
|
+
if angleDegrees < 0 {
|
|
676
|
+
angleDegrees += 360
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
return angleDegrees
|
|
674
680
|
}
|
|
675
681
|
|
|
676
682
|
}
|