Bowl of Eggs Physics Demo

Return to Scripting Issues

Bowl of Eggs Physics Demo

Postby Liquid7800 » Tue Mar 20, 2007 11:19 am

Hello, my buddy uses the UNITY game engine and I asked him to do a demo using a curved surface (bowl) holding some eggs to see the physics and collision detection ability.

Here is the UNITY sample's link:
http://vids.myspace.com/index.cfm?fusea ... 2016335848

Looks pretty cool in my opinion so he asked what Panda could do ...any ideas how to do this in Panda? Would I be able to use the basic collision detection equations with specific functions or would I need something more like PyODE integration.
The problems I see are like the Ralph demo on uneven terrain: I guess a bowl would be like an uneven terrain, no?

Anyway, if anyone could give an idea of how to set this up. I plan to use the samples of the maze, ynjh_jo 's great samples, and Roaming Ralph to start.

Thanks!
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Postby ThomasEgi » Tue Mar 20, 2007 2:08 pm

guess you need PyODE for this. panda's collision and physics are very basic.
there are a couple of posts here in the forum about how to use pyode. incudling a function to pass triangle-geometry. should work fine with it.

the samples use manually coded "physics". its more or less python code to define the behaviour of ralph and the ball combined with basic collision detection. wouldnt work too well in your case since you have 2 meshes colliding with each other. panda is only good if you have one mesh (like a terrain) and a collison solid like a ray or a sphere.
User avatar
ThomasEgi
 
Posts: 2147
Joined: Fri Jul 28, 2006 10:43 am
Location: Germany,Koblenz

Postby Liquid7800 » Tue Mar 20, 2007 2:12 pm

Thanks for the reply...

To understand better, based on your answer... If there were only one egg in that bowl then Panda's hard coded "physics" would work just fine to simulate that action?
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Postby ThomasEgi » Tue Mar 20, 2007 3:55 pm

hm.. not exactly.. if there would be oanly one egg which would be a perfect sphere it would be possible to code the behaviour quite easy.
but since egg's are no perfect spheres and since you have more than one egg it would be very difficult without a real physic engine.
User avatar
ThomasEgi
 
Posts: 2147
Joined: Fri Jul 28, 2006 10:43 am
Location: Germany,Koblenz

Postby enn0x » Wed Mar 21, 2007 5:39 am

Hello,

do you mind providing a (temporary) download for the the egg and bowl meshes, in a format that is easy to convert, e.g. Wavefront OBJ or DirectX?

I'd like to give it a try using Newton convex hulls.

enn0x
enn0x
 
Posts: 1267
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Liquid7800 » Wed Mar 21, 2007 10:08 am

Awesome! I hope you are able to do it. Here is a temporary download link for you....I made the meshes as OBJ file. Let me know if you need them as seprate files (they are seperate meshes though!) Thanks !
here is the link:

http://www.yousendit.com/download/M3Brc ... bmcwTVE9PQ

PS is the Newton convex hulls part of Panda?
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Postby ynjh_jo » Wed Mar 21, 2007 3:34 pm

I took the dare and --[THIS]-- is the result.
Use arrow keys to move the bowl, SPACE to lift it, and TAB to see the egg's collision spheres. I use 3 spheres for 1 egg, which are arranged to fit the egg's shape. I created those spheres since modeling phase, and then loaded and sent to ODE. Then they get connected by fixed joints to lock it's position relative to each other. And since they overlap each other, I modify my OO classes a little to allow multiple collision geoms build a larger custom collision structure. It's cheap, runs at 65+ fps for 15 eggs.
The result is interesting, when the egg is on the table and get hit by the bowl's side, it spins while circling over it's orbit. It could spin upright or at very shallow angle, just like motoGP racer circling the circuit :lol: . It can be fun afterall.
http://ynjh.panda3dprojects.com | http://ynjh.p3dp.com
Intel P4Prescott 2.8GHz HT | ATI Radeon HD4670 1GB GDDR3
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

AWESOME!

Postby Liquid7800 » Wed Mar 21, 2007 4:38 pm

This is super impressive. I just showed my buddy this and he couldnt beleive what you did with this scenario.
See UNITY has it all built in (the Agia Physx engine) and to get what you did requires no coding at all. So this is brilliant...he is really impressed with Panda and I told him that knowing how to code this type of stuff has its benefits in the long run.
I didnt get this far at all, I was still studying the OOriented PyODE sample that ynjh_jo made!

Speaking for the panda community....thanks for the contributions to Panda3D.
Last edited by Liquid7800 on Wed Mar 21, 2007 11:39 pm, edited 3 times in total.
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Postby ThomasEgi » Wed Mar 21, 2007 5:21 pm

really nice example.. had to change "from direct.ode import ode" to "import ode" but nice..
and now the 1mio dollar question.. why is the empty bowl harder to lift than the full one? :D
User avatar
ThomasEgi
 
Posts: 2147
Joined: Fri Jul 28, 2006 10:43 am
Location: Germany,Koblenz

Postby Liquid7800 » Wed Mar 21, 2007 10:16 pm

ynjh_jo,
Let me know if I am wrong in understanding this,...
but you modeled/created some spheres and then fit them into the egg model...then exported them to Panda? Are these spheres Panda primitives or new mesh models? How did you manage to fit the spheres so perfectly into the egg model? Thanks.
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Postby ynjh_jo » Thu Mar 22, 2007 12:10 am

ThomasEgi wrote:had to change "from direct.ode import ode" to "import ode"

Ok, I moved ode.pyd to Panda install dir.

ThomasEgi wrote:why is the empty bowl harder to lift than the full one?

I'm not sure, but now I use stay-pressed key to lift it, so you don't have to hit the SPACE like crazy. And that weird behaviour doesn't show up again.

@ Liquid7800:
those spheres are just ordinary polygonal spheres, arranged by hands in modeling phase, to make them fit the egg skin perfectly. Then in ODEsphere, the sphere is passed in as collObj, which next queried for it's radius by iterating through it's vertices. For that, basically you only need 1 triangle for each sphere, but I'd like to see them, so I left them uncorrupted.
I just added new param to ODEsphere : isPerfectSphere. If it's true, it would grab only the 1st vertex. If it's false, it would iterate through all vertices, looking for the outermost vertex, to make sure the object is covered entirely, but not overcovered as if using the bounding volume. As you can see, no more lag during reset scene, right ?

Liquid7800 wrote:UNITY has it all built in (the Agia Physx engine) and to get what you did requires no coding at all

that's cool, so your buddy must use the eggs' triangles to collide with the bowl. Unfortunately, my trimesh-trimesh collision using ODE is far from expectation. Maybe it's due to old version, or I just haven't figured out the best way to do collision response when both colliding objects are trimeshes.

update : ODE6-bowlEgg.py
Last edited by ynjh_jo on Sun Apr 01, 2007 5:07 am, edited 1 time in total.
http://ynjh.panda3dprojects.com | http://ynjh.p3dp.com
Intel P4Prescott 2.8GHz HT | ATI Radeon HD4670 1GB GDDR3
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby enn0x » Thu Mar 22, 2007 4:14 am

Back with may own version off the eggs in a bowl. I use self-written bindings for Newton Game Dynamics. The bindings are not yet complete (e.g. rad dolls are missing) and there are still some issues (e.g. with scaling). As soon as I have enough webspace again I will release a first alpha. I already busted my html quota.

The eggs in my version have convex hull collisions created from the mesh vertices. So it is kinda trimesh-trimesh collision. Something Newton is rather good with.

But it comes at a price: for the bowl I had to use a tree collision. Tree collision is a polygon mesh that been designed and optimized for collision with (large) static scenes, like terrain and static objects. And this means I have to cheat when it comes to shaking the bowl. I have to move the gravity vector and rotate the camera while the bowl stays where it is :-(

Anyway, performance is about the same a ynjh_jo's ODE demo, but with mesh-mesh collisions.

http://www.dachau.net/users/pfrogner/10-Egg-Bowl.zip (including win32 binary for PandaNewton)

enn0x
enn0x
 
Posts: 1267
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby ynjh_jo » Thu Mar 22, 2007 6:45 am

It's great, all sim (detection->response) is done entirely at low level.

1. I don't know anything about Newton. So Newton doesn't seem to know about joint/constraint (nail, hinge, spring, etc.) to connect bodies. Then how do you build a complex system ? Is it true, or it's just because you haven't binded that yet ?
2. I found something wrong in your code, as you said : scaling, both in makeCollisionHull and makeCollisionTree.
You want the relative pos of each vtx at the top root's coordinate space, right ? But why did you bring it to the object's CS ? It should be the top parent.
3. in makeEgg, only position and rotation from the matrix is used. How about the scale, ignored ? but the convex hull is already scaled. Or is this scaling what you meant ?
4. How does Newton deal with friction ? Which friction coef would be used when 2 meshes collide, the small one or the average, or what ?
My bottleneck is Python....
http://ynjh.panda3dprojects.com | http://ynjh.p3dp.com
Intel P4Prescott 2.8GHz HT | ATI Radeon HD4670 1GB GDDR3
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby enn0x » Thu Mar 22, 2007 8:42 am

Thank you, ynjh_jo. But it is not as shiny as it might look at first. ODE and Newton are very similar in what they can do or how fast they are. I think it is down to personal preferences.

for 1: Newton has joints too, and they are wrapped already, except for user defined joints (6DOF). Basic joints like ball, hinge, slider are almost the same in both engines. Newton has an UpVector joint for keeping actor upright even on slopes. And ODE hinge2joint is JointVehicle, only that you have to create one joint per vehicle and add tires to it.

for 2: The scaling is defaulted to (1,1,1) if I remember right. This is a code fragment remaining from some of my experiments with NodePath scaling. I have an unsolved issue when using setScale( ) on a node path, both from C++ and from Python. Panda3D crashes and complains about transform states having no previous state, weired). For now I use no scaling with Newton, until I found the reason for these crashes.

Hmm.. about the coordinate system transformation. I thought I had it transformed from the geom nodes CS to the top NodePaths CS, but I might be wrong. I believe you are right, and will look at the code this evening.

for 3: The C++ transform callback ignores scale and shear for now. This is what I meant about scale. Perhaps I will change the API sometime to set position, orientation and scale of a Body, once it has become stable.

for 4: Friction is supported (of course :-), by employing a material system. Each body can have a material, and properties like static/kinetic friction, elasticity, softness can be set for a material pair. e.g. for vehicle tire on wet stone.

Newton offers a lot of callbacks to the user, for example if the simulations is advanced by a timestep dt then newton does update the position and orientation of a body. But the graphical representation is still where it is. So Newton offers a "transform callback" that gets called every time a bodies transform is changed by Newton. One useful thing to do in such a callback is updating the graphical object (NodePath). When wrapping Newton I decided to offer two choices. Either implementing a python method to do the updating of a NodePath (and whatever a user would want to do), or using a "default" callback implemented in C++. For most cases the default callbacks will be sufficient, and a little bit faster than Python callbacks.

A real advantage of Newton is the collision tree which can handle static geometry of 50000 and more polygons at reasonable speed, but raytaller has some very interesting Panda3D work here too. The big disadvantage: Newton is free but closed source :-(

Please give me a few days. Even if there are still a lot of issues I will try to come up with a first release (including source and basic demos) next weekend.
enn0x
enn0x
 
Posts: 1267
Joined: Wed Nov 08, 2006 1:39 am
Location: Germany, Munich

Postby Liquid7800 » Thu Mar 22, 2007 9:08 am

@ enn0x Looks great! By employing a physics engine you really have shown some neat things Panda is capable of. Did you write your own Python "wrapper" for the newton system into Panda or is there one out there?

@ ynjh_jo I think your example is on par with the Unity demo. I am slowly getting familiar with the way ODE works, saying that, would it have been possible just to use the Egg model (not the spheres) as the colObj interacting with the bowl? Or does ODE not support asymetrical objects (like an egg vs a sphere?)

I guess to state this better is: why did you need to use spheres to get ODE to detect the collision. Thanks!
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Postby ynjh_jo » Fri Mar 23, 2007 1:12 am

@ enn0x
I checked your code again. Sorry, there is nothing wrong in makeCollisionHull and makeCollisionTree. The problem is you didn't pass the object's scale to them.

@ Liquid7800
if you'd like to see trimesh-trimesh collision, use ODEtrimesh instead of ODEsphere.

I just found something about ODE :
In order to efficiently resolve collisions, dCollideTTL needs the positions of the colliding trimeshes in the previous timestep. This is used to calculate an estimated velocity of each colliding triangle, which is used to find the direction of impact, contact normals, etc. This requires the user to update these variables at every timestep. This update is performed outside of ODE, so it is not included in ODE itself

in here :
http://www.ode.org/ode-latest-userguide.html

That explains why trimesh-trimesh collision is so horrible !
http://ynjh.panda3dprojects.com | http://ynjh.p3dp.com
Intel P4Prescott 2.8GHz HT | ATI Radeon HD4670 1GB GDDR3
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby Liquid7800 » Fri Mar 23, 2007 2:44 pm

That sure does explain it. Thanks for the link.
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Postby Liquid7800 » Tue Mar 27, 2007 3:14 pm

I was playing around with your example, ynjh_jo, and I was trying to incorporate tilting the bowl on its orgin (like the maze example) with the mouse to roll the egg with the bowl (in addition to your arrow controls).

I added this function in the code and called it in the gLoop function
Code: Select all
    def tiltTask(self):
    #Read the mouse position and tilt the maze accordingly
       if base.mouseWatcherNode.hasMouse():
          mpos = base.mouseWatcherNode.getMouse() #get the mouse position
          self.bowl.setP(mpos.getY() * -10)
          self.bowl.setR(mpos.getX() * 10)


The bowl tilts, but the tilting doesnt affect the egg at all. I assume it is because it is the (ODE) collObj that needs to tilt as well but I am unclear on how to do that.
Does anyone have any suggestions, thanks
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Postby ynjh_jo » Tue Mar 27, 2007 3:38 pm

If you want to affect the physics system, you should apply the changes to the body (for forces, position, rotation), or geom (for position & rotation).
Add this line to rotate the bowl's body :
Code: Select all
          self.SIM_bowl.body.setRotation(self.geomRotMat(self.bowl.getHpr()))
http://ynjh.panda3dprojects.com | http://ynjh.p3dp.com
Intel P4Prescott 2.8GHz HT | ATI Radeon HD4670 1GB GDDR3
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby Liquid7800 » Tue Mar 27, 2007 4:39 pm

Thanks for the idea!

You worded it correctly. I wanted to affect the physics system...

It is very frustrating to be so new to this, but I am trying to begin the simulation with the bowl levitating at a height of say 2. The tilting is proving to be a little unstable.
I looked at your "lifting" code and the ODE API about position and orientation but I cannot figure out how to begin and have the bowl lifted consistently at a determined height.
Any guidance is appreciated
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

setPosition in ODE

Postby Liquid7800 » Wed Mar 28, 2007 12:36 pm

Hmmmm I tried the setPosition function
Code: Select all
def rollTask(self):
    #Read the mouse position and tilt the maze accordingly
       if base.mouseWatcherNode.hasMouse():
          mpos = base.mouseWatcherNode.getMouse() #get the mouse position
          #upos = base.mouseWatcherNode.getZ
          self.bowl.setP(mpos.getY() * -30)
          self.bowl.setR(mpos.getX() * 30)
          self.bowl.setZ(2)
          self.SIM_bowl.body.setRotation(self.geomRotMat(self.bowl.getHpr()))
          self.SIM_bowl.body.setPosition(self.geomPosMat(self.bowl.getZ()))


Used as a basis from
Code: Select all
def geomPostMat(self,pos):
        dum=NodePath('')
        dum.setPos(pos)
        mat=dum.getMat()
        mat4=[]
        for col in range(3):
            mat3.append(mat.getCol3(col)[0])
            mat3.append(mat.getCol3(col)[1])
            mat3.append(mat.getCol3(col)[2])
            mat3.append(mat.getCol3(col)[3])
        dum.removeNode()
        return mat4


However the bowl does not levitate or use Z as the starting point?
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Postby ynjh_jo » Wed Mar 28, 2007 2:36 pm

Note that there is another way to define the rotation directly, using setQuaternion :
Code: Select all
self.SIM_bowl.body.setQuaternion(self.bowl.getQuat())

But, setting the rotation directly is not the ideal way, especially when there is collision with the object. The ideal way is to apply force to it, so that it will rotate naturally.
If you'd like the bowl stays in the mid air, you should connect it to another body with joint type you need. Then you should nail that body to ode.environment using fixedJoint.
Insert this before creating the bowl :
Code: Select all
        # create a static position body
        levitation=1
        self.hangingBody = ode.Body(self.ode_WORLD)
        self.hangingBody.setPosition((0,0,levitation))
        fJ=ode.FixedJoint(self.ode_WORLD)
        fJ.attach(self.hangingBody, ode.environment)
        fJ.setFixed()
        # make sure to "save" the joint
        self.simJoints.append(fJ)

insert this after creating the bowl :
Code: Select all
        self.SIM_bowl.body.setPosition(self.hangingBody.getPosition())
        bJ=ode.BallJoint(self.ode_WORLD)
        bJ.attach(self.SIM_bowl.body, self.hangingBody)
        bJ.setAnchor(self.hangingBody.getPosition())
        # make sure to "save" the joint
        self.simJoints.append(bJ)

the new tiltTask :
Code: Select all
    def tiltTask(self):
    #Read the mouse position and tilt the maze accordingly
       if base.mouseWatcherNode.hasMouse():
          mpos = base.mouseWatcherNode.getMouse() #get the mouse position
          self.bowl.setP(mpos.getY() * -10)
          self.bowl.setR(mpos.getX() * 10)
          self.SIM_bowl.body.setAngularVel((0,0,0))
          self.SIM_bowl.body.addRelForceAtRelPos((0,0,-5),(mpos.getX() * 10,mpos.getY() * 10,0))

and make sure to add levitation to the eggs' randomized Z.
http://ynjh.panda3dprojects.com | http://ynjh.p3dp.com
Intel P4Prescott 2.8GHz HT | ATI Radeon HD4670 1GB GDDR3
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby Liquid7800 » Wed Mar 28, 2007 2:45 pm

Gotcha,
Thats a great idea to hold the bowl in midair...I suppose the joints act like a pedastal to hold it up. Ive been reading more on the ODE API so I am beginning to understand more of the concepts you give.

Adding a velocity to the tilt makes it look much more realistic

Thanks, much appreciated.
Last edited by Liquid7800 on Wed Mar 28, 2007 3:22 pm, edited 1 time in total.
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Postby ynjh_jo » Wed Mar 28, 2007 2:46 pm

Sorry, you don't need to set it's pitch & roll.
http://ynjh.panda3dprojects.com | http://ynjh.p3dp.com
Intel P4Prescott 2.8GHz HT | ATI Radeon HD4670 1GB GDDR3
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby Liquid7800 » Wed Mar 28, 2007 3:20 pm

I tried the simJoints function but it returned a message that it couldnt find the Joints. Did I place them in the right section?:

Code: Select all
    def startScene(self):
        if self.ode_SPACE.getNumGeoms()>1:
           for o in self.simObjects:
               o.destroy()
           self.simObjects = []
           for j in self.simJoints:
               j = None

        self.table=loader.loadModelCopy('misc/rgbCube')
        self.table.reparentTo(render)
        self.table.setScale(200,200,.5)
        self.table.setZ(.5*self.table.getSz())
        self.table.setColor(.2,.5,.7,1)
        self.table.setLightOff()
        self.simObjects.append( ODEbox( world=self.ode_WORLD, space=self.ode_SPACE,
                                        realObj=self.table,
                                        density=0, friction=0 ) )


 #############new## create a static position body
        levitation=1
        self.hangingBody = ode.Body(self.ode_WORLD)
        self.hangingBody.setPosition((0,0,levitation))
        fJ=ode.FixedJoint(self.ode_WORLD)
        fJ.attach(self.hangingBody, ode.environment)
        fJ.setFixed()
        # make sure to "save" the joint
        self.simJoints.append(fJ)

        # load the bowl
        self.bowl=loader.loadModelCopy('bowl')
        self.bowl.reparentTo(render)
        self.bowl.setZ(.5)
        self.SIM_bowl = ODEtrimesh( world=self.ode_WORLD, space=self.ode_SPACE,
                                     realObj=self.bowl, collObj=self.bowl,
                                     density=10, friction=1 )
        self.simObjects.append(self.SIM_bowl)

 #############new##################       
        self.SIM_bowl.body.setPosition(self.hangingBody.getPosition())
        bJ=ode.BallJoint(self.ode_WORLD)
        bJ.attach(self.SIM_bowl.body, self.hangingBody)
        bJ.setAnchor(self.hangingBody.getPosition())
        # make sure to "save" the joint
        self.simJoints.append(bJ)



        # list to keep ODE joints (to connect the collision spheres of the egg),
        # to keep their effect, or else Python considers the joints as garbage !!
        self.simJoints = []


I assume this is where the bowl is created and the levitation code sandwiches it there
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Postby ynjh_jo » Wed Mar 28, 2007 5:01 pm

first, simJoints is not a function, but a list to hold the active joints, so that they won't be removed by Python. Of course, you have to create it before using it. Move "self.simJoints = []" to the place before the 1st joint created.
http://ynjh.panda3dprojects.com | http://ynjh.p3dp.com
Intel P4Prescott 2.8GHz HT | ATI Radeon HD4670 1GB GDDR3
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby Liquid7800 » Wed Mar 28, 2007 10:09 pm

Thanks ynjh_jo, I apologize if I seem to be a pest, but I really do appreciate your help very much as I am eager to learn.
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Hmm

Postby Liquid7800 » Fri Mar 30, 2007 4:44 pm

I thought I would give myself a few days to try my best to figure out some of this ODE physics work. I can say after 3 days of solid work I have found out alot of what I can't do!

In regards to the code snippets and file above above some strange things are happening.

In the function,

Code: Select all
def startScene(self):

where I add the code to set my Fixed Joint to the scene

Code: Select all
levitation=2
        self.hangingBody = ode.Body(self.ode_WORLD)
        self.hangingBody.setPosition((1,0,levitation))
        self.simJoints = []
        fJ=ode.FixedJoint(self.ode_WORLD)
        fJ.attach(self.hangingBody, ode.environment)
        fJ.setFixed()
        self.simJoints.append(fJ)

The joint is set appropriately,
next the bowl is loaded...
then I added code to attach the bowl to the fixed object with a Balljoint:
Code: Select all
        self.SIM_bowl.body.setPosition(self.hangingBody.getPosition())
        self.simJoints = []
        bJ=ode.BallJoint(self.ode_WORLD)
        bJ.attach(self.SIM_bowl.body, self.hangingBody)
        bJ.setAnchor(self.hangingBody.getPosition())
        self.simJoints.append(bJ)

I run the program but the bowl does not remain fixed to the hangingBody...it seems to recognize the hangingBody's location (as it falls from the "levitation's" height and 1 unit to the X value given) but falls instead of levitates.

The only way I was able to get it to levitate was placing this code in the tiltTask function:
Code: Select all
  def tiltTask(self):
       if base.mouseWatcherNode.hasMouse():
          mpos = base.mouseWatcherNode.getMouse() #get the mouse position
          self.SIM_bowl.body.setAngularVel((0,0,0))
          self.SIM_bowl.body.addRelForceAtRelPos((0,0,-5),(mpos.getX() * 10,mpos.getY() * 10,0))
          levitation=1
          self.hangingBody = ode.Body(self.ode_WORLD)
          self.hangingBody.setPosition((0,0,levitation))
          self.simJoints = []
          fJ=ode.FixedJoint(self.ode_WORLD)
          fJ.attach(self.hangingBody, ode.environment)
          fJ.setFixed()
        # make sure to "save" the joint
          self.simJoints.append(fJ)
          self.SIM_bowl.body.setPosition(self.hangingBody.getPosition())
          self.simJoints = []
          bJ=ode.BallJoint(self.ode_WORLD)
          bJ.attach(self.SIM_bowl.body, self.hangingBody)
          bJ.setAnchor(self.hangingBody.getPosition())
        # make sure to "save" the joint
          self.simJoints.append(bJ)
        # make sure to "save" the joint

The bowl now levitates but does not collide with the egg (the egg falls through) nor responds to the arrow keys (the arrow keys are another issue I guess)
I really struggled to find a solution to post to the community on this but I never found a way to get this to work. Sorry to bother again...
User avatar
Liquid7800
 
Posts: 140
Joined: Mon Feb 19, 2007 1:22 am

Postby ynjh_jo » Sat Mar 31, 2007 5:34 am

Your grand problem is you initialized simJoints twice. Basically, simJoints only serves as a container for any created joint in your scene, so you only have to create it once in a (simulation) lifetime. It will be destroyed too when restarting the scene, and then created again.
You can directly nail your bowl to ode.environment:
Code: Select all
        self.simJoints = []
        levitation=2

        # load the bowl
        self.bowl=loader.loadModelCopy('bowl')
        self.bowl.reparentTo(render)
        self.bowl.setPos(1,0,levitation)
        self.SIM_bowl = ODEtrimesh( world=self.ode_WORLD, space=self.ode_SPACE,
                                     realObj=self.bowl, collObj=self.bowl,
                                     density=10, friction=1 )
        self.simObjects.append(self.SIM_bowl)

        bJ=ode.BallJoint(self.ode_WORLD)
        bJ.attach(self.SIM_bowl.body, ode.environment)
        bJ.setAnchor(self.SIM_bowl.body.getPosition())
        # make sure to "save" the joint
        self.simJoints.append(bJ)

And of course you can't move the bowl anywhere again, since it's nailed to the environment. No matter how you apply force to it, it will remain there.
You may want to see --[THIS]-- too, to see the other joints in action.
http://ynjh.panda3dprojects.com | http://ynjh.p3dp.com
Intel P4Prescott 2.8GHz HT | ATI Radeon HD4670 1GB GDDR3
User avatar
ynjh_jo
 
Posts: 1795
Joined: Tue Apr 18, 2006 12:41 am
Location: Malang, Indonesia

Postby Aq_La » Sun Apr 01, 2007 8:57 pm

ynjh_jo, the link you gave for your PyODE eggs example seems not work now. Would you please update it again? Thank you very much!
Aq_La
 
Posts: 48
Joined: Sat Mar 10, 2007 7:56 am

Next

Return to Scripting Issues

Who is online

Users browsing this forum: No registered users and 0 guests