box2d

Box2D - How can I know when 2 Fixtures are touching?

痴心易碎 提交于 2019-12-06 10:36:47
I'm just curious, in the case that I have a body that has 2 or more fixtures in it that are not "joined together", how can I determine this definitively in code? Here is an example of what I mean: I marked the vertices for each distinctive fixture just to make it completely clear that these are separate shapes which do not share vertices with each other. They are however combined into a single body. As you can see, two fixtures are within very close proximity to each other or "touching", and one is set apart by itself. I'm wondering how I can query the fixtures of a body in Box2D to be able to

Does Box2D Physics rely on the framerate?

谁说我不能喝 提交于 2019-12-06 09:28:58
I am making a 2D sidescroller game for Android and am thinking of using Box2D for the physics. I would like to know if when using Box2D, if the framerate of the device drops from 60 fps (Android's cap) to, for example, 30 fps will all the physics slow down with it? To elaborate, I'm going to be using real-time online multiplayer and so the framerate cannot be relied upon as a constant. So if one of the devices in the multiplayer game is running at 60 fps and another is at 30 fps and an object should be moving at 10 metres/second will it move at 5 metres/second on the slower device? I would

Box2D: How to manually render a body

99封情书 提交于 2019-12-06 09:22:20
I succeed installing Box2D into my project. But how can I render a body? Assume I'm using something that supports drawing polygons. I just want to find out the current positions of the vertices of the body-polygon, to draw it with the engine. If you can help me, I will be very thankful. I found it!!! void Box2DUtils::DrawBody(SDL_Surface *buffer, b2Body *body, int fr, int fg, int fb, int falpha, int lr, int lg, int lb, int lalpha, bool aa) { const b2Transform& xf = body->GetTransform(); for (b2Fixture* f = body->GetFixtureList(); f; f = f->GetNext()) { switch (f->GetType()) { case b2Shape::e

Game crashes when I try to destroy a b2Body, what should I do?

╄→гoц情女王★ 提交于 2019-12-06 07:50:00
"Assertion failed: (m_bodyCount < m_bodyCapacity), function Add, file libs/Box2D/Dynamics/b2Island.h, line 65." That is what it the crash leaves in the console. [self removeChild:(CCSprite*)body->GetUserData() cleanup:YES]; body->SetTransform(b2Vec2(30, 30), 0); //moving the body out of the scene so it doesnt collide anymore! world->DestroyBody(body); I think im doing the right stuff.. @property (nonatomic, assign) b2Body *body; Here is how i "make it" a property I dont understand why it doesnt work, "body" is a proper pointer because I can retrieve infromation from the bodys UserData like

LibGDX/Box2D UnsatisfiedLinkError

空扰寡人 提交于 2019-12-06 07:24:11
I'm using the EXACT same code as used in this tutorial but for some reason I get an error while trying to run the project. The default project for LibGDX worked fine. Error: Exception in thread "main" java.lang.UnsatisfiedLinkError: com.badlogic.gdx.physics.box2d.World.newWorld(FFZ)J at com.badlogic.gdx.physics.box2d.World.newWorld(Native Method) at com.badlogic.gdx.physics.box2d.World.<init>(World.java:222) at net.ocps.tchs.permarun.PermaRun.<init>(PermaRun.java:19) at net.ocps.tchs.permarun.Main.main(Main.java:14) Line it is referring to(the first line in the class): World world = new World

Box2D - Can't destroy multiple fixtures

爷,独闯天下 提交于 2019-12-06 04:17:34
I'm using box2d along with libgdx on a project I'm working on. I'm having a slight problem destroying a body/the fixtures of a body. Essentially, I want to completely destroy the body, which I do by destroying the fixtures of said body. Everything works perfectly fine with a body with one fixture, but when I use two fixtures, only one fixture get's destroyed, leaving the body intact with the other fixture. Here's two pictures to demonstrate what I mean: With both fixtures: With only one fixture: Here is how I create the body: BodyDef bodyDef = new BodyDef(); bodyDef.type = BodyType.DynamicBody

AndEngine Sprite/Box2D Body removal crashes my program with no error/exception information?

≡放荡痞女 提交于 2019-12-06 04:07:22
问题 I am making a skateboarding game with obstacles you have to jump over using box2D and AndEngine. I am trying to make it so that when the player collides with an object, the object is removed and an explosion is placed at the objects old position, however something in the sprite removal code is freezing my program causing it to end (not even a force close message it just closes itself and goes to my home screen) and no error/exception information appears in logcat so I have no idea what is

Box2d刚体轨迹预测

拟墨画扇 提交于 2019-12-06 02:03:03
前言 在游戏开发中经常会接触到各种物理引擎,虽然开源的引擎各种各样,但是基本原理是相通的。实质上物理引擎只是以时间为单位的刷新物理世界中的刚体的位置(其中运用了大量物理公式和知识),然后刷新刚体关联的物品(节点)的位置来达到模拟效果。其中的细节是我们开发者不需要知道,也不知道的。所以刚体轨迹预测成为了难题。 效果 物理公式 在开始之前先补一下高中基础物理公式(主要涉及匀加速直线运动): 速度公式 距离公式 阻尼公式 (比较贴近) 是指运动物体的 初始速度 , 是指运动物体的 运动时间 , 是指运动物体的 结束速度 , 是指运动物体 运动距离 , 是指运动物体的 运动加速度 , 是指运动物体的 阻尼系数 (模拟的空气阻尼等)。 即: //速度公式 v(v0, a, t) { return v0 + a * t; } //距离公式 s(v0, a, t) { return v0 * t + (a * t * t) / 2; } //阻尼公式 let damping = -this.linear_Damping * this.v_y * dt; this.v_y = this.v(this.v_y, this.a_y, dt) + damping; 运动分解 运动比较复杂,但是可以简单的拆解为X轴运动和Y轴运动,把运动简单化。 Y轴 阻尼系数: typescript this

SKPhysicsBody with restitution 0 still bounces

一个人想着一个人 提交于 2019-12-05 22:43:10
I'm am trying to drop the SKSpriteNode with constant speed and without bouncing. Here is the code I'm using: SKSpriteNode *floor = [SKSpriteNode spriteNodeWithColor:[UIColor clearColor] size:CGSizeMake(self.size.width, 1)]; floor.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:floor.size]; floor.physicsBody.restitution = 0.0f; floor.physicsBody.dynamic = NO; floor.physicsBody.allowsRotation = NO; SKSpriteNode* block = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed:imageName]]; block.position = CGPointMake(160, 300); block.physicsBody = [SKPhysicsBody

Typedef redefinition (C2371) for uint32 in two 3rd-party libraries

限于喜欢 提交于 2019-12-05 21:09:31
In my application I am using Box2D and Spidermonkey . Both libraries are defining the type uint32, which obviously gives me a compiler-error when using both in the same compilation unit. b2settings.h (Box2D): typedef unsigned int uint32; jsotypes.h (Spidermonkey): typedef unsigned long uint32; Is there any way to resolve this collision without needing to change the headers of the 3rd-party libraries? I am thankful for every hint! You can do this hack: #define uint32 Box2D_uint32 #include "Box2D.h" #undef uint32 #define uint32 Spider_uint32 #include "Spidermonkey.h" #undef uint32 Since typedef