behdad / box2d

Automatically exported from code.google.com/p/box2d
2 stars 12 forks source link

b2Island::Report() doesn't say how many impulses are set for b2ContactImpulse #229

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. setup world etc..
2. set contact listener 
3. implement postsolve

What is the expected output? What do you see instead?
not all impulses are set for the b2ContactImpulse parameter. I expect them to 
be set.

What version of the product are you using? On what operating system?
2.1.2 & I checked out from svn to double check if the report function has 
changed. Which it has not.

Please provide any additional information below.

[code]
void b2Island::Report(const b2ContactConstraint* constraints)
{
    if (m_listener == NULL)
    {
        return;
    }

    for (int32 i = 0; i < m_contactCount; ++i)
    {
        b2Contact* c = m_contacts[i];

        const b2ContactConstraint* cc = constraints + i;

        b2ContactImpulse impulse;
// sometimes cc->pointCount (vc is used for the version I'm using) is 1
// but impulse.normalImpulses is b2_maxManifoldPoints elements big (which is by 
default 2).
// when I get the postsolve event there is know easy way to know how many 
// normalImpulses are set. Atleast all the tutorials I have seen
// dont even address the issue :( they must have been lucky
// cause I get large numbers for the  normalImpulses[1]
// it worked fine on the iPhone for some strange reson
        for (int32 j = 0; j < cc->pointCount; ++j)
        {
            impulse.normalImpulses[j] = cc->points[j].normalImpulse;
            impulse.tangentImpulses[j] = cc->points[j].tangentImpulse;
        }

        m_listener->PostSolve(c, &impulse);
    }
}
[/code]

Solution 1: add a count to b2ContactImpulse
Solution 2 (hackish): set the impulses to 0 first

I did solution 2;
[code]
        for(int i =0; i < b2_maxManifoldPoints; i++)
            impulse.normalImpulses[i] = 0;
[/code]
And my game more closely matched the iphone results interms of things exploding.

Original issue reported on code.google.com by openem...@gmail.com on 11 Aug 2011 at 5:33

GoogleCodeExporter commented 9 years ago
The count is equal to b2Manifold::pointCount. Nevertheless, I added a count to 
b2ContactImpulse.

Command: Commit  
Modified: D:\Development\Box2D\Box2D\Box2D\Dynamics\b2Island.cpp  
Modified: D:\Development\Box2D\Box2D\Box2D\Dynamics\b2WorldCallbacks.h  
Sending content: D:\Development\Box2D\Box2D\Box2D\Dynamics\b2Island.cpp  
Sending content: D:\Development\Box2D\Box2D\Box2D\Dynamics\b2WorldCallbacks.h  
Completed: At revision: 206  

Original comment by erinca...@gmail.com on 23 Aug 2011 at 4:29