Gurrier
03-05-2010 15:43:43
Fast question.
In the Physx wrapper. Is there support for a custom force field kernel?
In the Physx wrapper. Is there support for a custom force field kernel?
Gurrier
03-05-2010 15:43:43
andy
09-05-2010 15:39:38
Gurrier
09-05-2010 20:09:32
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);