box2d

Applying a vortex / whirlpool effect in Box2d / Cocos2d for iPhone

回眸只為那壹抹淺笑 提交于 2019-11-29 12:53:50
I've used Nick Vellios' tutorial to create radial gravity with a Box2D object. I am aware of Make a Vortex here on SO, but I couldn't figure out how to implement it in my project. I have made a vortex object, which is a Box2D circleShape sensor that rotates with a consistent angular velocity. When other Box2D objects contact this vortex object I want them to rotate around at the same angular velocity as the vortex, gradually getting closer to the vortex's centre. At the moment the object is attracted to the vortex's centre but it will head straight for the centre of the vortex, rather than

LibGDX重建Flappy Bird——(6) 碰撞检测及细节处理

不打扰是莪最后的温柔 提交于 2019-11-29 09:27:31
本章源码链接: Libgdx重建FlappyBird 密码:twy2 上一章完整的介绍了BOX2D的物理仿真创建过程,在本章我们将继续完成BOX2D的剩余内容——碰撞检测。因为BOX2D帮我们完成了所有物理模拟过程,包括碰撞检测,这极大的降低我们的项目难度,我们不需要理解碰撞检测如何运行,甚至不需要知道任何碰撞检测算法,就能够完成碰撞检测并通知我们。下面就让我们为FlappyBird添加碰撞检测的回调函数和相应的逻辑代码。 碰撞检测 打开WorldController类,并为其添加下面代码: ... public class WorldController extends InputAdapter implements Disposable { ... private void initWorld() { if(world != null) world.dispose(); world = new World(new Vector2(0, -110.8f), false); // 为world添加碰撞检测监听器 world.setContactListener(new BirdContactListener()); } ... private void collisionDetection(AbstractGameObject a, AbstractGameObject b) {

Box2d: Maximum possible linear velocity?

佐手、 提交于 2019-11-29 06:50:14
I think I've configured Box2d to have some sort of maximum velocity for any body, but I'm not sure. I apply an impulse like (100000000, 100000000) , and the body moves just as fast as (100, 100) - which is not that fast at all. I'm using the Box2d XNA C# port. My game is a top-down 2d. Here is some code that may be relevant: private readonly Vector2 GRAVITY = new Vector2(0, 0); public void initializePhysics(ContactReporter contactReporter) { world = new World(GRAVITY, true); IContactListener contactListener = contactReporter; world.ContactListener = contactListener; } public void Update

Why use Float.floatToIntBits() in Java float comparisons?

a 夏天 提交于 2019-11-29 01:18:46
In JBox2d, there exists the following code for Vec2.equals() : @Override public boolean equals(Object obj) { //automatically generated by Eclipse if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Vec2 other = (Vec2) obj; if (Float.floatToIntBits(x) != Float.floatToIntBits(other.x)) return false; if (Float.floatToIntBits(y) != Float.floatToIntBits(other.y)) return false; return true; } I am wondering what purpose the float<->int bit conversions functions serve, here. Does this provide a way to get around Java's float comparison

What does cmake .. do?

一曲冷凌霜 提交于 2019-11-28 19:46:21
问题 I got the Box2D project source and want to compile the testbed portion of it. The project folder contains folders like: freeglu glui testbed(a demo) helloword(a demo) Box2D Build CMakeFiles There are many CMakeLists.txt in all the different folders. I was thinking that I should cmake all those files so that make files are created in all places required. I read this (as instructions to do do want I want) : wget http://box2d.googlecode.com/files/Box2D_v2.2.1.zip unzip Box2D_v2.2.1.zip cd Box2D

Move body to a specific position - Box2D

℡╲_俬逩灬. 提交于 2019-11-28 17:33:52
I have a b2Body which I would like to move at a certain target position. I don't want to use the SetPosition function. How can I achieve this using : Changing linear velocities. Using mouseJoint. (The target position is fixed. Mouse is NOT involved.) I'm using Box2DAS3 2.1a. Help in any other language would also be appreciated. Tom Guinther The simplest way is actually to use SetPosition / SetTransform(position,angle) . For example: body->SetTransform(b2Vec2(0,0),body->GetAngle()) Obviously, the instantaneous jump means you are subverting the physics simulation but it is the simplest most

Which Box2D JavaScript library should I use? [closed]

夙愿已清 提交于 2019-11-28 15:14:30
There are a few different ports of Box2D for JavaScript. Which one is the best? Box2DJS - "converted from Box2DFlashAS3_1.4.3.1 in an automatic manner" Box2Dflash 2.0 ported to JavaScript - "one big nasty hack that just happens to work" box2dweb - "a port of Box2DFlash 2.1a to JavaScript. I developed an ActionScript 3 -to- JavaScript converter to generate the code" HBehrens/box2d.js - "a JavaScript Version of Box2D 2.1a" (Added Nov 21, 2011) kripken/box2d.js - "a direct port of the Box2D 2D physics engine to JavaScript, using Emscripten" (Added Sep 24, 2013) Any ideas which version http:/

Is there an upper limit on velocity when using box2d?

断了今生、忘了曾经 提交于 2019-11-28 13:23:51
I'm using box2d for physics simulation. I'm moving a circle using arrow keys by applying impulse on the body when ever a key is pressed. Unfortunately, the circle moves excruciatingly slow and doesn't seem to accelerate like a true physical body is supposed to. My world's dimensions are 400x800 pixels. The radius of the circle body is 20f. According to this , the problem can be solved by scaling the circle radius down when creating it and scaling up after getting the body position during painting. It doesn't seem to make any difference at all. Is there some step or setting I'm missing here ?

Libgdx and Box2d Detect Collision of two specific bodies

…衆ロ難τιáo~ 提交于 2019-11-28 11:34:17
问题 I have two bodies, both dynamic, one of them I have turned off the gravity and only want to turn it on when it is hit by my other body. I know I can set my own contact listener but I want to specify an action only if two specific bodies touch. Any one have any guidance? 回答1: U can set the userdata of the body and use it like that public class GameColiision implements ContactListener { public GameColiision() { } @Override public void beginContact(Contact contact) { // TODO Auto-generated

Libgdx light without box2d

落花浮王杯 提交于 2019-11-28 09:26:22
I just started creating a game using libgdx. It is a top down 2d shooter using scene2d ui. Now i thought, that i could add darkness and light to some levels, but i don't want to rewrite everything using box2d. I don't need realistic shadows just some kind of ambient light and a lightcircle arround my character, which is not affected by walls and other obstacles arround him. So i wanted to know if there is any kind of lightsystem in libgdx? Or can i use box2dlights without using box2d bodies/world...? Thanks Unfortunately there is nothing like this already provided by LibGDX. But you can easily