gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 04:00:37 24 4
gpt4 key购买 nike

我试图让这个 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/

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