我有一个带有四个顶点的平面。可以绕z轴(0,0,1)旋转。(使用金属中的模型矩阵实现。)根据旋转手势更改模型矩阵。
所以我需要做的是绕z轴旋转任意(x,y)的平面,其中x,y不等于零,这意味着绕垂直于xy的轴旋转平面(x ,y)点。
好吗?
答案 0 :(得分:0)
这对我有用。在这里,dragCanvas方法更改了模型matix中的转换,而rotateCanvas更改了其旋转。您可以实现自己的方法。 Metod convertCoodinates按照https://developer.apple.com/documentation/metal/hello_triangle
中的描述映射坐标系以适合@objc func rotate(rotateGesture: UIRotationGestureRecognizer){
guard rotateGesture.view != nil else { return }
let location = rotateGesture.location(in: self.view)
var rotatingAnchorPoint = convertCoodinates(tapx:location.x , tapy:location.y )
if rotateGesture.state == UIGestureRecognizerState.changed {
print("rotation:\(rotateGesture.rotation)")
renderer?.dargCanvas(axis:float3(Float(rotatingAnchorPoint.x) ,Float(rotatingAnchorPoint.y ),0))
renderer?.rotateCanvas(rotation:Float(rotateGesture.rotation))
renderer?.dargCanvas(axis:float3(Float(-rotatingAnchorPoint.x ) ,Float(-rotatingAnchorPoint.y ),0))
rotateGesture.rotation = 0
} else if rotateGesture.state == UIGestureRecognizerState.began {
}else if rotateGesture.state == UIGestureRecognizerState.ended{
}
}