Open csabau opened 2 years ago
This is a mess
Lets clean up the indentation
Those bodyDetected statements aren't helping anyone and the
guard`else
cases could be neater
private func updateJointScreenPositions(frame: ARFrame)
{
guard let detectedBody = frame.detectedBody
else
{
bodyIsDetected = false
return
}
bodyIsDetected = true
guard let interfaceOrientation = self.arView.window?.windowScene?.interfaceOrientation else { return }
let jointLandmarks = detectedBody.skeleton.jointLandmarks
// ---------------------------------------------------------------------------
// Convert the normalized joint points into screen-space CGPoints.
let transform = frame.displayTransform(for: interfaceOrientation,
viewportSize: self.arView.frame.size)
// ---------------------------------------------------------------------------
for i in 0..<jointLandmarks.count
{
if (jointLandmarks[i].x.isNaN || jointLandmarks[i].y.isNaN)
{
continue
}
let point = CGPoint(x: CGFloat(jointLandmarks[i].x),
y: CGFloat(jointLandmarks[i].y))
// -------------------------------------------------------------------------
// Convert from normalized pixel coordinates (0,0 top-left, 1,1 bottom-right) to screen-space coordinates.
let normalizedCenter = point.applying(transform)
let center = normalizedCenter.applying(CGAffineTransform.identity.scaledBy(x: self.arView.frame.width,
y: self.arView.frame.height))
self.jointScreenPositions[i] = center
// -------------------------------------------------------------------------
}
}
This isn't to say this is the best style, but definitely be consistent in what you are doing.
Now, is there anything stopping you from adding print(jointLandmarks[i].x, jointLandmarks[i].y)
into that for i in 0..<jointLandmarks.count
loop?
i.e.
private func updateJointScreenPositions(frame: ARFrame)
{
guard let detectedBody = frame.detectedBody
else
{
bodyIsDetected = false
return
}
bodyIsDetected = true
guard let interfaceOrientation = self.arView.window?.windowScene?.interfaceOrientation else { return }
let jointLandmarks = detectedBody.skeleton.jointLandmarks
// ---------------------------------------------------------------------------
// Convert the normalized joint points into screen-space CGPoints.
let transform = frame.displayTransform(for: interfaceOrientation,
viewportSize: self.arView.frame.size)
// ---------------------------------------------------------------------------
for i in 0..<jointLandmarks.count
{
if (jointLandmarks[i].x.isNaN || jointLandmarks[i].y.isNaN)
{
continue
}
let point = CGPoint(x: CGFloat(jointLandmarks[i].x),
y: CGFloat(jointLandmarks[i].y))
print(jointLandmarks[i].x, jointLandmarks[i].y)
// -------------------------------------------------------------------------
// Convert from normalized pixel coordinates (0,0 top-left, 1,1 bottom-right) to screen-space coordinates.
let normalizedCenter = point.applying(transform)
let center = normalizedCenter.applying(CGAffineTransform.identity.scaledBy(x: self.arView.frame.width,
y: self.arView.frame.height))
self.jointScreenPositions[i] = center
// -------------------------------------------------------------------------
}
}
print just after this line?
https://github.com/csabau/BTracking/blob/9cba6cd650fe3d50fb30d53a3a791f1e0fcd21ff/Sources/BodyTracking/BodyTracker2D.swift#L139