Ios 二进制运算符'*';无法应用于类型为';SConverctor3';和';双倍';

Ios 二进制运算符'*';无法应用于类型为';SConverctor3';和';双倍';,ios,xcode,swift4,arkit,Ios,Xcode,Swift4,Arkit,我需要将SCNVactor3乘以0.1才能得到一个新的位置。当我尝试这样做的时候,我得到了下面的错误。这在以前的Xcode版本中是可行的。我使用的是带有Swift 4版本编译器的Xcode 10.1。我已经看到了同类问题的其他答案,但这里的数据类型不同 Binary operator '*' cannot be applied to operands of type 'SCNVector3' and 'Double' 下面是我使用的代码 guard let pointOfView = s

我需要将SCNVactor3乘以0.1才能得到一个新的位置。当我尝试这样做的时候,我得到了下面的错误。这在以前的Xcode版本中是可行的。我使用的是带有Swift 4版本编译器的Xcode 10.1。我已经看到了同类问题的其他答案,但这里的数据类型不同

Binary operator '*' cannot be applied to operands of type 'SCNVector3' and 'Double'
下面是我使用的代码

   guard let pointOfView = sceneView.pointOfView else { return }

    let mat = pointOfView.transform
    let dir = SCNVector3(-1 * mat.m31, -1 * mat.m32, -1 * mat.m33)
让currentPosition=pointOfView.position+(dir*0.1)---> 在此处获取错误


未为操作数
SCConvert3
Double
定义运算符
*

我猜通过
someVector*0.1
,你的意思是将向量的每个分量乘以0.1

在这种情况下,您可以定义自己的
*
运算符:

// put this in the global scope
func *(lhs: SCNVector3, rhs: Double) -> SCNVector3 {
    return SCNVector3(lhs.x * CGFloat(rhs), lhs.y * CGFloat(rhs), lhs.z * CGFloat(rhs))
}

// usage
SCNVector3(1, 2, 3) * 0.1 // (0.1, 0.2, 0.3)

把这个放到你的项目中,它应该会起作用

    public static func * (lhs: SCNVector3, rhs: Double) -> SCNVector3 {
        return SCNVector3(lhs.x * .init(rhs), lhs.y * .init(rhs), lhs.z * .init(rhs))
    }

    public static func * (lhs: Double, rhs: SCNVector3) -> SCNVector3 {
        return rhs * lhs
    }
}
    public static func * (lhs: SCNVector3, rhs: Double) -> SCNVector3 {
        return SCNVector3(lhs.x * .init(rhs), lhs.y * .init(rhs), lhs.z * .init(rhs))
    }

    public static func * (lhs: Double, rhs: SCNVector3) -> SCNVector3 {
        return rhs * lhs
    }
}