所以我在 iOS8 和 Scene Kit 上做了很多工作。这是我不会让用户在屏幕上点击和 3D 模型指向用户点击的地方感到高兴。
shipAngle = [self calculateAngle:location.x :location.y :shipNode.position.x :shipNode.position.y];
shipNode.rotation = SCNVector4Make(0.0, 1.0, 0.0, shipAngle);
NSLog(@"shipAngle %f",shipAngle);
- (float) calculateAngle:(CGFloat)x1 :(CGFloat)y1 :(CGFloat)x2 :(CGFloat)y2
{
// DX
float x = x2 - x1;
// DY
float y = y2 - y1;
// Perform atan2 calculation as is inexpensive in comparison to atan
// to find tangent of angle.
float baseAngle = atan2(x, y);
// Convert to radians
float radians = baseAngle * (180.0 / M_PI);
// Adjust to give value ranging between 0 and 360.
CGFloat angle = 180 + radians;
return angle;
}