iPhone轮(命运)旋转动力

bas*_*svk 4 iphone objective-c touch angular-momentum

我在为我的纺车增加动力方面遇到了困难.
我有这个轮子(类似这样的东西)并且我通过使用单个触摸事件在它的中心旋转它.
这里没有问题,但是当触摸(又名拖动)结束时; 我希望方向盘保持它的动量并缓解它的运动.

任何能给我一些指示的人,都不一定要在客观方面.AS3,javascript或JAVA也足够了.

*更新(旋转车轮的代码)*

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        rotation = _startAngle = atan2(384 - touchPoint.y, 512 - touchPoint.x);
    };

    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        CGPoint touchPoint = [[touches anyObject] locationInView:self.view];
        rotation = atan2(384 - touchPoint.y, 512 - touchPoint.x);
        rotation = fmod(rotation - _startAngle, M_PI * 2.0f);
        [wheel setTransform:CGAffineTransformMakeRotation(_circleRotationOffset + rotation)];   
    };

    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        _circleRotationOffset = fmod(_circleRotationOffset + rotation, M_PI * 2);
    };
Run Code Online (Sandbox Code Playgroud)

Tom*_*mmy 5

你希望动量因摩擦而减少; 摩擦力是速度的函数.所以从技术上讲,你已经有了一个微分方程式.然而,这并不值得投入太多的思考,因为解决方案可能更容易通过手挥手达到.

因此:存储当前角度和当前角速度.n次秒(可能通过a NSTimer或a CADisplayLink)将角速度加到角度上,然后将角速度乘以某个值使其变小 - 例如0.995.接近1.0的常数将使得减速需要更长的时间; 如果你超过1.0,它显然会加速.这实际上是欧拉整合的一种形式,但同样值得担忧.

它也可能值得给角速度设置一个最小上限,这样如果它下降到0.01弧度/秒,那么你将它快速降低到0.这有效地修改了你的摩擦模型,在适当的时刻从动能跳到静摩擦,并充当浮点精度缓冲区.

要从拖动中获取初始速度,您可以计算出从滚轮中心到拖动开始的向量,将该向量旋转90度,使用该向量做一个点积,并根据距离从中心.