旋转到对象场景工具包

时间:2014-07-01 18:57:35

标签: ios xcode object rotation scenekit

所以我在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;
}

0 个答案:

没有答案