From: Jonathan V T. <to...@ph...> - 2005-03-03 04:38:22
|
Friends, I am writing a simples 2D physics simulator for an amateur game I am working on, and the following problem has come up: I am trying to follow, more or less, Tutorial 3 from the webpage, in that I create my "physical objects" by associating them with bodies and I create my environment, which is fixed and immovable, by simply creating Geom objects without bodies. In linux, this works fine, but in Windows the line of the code in the collision callback which looks like: j.attach(geom1.getBody(),geom2.getBody()); Causes a nasty error. This is because if one of the Geom objects is an immovable object, getBody returns None. This behaviour is puzzling, since in Linux, I am clearly getting a body, perhaps where I shouldn't be. So the question is, how do you handle adding contact joints to objects which do not have bodies? Or, how do you make an object with a body permanantly fixed in space? Or, am I doing something totally ridiculous? Thanks in advance for any help that is offered. -Vincent PS - In this case, the geoms which are giving me trouble are simply GeomBox objects. |
From: Chris B. <chr...@gm...> - 2005-03-03 09:41:15
|
On Wed, 2 Mar 2005 23:35:28 -0500 (EST), Jonathan V Toups <to...@ph...> wrote: > > j.attach(geom1.getBody(),geom2.getBody()); > > Causes a nasty error. This is because if one of the Geom objects is an > immovable object, getBody returns None. This behaviour is puzzling, since > in Linux, I am clearly getting a body, perhaps where I shouldn't be. Are you sure? The behaviour under linux and windows should be identical... it's the same code. getBody should return None. > So the question is, how do you handle adding contact joints to > objects which do not have bodies? Or, how do you make an object with a > body permanantly fixed in space? Or, am I doing something totally > ridiculous? You can't add joints to geoms. You can only use joint constraints on ODE bodies. You can fix a body in space by creating a fixedjoint with the environment (pass 0 as the body arg). However, this is generally advised against since it adds unnecessary constraints. The usual way to get what your trying to do is to place the geom somewhere, and then calculate contact joints. The contact joint should be attached to the static environment. afaik, calling getBody should return None, and your contact joint is created with that and a real body, so your code should already work! |
From: Jonathan V T. <to...@ph...> - 2005-03-03 13:43:21
|
Chris, Thanks for the speedy response. In Linux the behavior is exactly as you describe. I just checked the code, and the getBody() calls return None, just like they do in Windows. But in Windows the j.attach call with one of the arguments as None causes a crash with an error message about an unexpected segmentation violation. Could it be a bug? I was working on recompiling the ODE library and PyODE in windows (thinking maybe the latest source had fixed it, or that I might be able to poke around the code and find the problem myself) but I was trying to do it with cygwin and wasn't getting too far. The code definitely functions the way I am expecting it to under Linux, so something is definitely going on. I wonder what to do next? -Vincent |
From: Jonathan V T. <to...@ph...> - 2005-03-05 14:05:09
|
Chris, I had been having problems with passing None to the j.attach call in Windows. I am still having these problems, but found that if I test for None and instead pass ode.environment, the program functions as expected. I guess I should submit a bug report, but hopefully if anyone else is having this problem, they can find this post in the archives. -Vincent On Thu, 3 Mar 2005, Chris Bainbridge wrote: > On Wed, 2 Mar 2005 23:35:28 -0500 (EST), Jonathan V Toups > <to...@ph...> wrote: > > > > j.attach(geom1.getBody(),geom2.getBody()); > > > > Causes a nasty error. This is because if one of the Geom objects is an > > immovable object, getBody returns None. This behaviour is puzzling, since > > in Linux, I am clearly getting a body, perhaps where I shouldn't be. > > Are you sure? The behaviour under linux and windows should be > identical... it's the same code. getBody should return None. > > > So the question is, how do you handle adding contact joints to > > objects which do not have bodies? Or, how do you make an object with a > > body permanantly fixed in space? Or, am I doing something totally > > ridiculous? > > You can't add joints to geoms. You can only use joint constraints on > ODE bodies. You can fix a body in space by creating a fixedjoint with > the environment (pass 0 as the body arg). However, this is generally > advised against since it adds unnecessary constraints. The usual way > to get what your trying to do is to place the geom somewhere, and then > calculate contact joints. The contact joint should be attached to the > static environment. afaik, calling getBody should return None, and > your contact joint is created with that and a real body, so your code > should already work! > |
From: Matthias B. <ba...@ir...> - 2005-03-03 09:59:14
|
Jonathan V Toups wrote: > j.attach(geom1.getBody(),geom2.getBody()); > > Causes a nasty error. This is because if one of the Geom objects is an > immovable object, getBody returns None. This behaviour is puzzling, since > in Linux, I am clearly getting a body, perhaps where I shouldn't be. > So the question is, how do you handle adding contact joints to > objects which do not have bodies? Or, how do you make an object with a > body permanantly fixed in space? Or, am I doing something totally > ridiculous? PyODE contains an actual body object that represents the static environment. And that's the ode.environment object. However, this concept isn't really applied consistently throughout PyODE. The getBody() method can return None, however the attach() method must not be called with None as one of its arguments. This means, you're near callback has to look somewhat like this. ... b1 = geom1.getBody() b2 = geom2.getBody() if b1==None: b1=ode.environment if b2==None: b2=ode.environment j.attach(b1, b2) ... The tutorial did work because the only object that has no body associated with it was the ground floor which is a non-placeable object. And calling getBody() on non-placeable objects always returns ode.environment. This situation is not really ideal. Either the ode.environment object should be dropped and the value None will represent the static environment. Or the environment concept should be consistent and getBody() should never return None. I'm quite undecided about what approach would be the better one (I'm probably slightly in favor of the environment object...). By the way, I don't know why you get a different behavior under Linux. getBody() should also return None. What body is it actually returning? - Matthias - |
From: Hezekiah M. C. <ode...@tr...> - 2005-03-03 21:29:41
|
Jonathan V Toups wrote: > Friends, > I am writing a simples 2D physics simulator for an amateur game I > am working on, and the following problem has come up: Out of curiosity, how are you planning on restricting the game to physics to 2D? I have used the Plane2D ODE addon in C/C++, but it looks like pyode does not have support for this. Hez |
From: Jonathan V T. <to...@ph...> - 2005-03-03 21:35:04
|
Hezekiah, I am using geomBox objects which are perfectly flat in on direction and extend slightly into and out of the screen. As long as no forces are applied in the z-direction, you can construct your level out of these objects. It works in Linux at any rate. -Vincent On Thu, 3 Mar 2005, Hezekiah M. Carty wrote: > Jonathan V Toups wrote: > > Friends, > > I am writing a simples 2D physics simulator for an amateur game I > > am working on, and the following problem has come up: > > Out of curiosity, how are you planning on restricting the game to > physics to 2D? I have used the Plane2D ODE addon in C/C++, but it looks > like pyode does not have support for this. > > Hez > > |