cpJoint types

Official forum for the Chipmunk2D Physics Library.
Post Reply
dc443
Posts: 20
Joined: Sun Dec 02, 2007 3:54 am
Contact:

cpJoint types

Post by dc443 »

I was wondering if it was possible to add something like this:

Code: Select all

enum cpJointType{
	PIN,
	SLIDE,
	PIVOT,
	GROOVE
};
and then modify cpJoint to include it:

Code: Select all

typedef struct cpJoint {
	cpBody *a, *b;
	// begin new code
	cpJointType type;
	// end new code
	void (*preStep)(struct cpJoint *joint, cpFloat dt_inv);
	void (*applyImpulse)(struct cpJoint *joint);
} cpJoint;
That way we can easily figure out which type of joint each joint is, and to treat it accordingly (for example to draw it on the screen or something).

Because otherwise I'd have to make a completely separate data structure to hold a list of joints. it just seems way too cumbersome. There is already something very similar to this that is implemented with cpShape.
W.P. van Paassen
Posts: 16
Joined: Tue Aug 21, 2007 3:53 am
Contact:

Re: cpJoint types

Post by W.P. van Paassen »

Hi,

See thread http://www.slembcke.net/forums/viewtopic.php?f=3&t=17
I've also attached a patch in there

Cheers
WP
dc443
Posts: 20
Joined: Sun Dec 02, 2007 3:54 am
Contact:

Re: cpJoint types

Post by dc443 »

Oh, whoops! And I thought i had read every topic on this forum.
W.P. van Paassen
Posts: 16
Joined: Tue Aug 21, 2007 3:53 am
Contact:

Re: cpJoint types

Post by W.P. van Paassen »

No problem, in fact the more people who ask for this, the more likely it will get included :-)
User avatar
slembcke
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: cpJoint types

Post by slembcke »

(sigh)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Esch
Posts: 3
Joined: Fri Jan 04, 2008 4:02 am
Contact:

Re: cpJoint types

Post by Esch »

This is only tangentially on topic, but perhaps it's better to keep the joint struct opaque rather than introduce some form of a runtime typing system just to make drawing joints easier. Judging from the way other things are done in the library, I think you're intended to keep a reference to a joint you've created in your own joint class and maintain a list of those. You can then add any typing you want without relying on the engine's internal representation of joints, etc. which may help to keep things cleaner.

Just my two cents on the topic of joint types, I suppose. Having the types available certainly does make things more convenient when you're just playing around, though.
User avatar
slembcke
Site Admin
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: cpJoint types

Post by slembcke »

With some of the changes I have in mind for the future, I will be needing to add joint classes like I've done with shapes. That will require me to store the joint type yes. It will also mean that functions to get the impulse magnitude applied to the joint available for inspection will be possible. (think breakable joints)

On the other hand Esch has the right idea, you really should be thinking of a lot of the Chipmunk datatypes to be immutable and opaque. You really don't want to rely on the internal implementation of joints and shapes if you want your program to be compatible with newer Chipmunk releases.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests