Restriction to 2D

GeoffNin
Posts: 2
Joined: Thu Jun 19, 2008 7:01 pm

Restriction to 2D

Post by GeoffNin »

My company is working on a game and we would like to use the bullet engine as our physics engine, but because the game has many physics based 2d elements we'll need to restrict the calculation of many of our physics 'worlds' to 2d.

how is this done?
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Restriction to 2D

Post by Wavesonics »

this is done by creating a "zero plane" body which just sits at (0, 0, 0) then attaching every dynamic body to this zero plane body via a constraint that only locks z translation.

We just did this and I found a great tutoiral, let me find it.
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Restriction to 2D

Post by Wavesonics »

Here ya go:
http://darkrockstudios.com/files/bulletthings.pdf

I couldn't find where it was originally hosted, so i threw it up on my site.

It's section 3.2 in that pdf

There are also a load of other great rather undocumented things explained in here.

Hope that helps.
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Restriction to 2D

Post by sparkprime »

that's chunky's pdf, and yeah, it's good
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Restriction to 2D

Post by Wavesonics »

Oh good to know. It's been the best reference I have found for Bullet so far.

Though it could use some updating, and expanding.
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Restriction to 2D

Post by chunky »

Wow, I'm flattered that I've been useful to people!

http://chunkyks.com/bulletthings.pdf was the original URL of it. I've modified the layout [line breaks by space rather than indentation are so much more readable IMHO], but it's otherwise the same as the one linked above I think.
Though it could use some updating, and expanding.
What topics would you like added? I'm happy to document anything and everything I can [and can find time for]. What's there so far are just what I felt where the nonobvious or undocumented things while I was learning bullet.

I'm sure there are things that I understand now that other people would appreciate more knowledge spreading for, but I simply don't know what topics I should write on to actually be of help to people :-)

Gary (-;
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: Restriction to 2D

Post by sparkprime »

At the moment you've collected together a bunch of info on various bullet-related things, which is good, but if you wanted to write a larger document I think you'd need more structure, tell a story, etc. If you want to continue writing stuff on particular topics, why not use the wiki? You can put tutorials on there kinda like your rocket thing.

Just some suggestions :)
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Restriction to 2D

Post by chunky »

If you want to continue writing stuff on particular topics, why not use the wiki?
Heh. Actually I started it a while ago mostly to have something to put up on the wiki when I gained access to it again. But it's still not really visible or present [and I still couldn't create pages last I tried]

Gary (-;
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Restriction to 2D

Post by Wavesonics »

I'm heading out for vacation in about 5 minutes so i cant really get into it. but Thank you so much chunky for that document, it's been a huge help.

I do have some ideas for things that would be good to expand on and I'll post about them when I get back from vacation in a week.

The callback section is what could use some more love IMO. The processed called back function signature you provide is incorrect as of 2.69 i think.

And the destroyed call back doesn't work, but I believe that is due to, at the very least, one confirmed bug in 2.69.

Also, a nice new section could be, if this is even possible, changing collision groups / collides with masks on the fly, is that possible? Or would the body have to be destroyed and recreated with the new masks?

See you all in a week!
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Restriction to 2D

Post by chunky »

Also, a nice new section could be, if this is even possible, changing collision groups / collides with masks on the fly, is that possible? Or would the body have to be destroyed and recreated with the new masks?
Don't think so. Might be possible-but-unsupported or something. Really, if you want more complex behaviour than simple bitmasks then you should probably just use a nearcallback as described in the next section, instead

Gary (-;
GeoffNin
Posts: 2
Joined: Thu Jun 19, 2008 7:01 pm

Re: Restriction to 2D

Post by GeoffNin »

Thank you for your reply, I would like to mark this topic as answered but It's not immediately obvious on how to do so.


thanks again
chunky
Posts: 145
Joined: Tue Oct 30, 2007 9:23 pm

Re: Restriction to 2D

Post by chunky »

Well, assuming you want to do roughly what I've done:
"I want to constrain an object to two dimensional movement, skipping one of the cardinal axes "

There are a lot of ways of doing this. Here’s the one that’s working for me.
1. Create a body in space. It doesn’t need a position, size, collision object. Just a body e nihil that you can attach other bodies to
(a) It does need its mass to be zero, though, in order to effectively disable it from moving
2. Create a generic6dof joint that restrains movement along the axis you want to restrain movement along
3. Attach your body you want to restrict movement on, to the body you created in the ?rst step In the case you see here, I have constrained movement along the Z axis. My spaceship travels only along the X and Y axes.

Code: Select all

btRigidBody zerobody(0,NULL,NULL); // Create the body that we attach things to 
btRigidBody spaceship; // Construct your body that will only move in two dimensions 
btGeneric6DofConstraint constrict(spaceship, zeroBody, btTransform::getIdentity(), btTransform::getIdentity(), false); 
// Use limit(axis, a, b) where a>b to disable limits on that axis 
constrict->setLimit(0,1,0); // Disable X axis limits 
constrict->setLimit(1,1,0); // Disable Y axis limits 
constrict->setLimit(2,0,0); // Set the Z axis to always be equal to zero 
constrict->setLimit(3,1,0); // Uncap the rotational axes 
constrict->setLimit(4,1,0); // Uncap the rotational axes 
constrict->setLimit(5,1,0); // Uncap the rotational axes 
mWorld->addConstraint(constrict);
Gary (-;
Wavesonics
Posts: 71
Joined: Thu May 22, 2008 8:03 pm

Re: Restriction to 2D

Post by Wavesonics »

Maybe your right chunky, but it seems like it would be such a simple thing to be able to change the bit masks as long as you did it outside of the process() cycle.

Wounder if the devs would be interested in an SVN patch which added the functionality to change the bit mask on the fly...
kclancy
Posts: 1
Joined: Mon Jul 07, 2008 8:16 pm

Re: Restriction to 2D

Post by kclancy »

The bullet manual seems to claim that you can. It says the following:

You can override this default filtering behaviour after the rigidbody has been added to the dynamics world by assigning new values to collisionFilterGroup and collisionFilterMask.

I have tried doing this (using rb->getBroadphaseProxy()->m_collisionFilterMask = x), but it didn't seem to work. Am I misinterpreting the statement from the manual?