PHYSX: custom force field kernel

Gurrier

03-05-2010 15:43:43

Fast question.

In the Physx wrapper. Is there support for a custom force field kernel?

andy

09-05-2010 15:39:38

I'm not actively supporting the Physx wrapper but happy to take a look -- what module/header/library are you referring to? (ie what do I need to go looking for to see if it's included or what is missing)

Thanks
Andy

Gurrier

09-05-2010 20:09:32

Well in Physx you have the default ForcefieldKernel called LinearForceFieldKernel. A fancy word for "What should I do with the actors".
This kernel is made for linear forcefield is a simple wind or gravity. Now if you want to make a different or special kernel, like the gravitational pull of planets we have to make our own. The problem is that this is pretty weard.

This comes from the physx API docs:
Creation
You create a force field custom kernel in a scene by creating a .h file which is structured in the following way:

-------- SimpleKernel.h --------
#ifndef SIMPLEKERNEL_H
#define SIMPLEKERNEL_H

#include "NxForceFieldKernelDefs.h"

// NxForceFieldKernelSimple will be the name of this kernel class
NX_START_FORCEFIELD(Simple)

// bindable constants - e.g. the height of your tornado
NxVConst(Foo);
NxFConst(Bar);
NxBConst(Orc);

NX_START_FUNCTION
// all kernel function code goes in here and have to be statements
// which were described in the Custom Kernel Statements section of the user guide.
// input are the vectors Position and Velocity transformed into the chosen coordinate system.
// output are the vectors force and torque

// sample instructions
NxFloat a = 2.0f;
NxFloat b = NxSelect(Orc, 2.0f, 15.0f);
NxVector x = Foo * Velocity;
NxFailIf(1.0f < a | b > x.getX());

force = Position * x.dot(x);
NX_END_FUNCTION

NX_END_FORCEFIELD(Simple)
#endif
--------------------------------

And then you can instantiate the custom kernel class in your application and pass it to the force field:
#include "SimpleKernel.h"
...
NxForceFieldKernelSimple* pSimpleKernel;
pSimpleKernel = new NxForceFieldKernelSimple();
...
NxForceFieldDesc ffDesc;
ffDesc.kernel = pSimpleKernel;

NxForceField* pForceField;
pForceField = scene->createForceField(ffDesc);



I'm totally clueless.