我有一个有四个顶点的平面。它可以绕z轴(0, 0,1)旋转。(实现在金属中使用模型矩阵)。模型矩阵根据旋转手势进行更改。
所以我需要做的是通过任意(x,y)围绕z轴旋转平面,其中x,y不等于零。这意味着围绕垂直于xy平面的轴旋转平面并通过(x,y)观点。
请问有什么建议吗?
这对我有用。在这里,dragCanvas 方法更改模型 matix 中的平移,而 rotateCanvas 更改其旋转。您可以实现自己的方法。方法 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{
}
}