Where is code that resolves collisions?

razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Where is code that resolves collisions?

Post by razer »

I wish to control directions where rigidBodies go after collision.

How do I do that?

I have already set btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK flag for some rigidBodies and defined

void myContactAddedCallback(btManifoldPoint& cp, const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1);

I can track all collisions now.
But I still can't find what should I do to define where rigidBodies go after collision.

I can apply new velocity in contactAddedCallback but it would be a dirty hack. I wish to do it properly.

Thanks
razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Re: Where is code that resolves collisions?

Post by razer »

I found that line in source code

///solve contact and other joint constraints
solveConstraints(getSolverInfo());


So solveConstraints also solves contacts
razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Re: Where is code that resolves collisions?

Post by razer »

I am learning
void btSequentialImpulseConstraintSolver::convertContact(btPersistentManifold* manifold,const btContactSolverInfo& infoGlobal)


Is that method resolves collisionsby applying following impulses?

Code: Select all

				///warm starting (or zero if disabled)
				if (infoGlobal.m_solverMode & SOLVER_USE_WARMSTARTING)
				{
					solverConstraint.m_appliedImpulse = cp.m_appliedImpulse * infoGlobal.m_warmstartingFactor;
					if (rb0)
						m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].applyImpulse(solverConstraint.m_contactNormal*rb0->getInvMass(),solverConstraint.m_angularComponentA,solverConstraint.m_appliedImpulse);
					if (rb1)
						m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].applyImpulse(solverConstraint.m_contactNormal*rb1->getInvMass(),-solverConstraint.m_angularComponentB,-solverConstraint.m_appliedImpulse);
				} else
				{
					solverConstraint.m_appliedImpulse = 0.f;
				}
razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Re: Where is code that resolves collisions?

Post by razer »

I have remmed these lines but it still work as before with no difference.

Code: Select all

					//if (rb0)
					//	m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdA].applyImpulse(solverConstraint.m_contactNormal*rb0->getInvMass(),solverConstraint.m_angularComponentA,solverConstraint.m_appliedImpulse);
					//if (rb1)
					//	m_tmpSolverBodyPool[solverConstraint.m_solverBodyIdB].applyImpulse(solverConstraint.m_contactNormal*rb1->getInvMass(),-solverConstraint.m_angularComponentB,-solverConstraint.m_appliedImpulse);
Please, advise where should I look in code.
bone
Posts: 231
Joined: Tue Feb 20, 2007 4:56 pm

Re: Where is code that resolves collisions?

Post by bone »

All you did was commented out the test if the rigid bodies were valid (which they probably were in your case), of course it works the same.

Do you have access to a debugger?
razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Re: Where is code that resolves collisions?

Post by razer »

Thanks. Yes. I can debug the code and I set break point and it was calling and applying the impulses

I looked to be the place because it is applying impulse directed by contact normal.

There are other similar calls but they reside in methods like "resolveSingleConstraintRowGeneric"

I guess I should not look in Constraint code if I wish to correct contact logic.
razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Re: Where is code that resolves collisions?

Post by razer »

Could someone point me at code which resolves collisions after they are detected by applying force or impulses or translating bodies?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Where is code that resolves collisions?

Post by Erwin Coumans »

This happens inside the constraint solver, check out btSequentialImpulseConstraintSolver::solveSingleIteration.

Several versions are implemented, with and without SIMD. Check for the comments //solve all contact constraints
Thanks,
Erwin
razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Re: Where is code that resolves collisions?

Post by razer »

Thank You! You helped me a lot!

Looks like I have to define m_normalWorldOnB for certain collisions. Right now it is defined by Gjk and I have to define custom class that will use Gjk and override normals for certain pairs of objects.
razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Re: Where is code that resolves collisions?

Post by razer »

I made a following sketch

Image

I wish to detect point where rigitBody (e.g. convex) touches static body.

I make call collisionWorld->convexSweepTest() and I have defined my convexResultCallback.

But collisionWorld returns contact point like on image 3 but I wish to get point like on image 3a

I wish to know where object must stop before colliding.

Thanks
razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Re: Where is code that resolves collisions?

Post by razer »

Could someone tell me how to find contact point of convex or triangle mesh? Like I showed in previous post. Thanks
razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Re: Where is code that resolves collisions?

Post by razer »

I have not proceed far with code.
SIMD code is harder to understand and I turned it off.
But now I found that SIMD code works reliably/stable or at least differently.

Is that possible? Does SIMD use different algorithm?

-----

Back to previous my question with picture. It looks like I have to adjust collision code to make it work as I wish.
Am I right?

Thanks
razer
Posts: 82
Joined: Sun Apr 04, 2010 10:08 pm

Re: Where is code that resolves collisions?

Post by razer »

What is a status of btContinuousDynamicsWorld?

Looks like it does what I want but it has some different "bugs" also.