How to create a working force field

leandro

12-07-2008 09:23:32

I'm trying to create a force field, with this code

NxOgre::SimpleShape* shape = NxOgre::SimpleShape::createFromString("sphere: 100");
NxOgre::ForceFieldFunction force;
force.Constant = NxVec3(0,100000,0);
NxOgre::ForceField field = NxOgre::ForceField(shape,mScene,force);
field.simulate();


but it doesn't happen anything.
What's the correct way to do this??

Gohla

12-07-2008 10:24:47

I also had problems with the NxOgre forcefield code, so I just used PhysX code instead. The forcefield demo has some nice code examples, you can take most code from that example and edit it a bit so it works with NxOgre.

Here's a piece of code I use to create a forcefield for a blow fan:

void Fan::createForcefield(const NxOgre::Pose& rPose) {
NxForceFieldDesc ffDesc;
NxForceFieldLinearKernelDesc lKernelDesc;

lKernelDesc.constant = NxVec3(500, 0, 0);
lKernelDesc.falloffLinear = NxVec3(0.4, 0, 0);

//The forces do not depend on where the objects are positioned
NxMat33 m;
m.zero();
lKernelDesc.positionMultiplier = m;

//Create linear kernel
mLinearKernel = this->getScene()->getNxScene()->createForceFieldLinearKernel(lKernelDesc);
ffDesc.kernel = mLinearKernel;
ffDesc.coordinates = NX_FFC_CARTESIAN;
ffDesc.actor = this->getNxActor();
ffDesc.flags = 0;

mForceField = this->getScene()->getNxScene()->createForceField(ffDesc);

//Attach an include shape
NxBoxForceFieldShapeDesc b;
b.dimensions = NxVec3(30, 3, 3);
b.pose.t = NxVec3(30, 0, 0);
mForceFieldShape = mForceField->getIncludeShapeGroup().createShape(b);
}

leandro

12-07-2008 16:55:03

Ok, I'll try with the Physx demo's code, but it would be interesting to know how does the NxOgre ForceField work :roll:

Thanks anyway!!

betajaen

12-07-2008 17:11:53

I haven't tried the FF code in a while. It may be broken, I'll do some tests when I've finished Cloth and Cake.