Hi everyone,
Im having a strange problems with objects (circles and boxes) crossing through the bottom part of the ground box and going out of screen. The gravity is set to (0,20) (note the difference in the coordinate system from opengl, but other than that everything is pretty much the same as the hello world program).
the small box does slow at the bottom of the larger one but then just keeps on going instead of resting on top of it. I am banging my hand on this for a few hours now...
here the code:
I'm using HGE (hge.relishgames.com) as my games engine instead of opengl and I dont know if it the cause of my problems (I doube it, though I cant find any other difference). it uses a different coordinate system
the glut - 0,0 is the top most vertex of the screen and 800,600 is the rightmost bottom one.
the exe with the demo can be downloaded here:
http://www.mediafire.com/?71hdjgw2bgy
BTW - when i place the smaller box above the larger one, it does rest on its head as it should - only when it is inside the box it failes to do so.
Im having a strange problems with objects (circles and boxes) crossing through the bottom part of the ground box and going out of screen. The gravity is set to (0,20) (note the difference in the coordinate system from opengl, but other than that everything is pretty much the same as the hello world program).
the small box does slow at the bottom of the larger one but then just keeps on going instead of resting on top of it. I am banging my hand on this for a few hours now...
here the code:
Code:
b2AABB worldAABB;
worldAABB.minVertex.Set(-1000,-1000);
worldAABB.maxVertex.Set(1000.0f, 1000.0f);
// Define the gravity vector.
b2Vec2 gravity(0.0f, 20.0f);
// Do we want to let bodies sleep?
bool doSleep = true;
// Construct a world object, which will hold and simulate the rigid bodies.
world = new b2World(worldAABB, gravity, doSleep);
// Define the ground box shape.
b2BoxDef groundBoxDef;
// The extents are the half-widths of the box.
groundBoxDef.extents.Set(100.0f, 20.0f);
// Set the density of the ground box to zero. This will
// make the ground body static (fixed).
groundBoxDef.density = 0.0f;
// Define the ground body.
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(250.0f, 100.0f);
// Part of a body's def is its list of shapes.
groundBodyDef.AddShape(&groundBoxDef);
// Call the body factory which allocates memory for the ground body
// from a pool and creates the ground box shape (also from a pool).
// The body is also added to the world.
ground = world->CreateBody(&groundBodyDef);
// Define another box shape for our dynamic body.
b2BoxDef boxDef;
boxDef.extents.Set(4.0f, 4.0f);
// Set the box density to be non-zero, so it will be dynamic.
boxDef.density = 1.0f;
// Override the default friction.
boxDef.friction = 0.3f;
// Define the dynamic body. We set its position,
// add the box shape, and call the body factory.
b2BodyDef bodyDef;
bodyDef.position.Set(260.0f, 100.0f);
bodyDef.AddShape(&boxDef);
body1 = world->CreateBody(&bodyDef);
worldAABB.minVertex.Set(-1000,-1000);
worldAABB.maxVertex.Set(1000.0f, 1000.0f);
// Define the gravity vector.
b2Vec2 gravity(0.0f, 20.0f);
// Do we want to let bodies sleep?
bool doSleep = true;
// Construct a world object, which will hold and simulate the rigid bodies.
world = new b2World(worldAABB, gravity, doSleep);
// Define the ground box shape.
b2BoxDef groundBoxDef;
// The extents are the half-widths of the box.
groundBoxDef.extents.Set(100.0f, 20.0f);
// Set the density of the ground box to zero. This will
// make the ground body static (fixed).
groundBoxDef.density = 0.0f;
// Define the ground body.
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(250.0f, 100.0f);
// Part of a body's def is its list of shapes.
groundBodyDef.AddShape(&groundBoxDef);
// Call the body factory which allocates memory for the ground body
// from a pool and creates the ground box shape (also from a pool).
// The body is also added to the world.
ground = world->CreateBody(&groundBodyDef);
// Define another box shape for our dynamic body.
b2BoxDef boxDef;
boxDef.extents.Set(4.0f, 4.0f);
// Set the box density to be non-zero, so it will be dynamic.
boxDef.density = 1.0f;
// Override the default friction.
boxDef.friction = 0.3f;
// Define the dynamic body. We set its position,
// add the box shape, and call the body factory.
b2BodyDef bodyDef;
bodyDef.position.Set(260.0f, 100.0f);
bodyDef.AddShape(&boxDef);
body1 = world->CreateBody(&bodyDef);
I'm using HGE (hge.relishgames.com) as my games engine instead of opengl and I dont know if it the cause of my problems (I doube it, though I cant find any other difference). it uses a different coordinate system
the glut - 0,0 is the top most vertex of the screen and 800,600 is the rightmost bottom one.
the exe with the demo can be downloaded here:
http://www.mediafire.com/?71hdjgw2bgy
BTW - when i place the smaller box above the larger one, it does rest on its head as it should - only when it is inside the box it failes to do so.