简体   繁体   English

不了解这些C ++ box2d错误

[英]Don't understand these C++ box2d Errors

I've trying to get this C++ method to work in my iOS game. 我试图让这种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;
}

I know a fair bit about obj-c, but not C++. 我对obj-c相当了解,但对C ++却不太了解。 Here's a screen shot of the errors for that method it's showing. 这是该方法显示的错误的屏幕快照。

在此处输入图片说明

Any help appreciated (in Chrome you can do right click and open image in new tab to see it better) 感谢所有帮助(在Chrome中,您可以右键单击并在新标签页中打开图片以更好地查看它)

You need to be more explicit with the variables passed into the Objective-C function. 您需要更清晰地传递给Objective-C函数的变量。 You are passing without a type so it is not able to infer that it is actually a C++ type rather than an Objective-C type. 您所传递的没有类型,因此它无法推断它实际上是C ++类型而不是Objective-C类型。

Try something like: 尝试类似:

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

Edit : a quick check of the box2d docs says you need something like this: 编辑 :快速检查box2d文档说您需要这样的东西:

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

Edit 2 : Also worth noting that the Raycast function takes a third parameter childIndex as described in the docs . 编辑2 :同样值得注意的是,Raycast函数采用了文档中所述的第三个参数childIndex

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM