gpt4 book ai didi

iphone - 3D 立方体问题,第 2 部分

转载 作者:太空狗 更新时间:2023-10-30 03:43:37 25 4
gpt4 key购买 nike

这是我在 iPhone 中使用 CALayer 的 3D 立方体的第二个问题,CALayer 是用 Objective-c 编写的核心动画框架。对于我的第一个问题,请访问此处 3D Cube Problem! Part 1 .

我正在使用 Brad Larsons 代码从这个链接旋转我的 3D 立方体

http://www.sunsetlakesoftware.com/2008/10/22/3-d-rotation-without-trackball

问题是我的立方体沿着图中粉红色的线在 x 轴上旋转。

enter image description here

但是我想沿着图中黑线绕x轴旋转。
现在在我的代码中,我的 View 上没有画任何粉红色的线或黑色的线,所以有人可以帮我解决这个问题。

如果这里有帮助,请查看在touchesMoved: 方法中旋转我的立方体的代码

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
CGPoint location = [[touches anyObject] locationInView:self];
CATransform3D currentTransform = currentLayer.sublayerTransform;
CGFloat displacementInX = location.x - previousLocation.x;
CGFloat displacementInY = previousLocation.y - location.y;
CGFloat totalRotation = sqrt(displacementInX * displacementInX + displacementInY * displacementInY);
CGFloat x = (displacementInX/totalRotation) * currentTransform.m12 + (displacementInY/totalRotation) * currentTransform.m11;
CATransform3D rotationalTransform = CATransform3DRotate(currentTransform, totalRotation * M_PI / 180.0, x, y, 0);
currentLayer.sublayerTransform = rotationalTransform;
}

previousLocation 是在 touchesBegan: 方法中初始化的 CGPoint,currentLayer 是我创建此立方体的 CALayer

感谢您的帮助。

附言。如果您想知道我是如何创建这个立方体的,请告诉我

最佳答案

看起来您需要先平移层,然后再旋转它们。

您可以先使用 CATransform3DTranslate 将图层从其自然原点平移,然后再使用 CATransform3DRotate,而不是选择轴心点/ anchor 。

查看您如何构建多维数据集以查明如何实现它会有所帮助。

关于iphone - 3D 立方体问题,第 2 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6278658/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com