I know, I'm not the most patient man on earth.

Code: Select all
//particle globals
#define REST_PARTICLES_PER_METER 10
#define KERNEL_RADIUS_MULTIPLIER 1.8f
//#define MOTION_LIMIT_MULTIPLIER (3*KERNEL_RADIUS_MULTIPLIER)
#define MOTION_LIMIT_MULTIPLIER 3
#define PACKET_SIZE_MULTIPLIER 8
NxFluid* fluid = NULL;
NxVec3 gParticleBuffer[10000];
NxU32 gParticleBufferCap = 10000;
NxU32 gParticleBufferNum = 0;
array<ISceneNode*> particles;
NxFluid* CreateFluid(const NxVec3& pos, NxU32 sideNum, NxReal distance, NxScene* scene)
{
// Create a set of particles
gParticleBufferNum = 0;
NxReal rad = sideNum*distance*0.5f;
for (NxU32 i=0; i<sideNum; i++)
{
for (NxU32 j=0; j<sideNum; j++)
{
for (NxU32 k=0; k<sideNum; k++)
{
NxVec3 p = NxVec3(i*distance,j*distance,k*distance);
if (p.distance(NxVec3(rad,rad,rad)) < rad)
{
p += pos - NxVec3(rad,rad,rad);
gParticleBuffer[gParticleBufferNum++] = p;
}
}
}
}
// Set structure to pass particles, and receive them after every simulation step
NxParticleData particles;
//particles.maxParticles = gParticleBufferCap;
particles.numParticlesPtr = &gParticleBufferNum;
particles.bufferPos = &gParticleBuffer[0].x;
particles.bufferPosByteStride = sizeof(NxVec3);
// Create a fluid descriptor
NxFluidDesc fluidDesc;
fluidDesc.maxParticles = gParticleBufferCap;
fluidDesc.kernelRadiusMultiplier = KERNEL_RADIUS_MULTIPLIER;
fluidDesc.restParticlesPerMeter = REST_PARTICLES_PER_METER;
fluidDesc.motionLimitMultiplier = MOTION_LIMIT_MULTIPLIER;
fluidDesc.packetSizeMultiplier = PACKET_SIZE_MULTIPLIER;
fluidDesc.stiffness = 50;
fluidDesc.viscosity = 22;
fluidDesc.restDensity = 1000;
fluidDesc.damping = 0;
fluidDesc.restitutionForStaticShapes = 0.4f;
fluidDesc.dynamicFrictionForStaticShapes= 0.3f;
fluidDesc.collisionResponseCoefficient = 0.5f;
fluidDesc.collisionDistanceMultiplier = 0.1f;
fluidDesc.simulationMethod = NX_F_SPH; //NX_F_NO_PARTICLE_INTERACTION
fluidDesc.initialParticleData = particles;
fluidDesc.particlesWriteData = particles;
fluidDesc.flags &= ~NX_FF_HARDWARE; //~NX_FF_HARDWARE;
fluidDesc.flags |= NX_FF_COLLISION_TWOWAY;
NxFluid* fl = scene->createFluid(fluidDesc);
assert(fl != NULL);
return fl;
}
void ReleaseFluid()
{
if(!particles.empty())
{
s32 num_destroyed=0;
for (u32 i = 0 ; i < particles.size() ; ++i)
{
particles[i]->remove();
particles.erase(i);
num_destroyed++;
}
printf("Particles destroyed: %d\n", num_destroyed);
}
if(fluid)
{
if (physxManager->getScene()) physxManager->getScene()->releaseFluid(*fluid);
fluid = NULL;
}
}
void RenderFluid()
{
//keep physics & graphics in sync
for (NxU32 p=0; p<gParticleBufferNum; p++)
{
NxVec3& particle = gParticleBuffer[p];
particles.push_back(smgr->addSphereSceneNode(.1f,5,0,-1,vector3df(particle.x,particle.y,particle.z)));
}
}
void UpdateFluid()
{
for (u32 i = 0 ; i < particles.size() ; ++i)
{
NxVec3& particle = gParticleBuffer[i];
particles[i]->setPosition(vector3df(particle.x,particle.y,particle.z));
}
}
....
fluid = CreateFluid(NxVec3(0,200,0), 15, 0.1, physxManager->getScene());
RenderFluid();
.....
//Release all
ReleaseFluid();
in the event that you want it to swing like a door you will want the anchor to be the point connecting the two boxes, that way they will be connected at that point. So a door you will want the anchor to be the middle of the door height and on the edge where the hinges would be. Hope this helps you.Sets the point where the two actors are attached, specified in global coordinates.
Set this after setting the actors of the joint.
Sleeping: This call wakes the actor(s) if they are sleeping.
Parameters:
[in] vec Point the actors are attached at, specified in the global frame. Range: position vector
Code: Select all
boxPosition=box.getPosition();
boxPosition.Y-=box.getHeight()/2;//I don't think this function exists though
boxPosition.X-=box.getWidth()/2;//Once again I don't think this exists
not sure what you mean by that...?You commented out cloth object creation which isn't a good work around