如何计算 SCNText 的中心与其左右角之间的距离
How to calculate the distance between a SCNText's Center and its Left and Right Corners
如何计算 SCNText 中心与其左边缘角和右边缘角之间的距离。
例如,使用下面的代码,如果单词是 "texas",字母 "x" 的中间部分将是 pivot point
,因为它位于单词的中间。我如何获得字母 "t" 左侧和字母 "x" 之间的距离。我如何获得字母右侧 "s" 和字母 "x"
之间的距离
let material = SCNMaterial()
material.diffuse.contents = UIColor.red
let geometry = SCNText(string: "texas", extrusionDepth: 0.1)
geometry.flatness = 0
geometry.font = UIFont.systemFont(ofSize: 6.3)
geometry.materials = [material]
let textNode = SCNNode()
textNode.geometry = geometry
textNode.geometry?.firstMaterial?.isDoubleSided = true
// set pivot point
let min = textNode.boundingBox.min
let max = textNode.boundingBox.max
textNode.pivot = SCNMatrix4MakeTranslation(
min.x + (max.x - min.x)/2,
min.y + (max.y - min.y)/2,
min.z + (max.z - min.z)/2
)
let totalWidth: Float = textNode.boundingBox.max.x - textNode.boundingBox.min.x
let halfWidth: Float = totalWidth / 2
print("total width:", totalWidth)
print("half width:", halfWidth)
如何计算 SCNText 中心与其左边缘角和右边缘角之间的距离。
例如,使用下面的代码,如果单词是 "texas",字母 "x" 的中间部分将是 pivot point
,因为它位于单词的中间。我如何获得字母 "t" 左侧和字母 "x" 之间的距离。我如何获得字母右侧 "s" 和字母 "x"
let material = SCNMaterial()
material.diffuse.contents = UIColor.red
let geometry = SCNText(string: "texas", extrusionDepth: 0.1)
geometry.flatness = 0
geometry.font = UIFont.systemFont(ofSize: 6.3)
geometry.materials = [material]
let textNode = SCNNode()
textNode.geometry = geometry
textNode.geometry?.firstMaterial?.isDoubleSided = true
// set pivot point
let min = textNode.boundingBox.min
let max = textNode.boundingBox.max
textNode.pivot = SCNMatrix4MakeTranslation(
min.x + (max.x - min.x)/2,
min.y + (max.y - min.y)/2,
min.z + (max.z - min.z)/2
)
let totalWidth: Float = textNode.boundingBox.max.x - textNode.boundingBox.min.x
let halfWidth: Float = totalWidth / 2
print("total width:", totalWidth)
print("half width:", halfWidth)