How to modelling a chain

CoffeeMan

26-07-2007 09:33:22

Hello all, I am beginner in game developing and ogre and physx, too
I try to make a chain. First idea, to create many spheres and connect it by spherical joints. But i have a problem described bellow code
Bellow my code of creating a chain:

body* createSphereBody(float radius, float density, Ogre::Vector3 pos)
{
params<rigidbody> _param;
_param.mScale = Vector3(radius, radius, radius);
return mScale->createBody("", "sphere.2m.mesh", new nxOgre::sphereShape(radius), density, _param, pos);
}

void createChain(body*& beg, body*& end, float xb, float yb, float zb, float xe, float ye, float ze, float m, float n)
{
float dx = (xe-xb)/n;
float dy = (ye-yb)/n;
float dz = (ze-zb)/n;
float dm=m/n;

body *prev = 0, *b;
for (int i = 0; i < n; i++) {
b = createSphereBody(0.02f, dm, Vector3(xb, yb, zb));
if (prev != 0)
joint::createSphericalJoint(prev, b, Vector3(xb+dx/2, yb+dy/2, zb+dz/2));
else beg = b;
prev = b;
xb += dx; yb += dy; zb += dz;
}
end = b;
}


Next I create box that hasn't a sence on gravitation and connect begin of chain with box:

body *beg, *end;
createChain(beg, end, 0,9.90,0, 0,1,0, 10, 30);

body *b = mScene->createBody("thing", "cube.1m.mesh", new nxOgre::cubeShape(1), 100.0f, Vector(0,10,0));
b->setIgnoreGravity(true);
joint::createSphericalJoint(b, beg, Vector3(0, 9.95, 0));

Problem: When I add force to box, all balls begin fast travel around a circle but don't follow the box (that has big mass and slow move)

betajaen

26-07-2007 09:49:14

It's probably to much stress on the joints, or another factor.

Have you tried creating a chain with cloth? If you use a low vertex/triangle count and use a chain texture in the material. It should come out pretty well, and quite accurate. The cloth would stretch though, so you'd have to limit it or turn it off.

CoffeeMan

26-07-2007 11:38:46

It's probably to much stress on the joints, or another factor.

Have you tried creating a chain with cloth? If you use a low vertex/triangle count and use a chain texture in the material. It should come out pretty well, and quite accurate. The cloth would stretch though, so you'd have to limit it or turn it off.


I thought creating a chain with cloth but i don't know how :oops: since tutorial 1001.Cloth crash in member function
NxStream& MemoryWriteBuffer::storeBuffer(const void* buffer, NxU32 size)
On line

NxU8* newData = (NxU8*)NX_ALLOC(maxSize);

NX_ALLOC returns NULL :cry:
If fully:

NxU32 expectedSize = currentSize + size; //currentSize==0, size==1

if(expectedSize > maxSize) { //maxSize == 0
maxSize = expectedSize + 4096;
NxU8* newData = (NxU8*)NX_ALLOC(maxSize); maxSize == 4097, newData==NULL
if(data) { //skip
memcpy(newData, data, currentSize);
NXOGRE_FREE(data);
}
data = newData; //data == 0
}
memcpy(data+currentSize, buffer, size); // crash
currentSize += size;

Pottej

28-07-2007 16:05:30

Check out the Ageia rope example in their documentation, it worked well for us and I'm sure with some tweaking you can get it to act more like a chain.

I found that if you attach objects to something with too much of a mass difference (order of 100+) then you will get very unstable behaviour. Also for our rope to remain stable we had to use a very high solver iteration count... try one around 30-100 (you need a powerful CPU!).