gpt4 book ai didi

objective-c - cocos2d - 如何在 3d 中定位 CCSprite?

转载 作者:行者123 更新时间:2023-12-04 18:15:31 25 4
gpt4 key购买 nike

我有一个圆盘 Sprite ,它总是围绕它的中心旋转,像轮子一样旋转。我想在 3d 空间中重新定位它并保持它的旋转。我试过弄乱网格属性、skewX/Y、相机,我能找到的一切,但我不知道如何通过旋转产生这种效果。
example

最佳答案

几条路线:

  • 找出数学以获得旋转值的正确偏斜值。 (我完全不知道,抱歉,尽管您可能可以从选项 2 对其进行逆向工程)
  • 你可以子类CCSprite , 覆盖 CCNode- (CGAffineTransform)nodeToParentTransform方法并且必须首先应用倾斜,然后旋转,以获得您想要的效果。这使您不必以相当笨拙的 Sprite 子类为代价来计算正确的偏斜计算。

  • 来自 CCNode.h您可以了解其当前的操作顺序:
     /* Order in transformations with grid disabled
    -# The node will be translated (position)
    -# The node will be rotated (rotation)
    -# The node will be skewed (skewX, skewY)
    -# The node will be scaled (scale, scaleX, scaleY)
    -# The node will be moved according to the camera values (camera)
    ... etc. */

    这是该方法的一个组合版本,首先带有倾斜:(缺少在 CCNode.m 中的原始方法中发现的优化)
    - (CGAffineTransform)nodeToParentTransform
    {
    if ( isTransformDirty_ ) {
    // Translate values
    float x = position_.x;
    float y = position_.y;

    if ( ignoreAnchorPointForPosition_ ) {
    x += anchorPointInPoints_.x;
    y += anchorPointInPoints_.y;
    }

    transform_ = CGAffineTransformMake(1.0f, tanf(CC_DEGREES_TO_RADIANS(skewY_)),
    tanf(CC_DEGREES_TO_RADIANS(skewX_)), 1.0f,
    x, y );
    // Rotation values
    float c = 1, s = 0;
    if( rotation_ ) {
    float radians = -CC_DEGREES_TO_RADIANS(rotation_);
    c = cosf(radians);
    s = sinf(radians);
    }

    CGAffineTransform rotMatrix = CGAffineTransformMake( c * scaleX_, s * scaleX_,
    -s * scaleY_, c * scaleY_,
    0.0f, 0.0f );
    transform_ = CGAffineTransformConcat(rotMatrix, transform_);

    // adjust anchor point
    if( ! CGPointEqualToPoint(anchorPointInPoints_, CGPointZero) )
    transform_ = CGAffineTransformTranslate(transform_, -anchorPointInPoints_.x, -anchorPointInPoints_.y);

    isTransformDirty_ = NO;
    }
    return transform_;
    }

    关于objective-c - cocos2d - 如何在 3d 中定位 CCSprite?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11822399/

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