c++ - 不理解这些 C++ box2d 错误

标签 c++ ios objective-c xcode box2d

我试图让这个 C++ 方法在我的 iOS 游戏中工作。

-(b2Vec2) RayCheckWithInput:p1 andX:p2
{
    b2RayCastInput input;
    input.p1 = p1;
    input.p2 = p2;
    input.maxFraction = 1;

    //check every fixture of every body to find closest
    float closestFraction = 1; //start with end of line as p2
    b2Vec2 intersectionNormal(0,0);
    for (b2Body* b = self.world.world->GetBodyList(); b; b = b->GetNext()) {
        for (b2Fixture* f = b->GetFixtureList(); f; f = f->GetNext()) {

            b2RayCastOutput output;
            if ( ! f->RayCast( &output, input ) )
                continue;
            if ( output.fraction < closestFraction ) {
                closestFraction = output.fraction;
                intersectionNormal = output.normal;
            }
        }
    }

    b2Vec2 intersectionPoint = p1 + closestFraction * (p2 - p1);

    return intersectionPoint;
}

我对 obj-c 了解一些,但对 C++ 了解不多。这是它显示的该方法错误的屏幕截图。

enter image description here

感谢任何帮助(在 Chrome 中,您可以右键单击并在新标签页中打开图片以更好地查看)

最佳答案

您需要更明确地处理传递给 Objective-C 函数的变量。您在没有类型的情况下传递,因此无法推断它实际上是 C++ 类型而不是 Objective-C 类型。

尝试这样的事情:

-(b2Vec2) RayCheckWithInput: (CPPTye*)p1 andX: (CPPTye*)p2

编辑:快速检查 box2d 文档说您需要这样的东西:

-(b2Vec2) RayCheckWithInput: (b2Vec2)p1 andX: (b2Vec2)p2

编辑 2:同样值得注意的是,Raycast 函数采用第三个参数 childIndex,如 docs 中所述。 .

关于c++ - 不理解这些 C++ box2d 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26205594/

相关文章:

ios - DateFormatter 不返回 "HH:mm:ss"的日期

c++ - 四舍五入到一个数字的最接近的倍数

c++ - 为什么我不能返回对压缩字段的引用?

c++ - 我不明白这个重载是如何解决的 "works"

c++ - 显示多值链表

ios - AddressBookUI View Controller 在 iOS 7 中的行为不符合预期

ios - 带 slider 的自定义 UITableViewCell

ios - NSOutputStream 的 hasSpaceAvailable 方法总是返回 False

ios - 无法将类型 'NSTaggedPointerString' 的值转换为数组

iOS 8 Facebook 共享链接、图像和文本