I’ve a 3d mannequin rendered on display screen for hit take a look at. That is my code:
let audio = strive! await ModelEntity(named: "audio.usdz", in: nil)
audio.place = simd_float3(x: 0, y: 0, z: 0)
let scale: Float = 0.5
audio.scale = simd_float3(x: scale, y: scale, z: scale)
let form = strive! await ShapeResource.generateConvex(from: audio.mannequin!.mesh)
audio.collision = CollisionComponent(shapes: [shape], mode: .colliding, filter: .default)
anchor.addChild(audio)
let digital camera = PerspectiveCamera()
let rotation = Rework(pitch: -.pi / 2, yaw: 0, roll: 0).rotation
let place = simd_float3(x: 0, y: 100, z: 0)
digital camera.rework = Rework(scale: .one, rotation: rotation, translation: place)
digital camera.digital camera.fieldOfViewInDegrees = 60
For example the issue, I name hitTest on a second matrix of dots, the place inexperienced means hit, and purple means not hit:
let hole = 10
for i in 0..<Int(view.body.width)/hole {
for j in 0..<Int(view.body.top)/hole {
let x = CGFloat(i * hole)
let y = CGFloat(j * hole)
let dot = UIView(body: CGRect(x: x, y: y, width: 2, top: 2))
arView.addSubview(dot)
if arView.hitTest(CGPoint(x: x, y: y), question: .nearest, masks: .all).isEmpty {
dot.backgroundColor = .purple
} else {
dot.backgroundColor = .inexperienced
}
}
}
I acquired this consequence:
Then I modified the fieldOfViewOrientation
from the default (vertical) to horizontal:
digital camera.digital camera.fieldOfViewOrientation = .horizontal
Then I acquired this:
You’ll be able to obtain my full instance right here: https://drive.google.com/file/d/1ntuq3YyBQ4454QWNGAuN9fV8MyERl7CP/view?usp=sharing
It seems to be like there is a "ghost" digital camera with default configuration that decides what the collision ought to seem like, whereas the mannequin rendering itself is predicated alone digital camera.
How can I ensure that hit take a look at is predicated on my present digital camera (which is clearly what we would like)?