Is the cpSimpleMotor constraint stable?

Official forum for the Chipmunk2D Physics Library.

Is the cpSimpleMotor constraint stable?

Postby Dave » Fri Nov 13, 2009 5:59 pm

I tried testing it, but I may have done something wrong.

The only other joint I've tested so far is the pin joint, but this code works ok with that. The creation passes ok, but it seems to crash on cpSpaceAddConstraint. Thanks. ;)

Code: Select all
cpSimpleMotorNew( entity[0].object[0]->body, entity[1].object[0]->body, 0 )
cpSpaceAddConstraint( world.space, entity[1].joint[0]->constraint )
Dave
 
Posts: 35
Joined: Mon Sep 29, 2008 10:43 pm

Re: Is the cpSimpleMotor constraint stable?

Postby zaerl » Fri Nov 13, 2009 7:55 pm

What kind of error? An invalid access? Do you save the result of cpSimpleMotorNew call?
Code: Select all
entity[1].joint[0]->constraint = cpSimpleMotorNew( entity[0].object[0]->body, entity[1].object[0]->body, 0 );
cpSpaceAddConstraint( world.space, entity[1].joint[0]->constraint );
zaerl
 
Posts: 40
Joined: Fri Aug 28, 2009 8:36 am

Re: Is the cpSimpleMotor constraint stable?

Postby Dave » Fri Nov 13, 2009 9:29 pm

LOL! You were right man. What a bonehead mistake! Thanks! :lol:
Dave
 
Posts: 35
Joined: Mon Sep 29, 2008 10:43 pm

Re: Is the cpSimpleMotor constraint stable?

Postby Dave » Sat Nov 14, 2009 1:10 am

I have a question that I can't seem to find an answer for. Is it possible to determine of two cpBodies are connected by a joint from within a callback? I'm mainly talking about a pin join for now. I may be going about this the wrong way, but I'm making a game similar to fantastic contraption. When a solid rod connects to a wheel, it wont collide with that exact wheel's shape, yet it will still collide with other wheels of the same type. For instance, I have collision pairs, wheels/lines, wheels/terrain, lines/terrain, etc... I guess the key may be in the data pointer I'm giving to the cpShapes, but I haven't been able to wrap my head around it. Adding the both shapes to the same cpBody is an option, but that seems really messy. Has anyone around done anything similar to this?
Dave
 
Posts: 35
Joined: Mon Sep 29, 2008 10:43 pm

Re: Is the cpSimpleMotor constraint stable?

Postby zaerl » Sat Nov 14, 2009 9:49 am

When a solid rod connects to a wheel, it wont collide with that exact wheel's shape, yet it will still collide with other wheels of the same type.

It's very easy. When you connect the rod with the rock assign them the same group (cpShape::group). Shapes from the same group do not collide.

The official documentation wrote:group: Shapes in the same non-zero group do not generate collisions. Useful when creating an object out of many shapes that you don't want to self collide. Defaults to 0
zaerl
 
Posts: 40
Joined: Fri Aug 28, 2009 8:36 am

Re: Is the cpSimpleMotor constraint stable?

Postby Dave » Sat Nov 14, 2009 6:43 pm

Thanks again man. Somehow that slipped by me. :p
Dave
 
Posts: 35
Joined: Mon Sep 29, 2008 10:43 pm

Re: Is the cpSimpleMotor constraint stable?

Postby Dave » Sun Nov 15, 2009 4:12 pm

Ok... here's another one, probably has a simple answer as well. :lol:

Is there a way I can determine if an object is bound to another by a joint upon destruction?


btw, here's what i have so far, if you're interested...

http://www.youtube.com/watch?v=EPk54Qrnp3Q

http://www.youtube.com/watch?v=IY6kLGGw7ZI

EDIT: Actually, the group thing isn't exactly what i need either, now that I've been messing with it. Is there any possible way using the API to determine if two bodies are connected via a joint? I really need to process this info in the callback. Thanks again! :)
Dave
 
Posts: 35
Joined: Mon Sep 29, 2008 10:43 pm

Re: Is the cpSimpleMotor constraint stable?

Postby Tam Toucan » Mon Nov 16, 2009 8:42 am

I don't think there is a way directly via the API. The way I structure things is I have a ChipmunkItem which represents things in my world. The data pointer points to one of these. A ChipmunkItem knows everything about that object, all the bodies and shapes that make it up (a single item can have multiple bodies) and all it's constraints. I drive everything from the ChipmunkItems e.g. i don't just "delete a body", instead a ChipmunkItem deletes one of it's bodies and it knows everything it needs to do for that.

So you could go down a fully flexible solution where you have an equivalent of ChipmunkItem and you add a merge(ChipmunkItem*) method. So you have two objects, draw a pin joint between them and then merge the two sets of bodies/shapes/constraints together. Or if you just want to find the constraint that a body is attached two why not just have a singleton look up table of body => constraint(s) and when you delete a body just scan the list to find any constraint(s).

If you're an over-engineering OO person like me you'll go for the first...I'd recommend the second :)
User avatar
Tam Toucan
 
Posts: 141
Joined: Tue Jun 23, 2009 4:26 pm

Re: Is the cpSimpleMotor constraint stable?

Postby Dave » Mon Nov 16, 2009 7:39 pm

hehehe... Well, I have a pretty robust structure, so I can just modify it a bit to contain ptrs for each body's joints and stuff. I was really hoping there was a way through the API... but maybe I'm being lazy. :lol: Thanks man. ;)
Dave
 
Posts: 35
Joined: Mon Sep 29, 2008 10:43 pm

Re: Is the cpSimpleMotor constraint stable?

Postby Dave » Thu Nov 19, 2009 1:25 am

Hello again. :) I was wondering if scanning for Constraint->a or Constraint->b to match a body in the world will return as I think it will, or is there some swapping/sorting that happens behind the scenes? It cold be that I just need to rethink my code again.
Dave
 
Posts: 35
Joined: Mon Sep 29, 2008 10:43 pm

Next

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest