How to create custom constraints?

Post Reply
hyyou
Posts: 96
Joined: Wed Mar 16, 2016 10:11 am

How to create custom constraints?

Post by hyyou »

I want to create a new constraint type that work a little different from btGeneric6DofSpring2Constraint.

The difference is that user can set (i.e. customize) "mass", "center of mass" and "inertia" (if involved) of body A and B in constraint perspective.

For example ,
  • This is what I guess how the official Bullet constraint work:-
    • - Light body (A) will be pulled/pushed more than heavy body (B).

    If A has lower mass and B has higher mass,
    but I customized in the constraint that A has very high mass, the effect from the constraint will be :-
    • - A is pulled very little compared to B.

    (Sorry if it sound confusing. In conclusion, I just want to create a new type of constraint.)
- Where should I start?
- Do I have to modify Bullet code?
- Which files contains the constraint solver that read RigidBody's mass?

In btGeneric6DofSpring2Constraint.cpp, there are a lot of functions that read RigidBody's mass.

Can I just copy btGeneric6DofSpring2Constraint to a new class,
  • - then in the new class, I will modify every mass/centerOfMass-variable reading
    - then the new type of constraint will work?
jauthu
Posts: 12
Joined: Tue Feb 28, 2012 7:34 pm

Re: How to create custom constraints?

Post by jauthu »

I been wondering on how to do custom constraints aswel. As far as I can see, yes, you can just copy whole the btGeneric6DofSpring2Constraint class and adjust it for you liking.

I can't tell whether you need, or should introduce a new btTypedConstraintType value. However, there shouldn't be anything wrong with it if you introduce new value. The only problem might be serialization or debug drawing.

If you find anything regarding how do bullet constraints are implemented, I would be thankful if you share.
benelot
Posts: 350
Joined: Sat Jul 04, 2015 10:33 am
Location: Bern, Switzerland
Contact:

Re: How to create custom constraints?

Post by benelot »

I have no idea what you intend to achieve. The constraint has not much to do with the rigidbodies except that it constrains the motion of them both in a certain way. I do not really understand how you would change properties of the rigidbody such as inertia, COM and mass from the constraint perspective. The only thing I would understand is to set the COM in the frame of reference of the constraint, but for that you do not need a custom constraint. I have the feeling that what you want to achieve should be done in another way. Tell us what you exactly want to achieve and we can help you.
Post Reply