在 XCode 4 中为 iOS 设置 Bullet Physics
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6575289/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting up Bullet Physics for iOS in XCode 4
提问by Claudia
So, I have downloaded the latest Bullet Physics package (2.78) and I have read the "Getting Started" documentation, which even includes an article on setting up a project in XCode from scratch (but not targeted at iOS nor XCode 4, which is what I'm using). Even so, I am still not able to set this up.
所以,我已经下载了最新的 Bullet Physics 包 (2.78) 并阅读了“入门”文档,其中甚至包括一篇关于从头开始在 XCode 中设置项目的文章(但不针对 iOS 或 XCode 4,这是我在用什么)。即便如此,我仍然无法设置它。
The following are the steps I'm currently taking:
以下是我目前正在采取的步骤:
I'm adding the Bullet Physics "src" folder in the classes of the Xcode
I'm including the Bullet Physics "src" folder path in the debug and release "Header Search Paths" in XCode
I add #include "btBulletDynamicsCommon.h" to the file where I want to use Bullet Physics
I change the Objective-C file to Objective-C++ by changing its file extension from "m" to "mm". This is the file where the "btBulletDynamicsCommon.h" is included
我在 Xcode 的类中添加了 Bullet Physics“src”文件夹
我在调试中包含 Bullet Physics“src”文件夹路径,并在 XCode 中发布“Header Search Paths”
我将 #include "btBulletDynamicsCommon.h" 添加到要使用 Bullet Physics 的文件中
我通过将文件扩展名从“m”更改为“mm”,将 Objective-C 文件更改为 Objective-C++。这是包含“btBulletDynamicsCommon.h”的文件
After I follow these steps, the compiler complaints about missing files (first few errors, there are 999+ errors shown when I try to build).
在我按照这些步骤操作后,编译器抱怨缺少文件(前几个错误,当我尝试构建时显示了 999 多个错误)。
These are the first few headers missing in the btSoftBodySolverVertexBuffer_DX11.h:
这些是 btSoftBodySolverVertexBuffer_DX11.h 中缺少的前几个头文件:
#include <windows.h>
#include <crtdbg.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dcompiler.h>
Now, I'm pretty new with XCode and iOS, so the fact that these are missing doesn't really tell me much on how to solve this issue, and it makes me even wonder if they are at all needed for iOSdevelopment given the appended "DX11" on the file name that is having this issue.
现在,我对 XCode 和 iOS 还很陌生,所以缺少这些并不能真正告诉我如何解决这个问题,这让我什至想知道iOS开发是否需要它们在出现此问题的文件名上附加了“DX11”。
So, what I would appreciate is either information on what's possibly wrong, or information on how to set up Bullet Physics to be used with iOSin XCode 4, from scratch.
因此,我希望了解有关可能出错的信息,或者有关如何从头开始设置用于在 XCode 4 中与iOS一起使用的 Bullet Physics 的信息。
Thanks.
谢谢。
Update: I have completely removed the DX11 and OpenCL and I'm now able to compile after step 4 above. I have not yet actually tested the Bullet Physics framework to see if it works without issues. But this now leads me to ask:
更新:我已经完全删除了 DX11 和 OpenCL,现在我可以在上面的第 4 步之后进行编译。我还没有真正测试过 Bullet Physics 框架,看看它是否可以正常工作。但这现在让我问:
What are the specific source files/folders that are strictly necessary to run Bullet Physics in iOS?
在 iOS 中运行 Bullet Physics 绝对需要哪些特定的源文件/文件夹?
回答by Orbitus007
How to insert Bullet Physics into iOS: iOS OpenGL BulletPhysics Sample Code
如何将 Bullet Physics 插入 iOS:iOS OpenGL BulletPhysics 示例代码
Download the sample code or follow on a new project form Xcode with iOS openGL template:
下载示例代码或使用 iOS openGL 模板在 Xcode 中创建一个新项目:
- Download bullet physics... put it into a folder like the following:
- 下载子弹物理...将其放入如下文件夹中:
*(notice that there is a folder for the project that contains the Xcode project file)
*(注意有一个包含Xcode项目文件的项目文件夹)
/MyProjectFolder/bullet-2.78/
/MyProjectFolder/MyProject/MyProject.xcproj
1.5. Run CMake in the physics directory to compile the frameworks (assuming you installed cmake already CMake) This step is optional with the sample code I uploaded since it already included the compiled frameworks in it....that made the file 100 megs but what is 100 megs these days anyway?
1.5. 在physics 目录中运行CMake 以编译框架(假设您已经安装了cmake CMake)这一步对于我上传的示例代码是可选的,因为它已经包含了编译的框架......这使得文件100 megs 但什么是这些天还是 100 兆?
cmake . -G "Unix Makefiles" -DINSTALL_LIBS=ON -DBUILD_SHARED_LIBS=ON -DFRAMEWORK=ON -DCMAKE_OSX_ARCHITECTURES='i386;x86_64' -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/Library/Frameworks -DCMAKE_INSTALL_NAME_DIR=/Library/Frameworks -DBUILD_DEMOS:BOOL=OFF
make -j4
sudo make install
- Goto your MyProject.xcproj and open in Xcode...
- 转到您的 MyProject.xcproj 并在 Xcode 中打开...
in XCode goto any file you wish to add the physics code to... you must understand that cpp files are c++ and .m .h files are generally cocoa. You must change the Class you wish to add the physics engine code to have a .mm extension signifying it should be compiled as Objective-C++ code...
在 XCode 中,转到您希望将物理代码添加到的任何文件...您必须了解 cpp 文件是 c++,而 .m .h 文件通常是可可。您必须更改要添加物理引擎代码的类,使其具有 .mm 扩展名,表示它应该编译为 Objective-C++ 代码...
In the particular class you want to add the physics which is now an Objective-C++ file or a cpp file, add the line
#include "btBulletDynamicsCommon.h"
在要添加物理的特定类中,现在是一个 Objective-C++ 文件或 cpp 文件,添加行
#include "btBulletDynamicsCommon.h"
and you should compile...the error is that the file is not found...
你应该编译...错误是找不到文件...
- Next goto the MyProjectFolder/bullet-2.78/src and drag the src folder into your project.
Delete the folder named BulletMultiThread...it will eliminate the error of trying to compile some openCL (.cl) files
Last step, copy the following frameworks from the src folder of your bullet physics installation into your project:
/MyProjectFolder/bullet-2.78/LinearMath/LinearMath.framework /MyProjectFolder/bullet-2.78/BulletCollision/BulletCollision.framework /MyProjectFolder/bullet-2.78/LinearMath/LinearMath.framework
Build and Run... should compile smoothly to iOS and Mac now...
- 接下来转到 MyProjectFolder/bullet-2.78/src 并将 src 文件夹拖到您的项目中。
删除名为 BulletMultiThread 的文件夹...它将消除尝试编译某些 openCL (.cl) 文件的错误
最后一步,将以下框架从您的项目符号物理安装的 src 文件夹复制到您的项目中:
/MyProjectFolder/bullet-2.78/LinearMath/LinearMath.framework /MyProjectFolder/bullet-2.78/BulletCollision/BulletCollision.framework /MyProjectFolder/bullet-2.78/LinearMath/LinearMath.framework
构建并运行...现在应该可以顺利编译到 iOS 和 Mac...
回答by iOS programming book
There is a tutorial with step by step instruction for integrating Bullet Physics with iOS and Apple's GLKit framework http://www.informit.com/articles/article.aspx?p=1914612
有一个教程,其中包含将 Bullet Physics 与 iOS 和 Apple 的 GLKit 框架集成的分步说明http://www.informit.com/articles/article.aspx?p=1914612
The example code downloadable with the tutorial will get you started quickly and produces an interesting simulation.
可与教程一起下载的示例代码将使您快速入门并生成有趣的模拟。
回答by Fonix
i found Orbitus007's answer a little miss leading. You can just add the bullet physics frameworks to the project instead of adding the whole src folder to your project. adding the src folder gave me errors and just adding the frameworks made my project compile
我发现 Orbitus007 的回答有点领先。您可以将子弹物理框架添加到项目中,而不是将整个 src 文件夹添加到您的项目中。添加 src 文件夹给了我错误,只是添加框架使我的项目编译
should look something like this http://imgur.com/CINtb
应该看起来像这样http://imgur.com/CINtb
you can then just go
然后你可以去
#import "BulletDynamics/btBulletDynamicsCommon.h"
you will still need to have your file with the .mm extension
您仍然需要使用 .mm 扩展名的文件
also, i found that i got an error when trying to use cmake saying something about xcode-select. if you get it try run this command in the terminal, then try again
另外,我发现在尝试使用 cmake 说一些有关 xcode-select 的内容时出现错误。如果你得到它尝试在终端中运行这个命令,然后再试一次
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
but other than that, his answer helped me get it working
但除此之外,他的回答帮助我让它发挥作用
回答by Claudia
OK, so as an update and to answer my own question:
好的,作为更新并回答我自己的问题:
I ended up deleting the folders DX11 and OpenCL and their content. This has so far allowed me to run a few Hello World tests.
我最终删除了文件夹 DX11 和 OpenCL 及其内容。到目前为止,这让我可以运行一些 Hello World 测试。
I still welcome more assertive answers, given it seems strange to me that I can't find any documentation covering this for iOS usage.
我仍然欢迎更自信的答案,因为我似乎很奇怪我找不到任何涵盖 iOS 使用的文档。