Panda Bullet

The problem is, if I reparent the model, I can’t get its position and rotation for Panda uses.

How can I set the rotation of a physics body? I would like to make ramps and such.

I could help with some documentation, I have been looking over the C++ source, so I understand a bit of whats going on.

The same way you would do it with any PandaNode: using setHpr, setMat or setQuat on the NodePath, or setting the thransform state on the node itself. Please note that only translation and orientation are supported, not shear or scale. This is a common limitation of all physics engine.

I don’t understand you here. Can you please elaborate a bit more?

Any help is certainly appreciated.

But I don’t want you to get frustrated after some time. This is still work in progress, and the API will change; for example the next release won’t have BulletMotionNode any longer (I want to make RigidBody a PandaNode), or the collision filtering will change (I want to make use of Panda3D’s from/into masks, if possible).

Currently I think the best way people could help is by playing around, asking questions, and making suggestions about what could be done differently.

In the following code, if I try to rotate the np node, the visual model rotates, but the physics block does not.

#Load a model:
        self.model = main.loader.loadModel("models/block.egg")

        self.tex = loader.loadTexture('gfx/'+str(Type)+'.jpg')
        self.model.setTexture(self.tex)


        #Reparent the model to render:
        self.model.reparentTo(render)

        #Physics:
        self.node = BulletMotionNode('box')
        self.node.setTransform(TransformState.makePos((x,y,z)))

        self.shape = BulletBoxShape(.4)

        self.body = BulletRigidBody(0,self.node,self.shape)
        physics.world.addRigidBody(self.body)

        self.np = render.attachNewNode(self.node)
        self.np.setHpr(h,p,r)
        self.model.reparentTo(self.np)

Another problem, I am trying to set the cameras X and Z to match that of a player model. (This is for a platformer.) I am using this code

main.camera.setX(player.np.getX()

)

It works, but is very jittery. If I reparent the camera to the players np node, its smooth, but the camera rotates with the player (a rolling ball), so that is no good.

When do you think the next release will come out?

Thanks,

Sothh
[/code]

In the following code, if I try to rotate the np node, the visual model rotates, but the physics block does not.

#Load a model:
        self.model = main.loader.loadModel("models/block.egg")

        self.tex = loader.loadTexture('gfx/'+str(Type)+'.jpg')
        self.model.setTexture(self.tex)


        #Reparent the model to render:
        self.model.reparentTo(render)

        #Physics:
        self.node = BulletMotionNode('box')
        self.node.setTransform(TransformState.makePos((x,y,z)))

        self.shape = BulletBoxShape(.4)

        self.body = BulletRigidBody(0,self.node,self.shape)
        physics.world.addRigidBody(self.body)

        self.np = render.attachNewNode(self.node)
        self.np.setHpr(h,p,r)
        self.model.reparentTo(self.np)

Another problem, I am trying to set the cameras X and Z to match that of a player model. (This is for a platformer.) I am using this code

main.camera.setX(player.np.getX()

)

It works, but is very jittery. If I reparent the camera to the players np node, its smooth, but the camera rotates with the player (a rolling ball), so that is no good.

When do you think the next release will come out?

Thanks,

Sothh
[/code]

I have been wrong. Setting pos and hpr on the motion node doesn’t work, because I left away the PandaNode hooks. This is one reason why I want to make BulletRigidBody a PandaNode and remove BulletMotionNode.

So far you can change the body’s position by using BulletRigidBody.translate(…). A method for changing the orientation is missing so far. I have added BulletRigidBody.setHrp(h, p, r) in the following release (no other changes, but using current Bullet version r2233):

http://enn0x.p3dp.com/libpandabullet-r9.zip

I thought that must be the case, since it was missing from the source code.

So it should work now? Thanks!

Okay, when I used body.setHpr, the visual model does not change its rotation, but the physics object rotates and seems to move to the position (0,0,0) which is a big problem.

Here is the code I tried:

class Block():

    def __init__(self,Type,x,y,z,h,p,r):

        #Load a model:
        self.model = main.loader.loadModel("models/block.egg")

        self.tex = loader.loadTexture('gfx/'+str(Type)+'.jpg')
        self.model.setTexture(self.tex)

        #Reparent the model to render:
        self.model.reparentTo(render)

        #Physics:
        self.node = BulletMotionNode('box')
        self.node.setTransform(TransformState.makePos((x,y,z)))

        self.shape = BulletBoxShape(.4)

        self.body = BulletRigidBody(0,self.node,self.shape)
        physics.world.addRigidBody(self.body)


        self.np = render.attachNewNode(self.node)
        self.body.setHpr(0,0,0)
        self.model.reparentTo(self.np)

Yep, this is the problem with quickshots. Ok, I fixed it; The method setHpr is removed again, and replaces by setTransform(TransformState xform). For example:

xform = TransformState.makePosHpr(Point3(0, 0, -5), Vec3(0, 0, 30))
body.setTransform(xform)

I updated libpandabullet-r9.zip, so the above download link can be used again.

Just for the record: your original problem can be solved by setting hpr BEFORE creating the body. Changing the position of a body AFTER creation is possible now, but it should be used with care. Sudden “explosions” might occur if objects penetrate each other after the change of transform.

I sent a game I made using this module to a friend, whom is running Panda 1.7.0, and he gets this error when he tries running the program:

Traceback (most recent call last):
  File "C:\Users\Exotath\Desktop\Blox\Blox.py", line 26, in <module>
    from libpandabullet import *
ImportError: DLL load failed: The specified procedure could not be found.

Your friend is missing this module, since it can’t be found. Forgot to pack libpandabullet.pyd, or maybe placed it in the wrong folder, or something like this…

Pack it? I sent him the same folder I have been using, which I know has all the modules it needs. I even asked him to check, and sure enough the libpandabullet module was present. I also experienced a similar problem when I used PackPanda to create an installer and installed it on my XP computer. Although it could import all the other custom modules I had in the same folder with it, it would not import it.

I can forward you the file if you will PM me your email address.

Well, the error message is pretty clear. Loading a DLL failed. This can be because libpandabullet is not found, or one of the libs required by libpandabullet is not found. This could be a VC runtime lib. I am using VC9. Anyway, I will pm you my mail address.

I found the problem. I installed Panda 1.7.0 instead of what I usually use, 1.7.1 and I get the same error.

I seems this wont work on 1.7.0, though I don’t know why.

Well, libpandabullet.dll is compiled against P3D 1.7.1, that is the current snapshot build. I don’t expect it to work with 1.7.0, though it should be possible to compile and link against 1.7.0.

Just to be sure, you can load libpandabullet using P3D 1.7.1 on your friends computer?

Yes, it works fine with 1.7.1

Maybe you should give two versions?

Oh, and another thing. I seem to be having a problem with objects going into each other. They go into each other a little before detecting the collision and then going back out. Is there any way I can fix this?

This is called “skin” or “margin” in most physics engine. You can use setMargin on any shape, but don’t choose the value too small or you will miss collision.

Two versions are too much effort at this stage.

I’d like to try this out and possibly help with development… I’d much rather be using Bullet than PhysX for my projects, especially since they’ve started integrating OpenCL hardware acceleration support.

I’ve downloaded libpandabullet-r9.zip and tried building it; the .pyd included doesn’t work on Linux apparently:

$ ppython 01_Basics.py 
DirectStart: Starting the game.
Known pipe types:
  glxGraphicsPipe
(all display modules loaded.)
Traceback (most recent call last):
  File "01_Basics.py", line 22, in <module>
    from libpandabullet import BulletWorld
ImportError: No module named libpandabullet

$ file libp ppython 01_Basics.py 
DirectStart: Starting the game.
Known pipe types:
  glxGraphicsPipe
(all display modules loaded.)
Traceback (most recent call last):
  File "01_Basics.py", line 22, in <module>
    from libpandabullet import BulletWorld
ImportError: No module named libpandabullet
andabullet.pyd 
libpandabullet.pyd: PE32 executable for MS Windows (DLL) (GUI) Intel 80386 32-bit

So, I tried installing the latest Bullet from SVN (r2243) and building libpandabullet, and the first time running scons seemed to indicate that it was also rather Windows-specific:

$ scons
scons: Reading SConscript files ...
KeyError: 'PROGRAMFILES':
  File "/home/whitelynx/devel/libpandabullet-r9/SConstruct", line 13:
    SConscript([ 'SConscript.%s' % PLATFORM, ])
  File "/usr/lib/python2.7/site-packages/SCons/Script/SConscript.py", line 614:
    return method(*args, **kw)
  File "/usr/lib/python2.7/site-packages/SCons/Script/SConscript.py", line 551:
    return _SConscript(self.fs, *files, **subst_kw)
  File "/usr/lib/python2.7/site-packages/SCons/Script/SConscript.py", line 260:
    exec _file_ in call_stack[-1].globals
  File "/home/whitelynx/devel/libpandabullet-r9/SConscript.VC9", line 4:
    PANDADIR  = os.environ['PROGRAMFILES'] + '/Panda3D-1.7.1'
  File "/usr/lib/python2.7/UserDict.py", line 23:
    raise KeyError(key)

I checked out the SConstruct file, and noticed the PLATFORM line, which seemed to indicate that setting it to ‘Linux’ was valid, but that doesn’t seem to work either:

$ scons
scons: Reading SConscript files ...

scons: warning: Ignoring missing SConscript 'SConscript.Linux'
File "/home/whitelynx/devel/libpandabullet-r9/SConstruct", line 13, in <module>

scons: *** Import of non-existent variable ''env''
File "/home/whitelynx/devel/libpandabullet-r9/SConstruct", line 14, in <module>

Is there currently a way to build this on Linux, or should I hack together a method for doing this? I’m not very familiar with scons aside from reading several articles about it, but I’m very fluent in both Python and waf. (which I prefer over scons from a purely feature-oriented and performance-oriented point of view… we use waf for all of our C/C+±based projects)

If it’d be desirable, I’d also love to write a waf build system for this… but it’s up to you if you’d want that.

The .pyd is a Windows 32bit DLL. It’s not usable on Linux. So far I provide - together with the source code - only Windows binaries.
Also the build script is Windows-only so far. There is a main script (SConstruc) which is platform-independent, and which loads a platform-dependent file for setting up the environment (e. g. SConscript.VC9). All you would have to do is add a script for your platform, and make sure it gets imported by the main script.

I didn’t try to compile on Linux so far. Might be there have to be some smaller changes to the code, but nothing serious.

Once the module is added to the P3D source code it will be compiled for all platforms automatically, so currently I don’t attempt to provide build scripts for Linux, Mac, etc.

I have no problem if you want to provide build script for waf. I haven’t used waf so far, and I’m not fixed on SCons. You will have to spend some time on the interrogate & interrogate_module calls, but I can provide help here.

Ok, I started trying to write a SConscript.Linux file for this, and it mostly seems to be working, but it’s trying to include a file that doesn’t get installed by Bullet:

$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o built/bullet_composite.os -c -fPIC -DFORCE_INLINING -DBUILDING_PANDABULLET -DHAVE_PYTHON -Ibuilt -Isource -I/usr/include/python2.7 -I/home/whitelynx/packages/panda3d-cvs/src/panda3d/built/include -I/usr/include/bullet/bullet source/bullet_composite.cxx
In file included from source/config_bullet.h:26:0,
                 from source/config_bullet.cxx:15,
                 from source/bullet_composite.cxx:1:
source/bullet_includes.h:36:72: fatal error: Extras/Serialize/BulletWorldImporter/btBulletWorldImporter.h: No such file or directory
compilation terminated.
scons: *** [built/bullet_composite.os] Error 1
scons: building terminated because of errors.

I’m assuming this file is in the Bullet source… is this actually needed? Shouldn’t we be sticking to things that Bullet provides in the install?

Hmmm… I checked out r2243 this weekend, and I still can see this file. Directory trees checked out from SVN should be the same both on Windows and Linux.