如何使用 Bullet 物理库设置碰撞?
嘿,我在 opengl/sfml 游戏中设置一些碰撞时遇到了一些“延迟”。这并不是什么大错误,只是寻求一些帮助。我正在使用子弹物理学(这是API参考),我一直在研究不同的功能和类。然后我注意到库中包含演示,所以在查看它们时我并不完全理解它们。
他们推荐我使用的主要库是 CollisionInterfaceDemo 因为我已经使用 GLM 用于 opengl 中的模型,并使用 sfml 用于 2D 目的和窗户。
我只是想知道是否有人知道我如何在游戏中实现碰撞。
hey im having a bit of a "delay" in setting up some collision in my opengl/sfml game. its not much of an error, just asking for some help. Im using Bullet Physics(this is the API reference) and i have been looking at the different functions and classes. then i noticed that there are demos included in the lbrary, so while looking them over i dont completely understand them..
the main library that they recommend me use is CollisionInterfaceDemo since i have already used GLM for models in opengl, and sfml for 2D purposes and the window.
im just wondering if anyone knows how i would be able to implement collision in my game.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定这是否是您想要的,但这是我的基本刚体物理设置代码:
之后只需向世界添加物体......
然后每帧更新世界状态即可。
这将为您提供一个简单的物理模拟,其中刚体相互碰撞和反弹,而 Bullet 则控制物体的移动方式。
Not sure if this is what you're after, but this is my setup code for basic rigid body physics:
After that it's just a matter of adding bodies to the world...
...and then updating the world state every frame.
That will give you a simple physics simulation with rigid bodies that collide and bounce off each other, with Bullet in control of the way bodies move.
如何将 BulletPhysics 插入 iOS:iOS OpenGL BulletPhysics 示例代码
下载示例代码或按照新项目进行操作使用 iOS openGL 模板形成 Xcode:
*(注意,有一个包含 Xcode 项目文件的项目文件夹)
1.5。在物理目录中运行 CMake 来编译框架(假设您已经安装了 cmake CMake )对于我上传的示例代码来说,此步骤是可选的,因为它已经包含了已编译的框架....这使得文件有 100 兆,但现在 100 兆是多少?
在 XCode 中转到您想要添加物理代码的任何文件...您必须了解 cpp 文件是 c++,而 .m .h 文件通常是 cocoa。您必须更改要添加物理引擎代码的类,使其具有 .mm 扩展名,表示它应编译为 Objective-C++ 代码...
在您要添加现在是目标的物理的特定类中-C++ 文件或 cpp 文件,添加行
<前><代码>#include“btBulletDynamicsCommon.h”
,您应该编译...错误是找不到该文件...
删除名为 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...
How to insert Bullet Physics into iOS: iOS OpenGL BulletPhysics Sample Code
Download the sample code or follow on a new project form Xcode with iOS openGL template:
*(notice that there is a folder for the project that contains the Xcode project file)
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?
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...
In the particular class you want to add the physics which is now an Objective-C++ file or a cpp file, add the line
and you should compile...the error is that the file is not found...
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...