Trap Door?

Official forum for the Chipmunk2D Physics Library.

Trap Door?

Postby ndizazzo » Fri Mar 18, 2011 7:34 pm

Hi all,

I'm using a switch to activate a trap door.

I have a segment shape in my world, attached with a pivot joint to the static world body. The segments body mass is 100.0f and the moment is set to INFINITY (so it doesn't rotate/move before it's supposed to). My code sends a signal to the trap door, which gets handled. The trap door responds by setting its moment to 2000.0f (which should allow it to rotate). This is all fine.

The problem is, however, when I set the moment in the event handler, the object doesn't respond like it should in the physical simulation.I can create the trap door with the moment NOT set to INFINITY, and the joint works as intended (but it rotates/falls immediately due to the fact that the moment is not INFINITY).

I've tried playing around with the moment and mass values with no luck. Any ideas?

Thanks.
ndizazzo
 
Posts: 15
Joined: Thu Feb 10, 2011 7:53 pm

Re: Trap Door?

Postby ndizazzo » Fri Mar 18, 2011 11:22 pm

I got this working by setting the angular velocity to something small, however, it never stops swinging! And, since I'm modifying gravity with the accelerometer, it gets applied to the trap door.

I'd like to:

  • make the pivot joint + segment shape swing and eventually come to rest
  • stop gravity from affecting it once it is in its resting position

Any ideas?
ndizazzo
 
Posts: 15
Joined: Thu Feb 10, 2011 7:53 pm

Re: Trap Door?

Postby ndizazzo » Sat Mar 19, 2011 2:05 am

So - I've made a bit more progress on this, except I'm running into some weird stuff when I pin the trap door on the RIGHT rather the left. Check out the videos. Sorry for the bad quality, needed it quick.

The first video is the segment shape being pinned on the left and constrained to 0 and M_PI_2... Its normal! yay!

http://www.facebook.com/video/video.php?v=989480426711

The second video is the same segment shape being pinned on the right and constrained to -M_PI_2 and 0 ... what the heck.

http://www.facebook.com/video/video.php?v=989480686191

In the second video, I didn't change ANYTHING except the location of the pin, and the rotary limit joint constraints... which leads me to believe that the constraint is making it go all crazy. Any ideas why?
ndizazzo
 
Posts: 15
Joined: Thu Feb 10, 2011 7:53 pm

Re: Trap Door?

Postby slembcke » Sat Mar 19, 2011 10:56 am

Are you sure you got the order of the minimum and maximum correct in the code? If you swap them, bad things will happen, much like the video you just posted actually.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Trap Door?

Postby ndizazzo » Sun Mar 20, 2011 2:18 am

slembcke wrote:Are you sure you got the order of the minimum and maximum correct in the code? If you swap them, bad things will happen, much like the video you just posted actually.


I did try changing them, but it actually crashed, so I assumed the trap door bouncing around like that was a step in the right direction :\
ndizazzo
 
Posts: 15
Joined: Thu Feb 10, 2011 7:53 pm

Re: Trap Door?

Postby slembcke » Sun Mar 20, 2011 1:52 pm

Hmm. What was the crash?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Trap Door?

Postby ndizazzo » Mon Mar 21, 2011 2:33 am

Code: Select all
// Calls the callback function for the objects in a given chain.
static inline void
query(cpSpaceHash *hash, cpSpaceHashBin **bin_ptr, void *obj, cpSpaceHashQueryFunc func, void *data)
{
   restart:

for(cpSpaceHashBin *bin = *bin_ptr; bin; bin = bin->next){
Code: Select all
      cpHandle *hand = bin->handle;
      void *other = hand->obj;
      
      if(hand->stamp == hash->stamp || obj == other){
         continue;
      } else if(other){
         func(obj, other, data);
         hand->stamp = hash->stamp;
      } else {
         // The object for this handle has been removed
         // cleanup this cell and restart the query
         removeOrphanedHandles(hash, bin_ptr);
         goto restart; // GCC not smart enough/able to tail call an inlined function.
      }
   }
}

Looks like the address of bin is NULL: "Thread 1: Program received signal: "SIGTERM"."

When I switched
Code: Select all
        [self addRotaryLimitJoint :-M_PI_2 :0];


to

Code: Select all
        [self addRotaryLimitJoint :0 :-M_PI_2];


Code: Select all
// Adds a pivot joint between this and the world static body
// Location is in world coordinates
-(void)addPivotJoint:(cpVect)location
{   
    cpConstraint *c = cpPivotJointNew(entityBody, nil, location);
    entityConstraints[currentNumConstraints] = c;
    ++currentNumConstraints;
}

// Adds a rotary joint between this and the world static body
-(void)addRotaryLimitJoint:(float)min:(float)max
{
    cpConstraint *c = cpRotaryLimitJointNew(entityBody, nil, min, max);
    entityConstraints[currentNumConstraints] = c;
    ++currentNumConstraints;
}


These methods are assuming Chipmunk works the same way when you add a constraint, similar to if you add a shape with a null body... That it automatically adds it to the static world body.
ndizazzo
 
Posts: 15
Joined: Thu Feb 10, 2011 7:53 pm

Re: Trap Door?

Postby ndizazzo » Mon Mar 21, 2011 3:22 am

I've been playing with these values for hours.... -M_PI_2 and 0 are the only ones which give me what I want. It just seems like it gets an extreme angular momentum for some reason :\

I tried moving the pivot joint around:

- When it was in the center, I didn't get that sporadic jumping behavior
- When it's 2/3 of the way through the trap door, it bounces once, then comes to rest, begins bouncing slowly until it is bouncing wildly again (like in the video)

It seems like as soon as the joint and constraint get to its limit and it comes time to bounce, the effect of the joint being constrained when it "hits" the bottom is what causes it to bounce back up but whatever value Chipmunk is giving it for its velocity is WAY off the chart. Not sure why :(
ndizazzo
 
Posts: 15
Joined: Thu Feb 10, 2011 7:53 pm

Re: Trap Door?

Postby ndizazzo » Mon Mar 21, 2011 3:58 am

Here's a really bad hack that fixes the problem.

Code: Select all
    if (entityBody->a >= M_PI_2 || resting && pivotSide == TRAP_RIGHT)
    {
        resting = YES;
        entityBody->a = M_PI_2;
        [self setAngularVelocity:0];
        [self setMoment:INFINITY];
        [self setVelocity:cpvzero];
    }


I'd still like to figure out why this is happening though.
ndizazzo
 
Posts: 15
Joined: Thu Feb 10, 2011 7:53 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 3 guests