this is my EdgeTest.h
Everytime I press 'c'
i got the different result
but after i press the "restart" button ,the first result is same
it's liked exist some random seriales in box2d contact result
"restart" can reset the random seed...
Code:
#ifndef EDGE_TEST_H
#define EDGE_TEST_H
#define MAX_TEST_BALL 30
class EdgeTest : public Test
{
public:
EdgeTest()
{
{
b2BodyDef bd;
b2Body* ground = m_world->CreateBody(&bd);
b2Vec2 v1(-10.0f, 6.0f), v2(-10.0f, 0.0f), v3(0.0f, 0.0f);
b2Vec2 v4(0.0f, 6.0f) ;
b2EdgeShape shape;
shape.Set(v1, v2);
shape.m_hasVertex3 = true;
shape.m_vertex3 = v3;
ground->CreateFixture(&shape, 0.0f);
shape.Set(v2, v3);
shape.m_hasVertex0 = true;
shape.m_hasVertex3 = true;
shape.m_vertex0 = v1;
shape.m_vertex3 = v4;
ground->CreateFixture(&shape, 0.0f);
shape.Set(v3, v4);
shape.m_hasVertex0 = true;
shape.m_hasVertex3 = false;
shape.m_vertex0 = v2;
ground->CreateFixture(&shape, 0.0f);
}
{
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.position.Set(-5.5f, 0.6f);
bd.allowSleep = false;
b2CircleShape shape;
shape.m_radius = 0.5f;
for (int i=0;i<MAX_TEST_BALL;i++)
{
m_testBody[i]= m_world->CreateBody(&bd);
m_testBody[i]->CreateFixture(&shape, 1.0f);
}
m_bombIndex=MAX_TEST_BALL;
}
}
b2Body* m_testBody[MAX_TEST_BALL];
int m_bombIndex ;
void Step(Settings* settings)
{
bool advanceRay = settings->pause == 0 || settings->singleStep;
if (m_bombIndex >=0 && m_bombIndex<MAX_TEST_BALL)
{
m_testBody[m_bombIndex]->SetLinearVelocity(b2Vec2(-2.0f+m_bombIndex*0.1f,20.0f));
m_testBody[m_bombIndex]->SetTransform(b2Vec2(0 ,6),0.0f);
m_bombIndex++;
}
Test::Step(settings);
}
void Keyboard(unsigned char key)
{
switch (key)
{
case 'c':
{
m_bombIndex=0;
}
break;
}
}
static Test* Create()
{
return new EdgeTest;
}
};
#endif