IrrPhysx 0.2 - Nvidia Physx 2.8.1 wrapper

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
MikeDee
Posts: 35
Joined: Wed Nov 18, 2009 11:41 pm

Post by MikeDee »

When will you release the new version for Irrlicht 1.6 ?
I know, I'm not the most patient man on earth. :lol:
rootroot1
Posts: 44
Joined: Wed Nov 25, 2009 6:42 pm
Location: Odessa, Ukraine

Greetings Chris !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Post by rootroot1 »

Greetings Chris !!!!!!!!!!

I have some proposition and questions to you...

1. I think you should add two methods to IrrPhysX namespace to get NxScene and NxActor. Am i right ?
it will be very useful for doing runtime changes or some external things...

2. I have implemented this methods to the namespace,
but when i trying to make revolute joints and sample fluid, nothing works properly. Where i made a mistake ?? Please help !!!!!!!!!!!!!!!!!! :cry: :cry:

source code
http://etlweb.com/nvPhysxTest.rar
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

I am not really sure how to add the get actor with how it is set up at the moment, any ideas JP? You commented out cloth object creation which isn't a good work around :P. I'll try and get creative.

As for the joints I just downloaded them I will look into it and see what I come up with.

We still have a few things on the todo list before the next release I have some time today since I am waiting on some lighting issues with my game and I need joints in the near future so I may get this fixed and added into irrphysx before the todo list gets complete.
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

It looks like your code is working fine actually you just didn't call the update transformation functions on the boxes. If you add those to your while loop then you see the bottom box fall and lean to the side which is caused by the joint I believe.
rootroot1
Posts: 44
Joined: Wed Nov 25, 2009 6:42 pm
Location: Odessa, Ukraine

Yahhhhhhhhhhhhooooooooooooooo

Post by rootroot1 »

Yaaaaaaaaaaaaaahooooooooooooooo!!!!!!

My fluid is working somehow now !!!! But not really well.... :cry:
I'l try to explain: When i create a set of ~2000 particles framerate is stable,
but if set of particles is bigger framerate suxx ^((

Maybe someone (Insomniacp, or JP, or someone else ...) could modify my code and post here ????????????????????????????????

Fragment of code:

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();


screenshot
Image

And full source & binary with vs 9.0 solution
http://etlweb.com/nvPhysxTestFluid.rar
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

I will look into it but I think it is because you are making 2000+ spheres which is going to cause fps to drop since that is a lot of polygons. That is my first thought at the moment.
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

yeah, that is the issue. The physx example uses a 2d square to display the particles as does most particle system I believe. I would suggest switching to billboards to display the particles instead of spheres or cubes. That should increase your performance quite a bit.
rootroot1
Posts: 44
Joined: Wed Nov 25, 2009 6:42 pm
Location: Odessa, Ukraine

Ok, joints is Ok !!!! but....

Post by rootroot1 »

Ok, now i have solved the problem with joints,
Insomniacp was right, we must update nodes, earlier I have forgot to
add objects to array core::array<SPhysxAndNodePair*> objects;
Thank you Insomniacp !!!!!!!!!!!!!!!!!!!!!!!!!!!

But I don't understand, how to calculate globalAnchor :shock: :shock:
In my code this parameter is wrong ((( a little ... :roll:

screen

Image

modified solution

http://etlweb.com/nvPhysxTest.rar
Last edited by rootroot1 on Sun Dec 20, 2009 1:33 am, edited 1 time in total.
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

The SDK Docs state the following
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
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.

To get the right position (will vary depending how the box was built, this will be if the center of the box is its origin).

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
PS, this is what I think you are trying to accomplish correct?
http://www.ozone3d.net/blogs/demoniak3d/?p=27
rootroot1
Posts: 44
Joined: Wed Nov 25, 2009 6:42 pm
Location: Odessa, Ukraine

Post by rootroot1 »

Yes, you're right !!!!!!!!!!!!!!!!!!! Thank you for fast replies!!
Ok, coud you calculate this parameter for boxes with dimensions like in my code, and
so it will looks like an example in blog that you've posted above ???

Please ... :idea:

My head will explode soon ))))))

createBox(physxManager, smgr, driver, core::vector3df(30.0f,110.0f,-60.0f), core::vector3df(30.0f,60.0f,30.0f), 10)

createBox(physxManager, smgr, driver, core::vector3df(30.0f,50.0f,-60.0f), core::vector3df(30.0f,60.0f,30.0f), 5)

Thanks in advance !!!!!!!!!!!!!!!
Insomniacp
Posts: 288
Joined: Wed Apr 16, 2008 1:45 am
Contact:

Post by Insomniacp »

NxVec3 globalAnchor = NxVec3(45.0f,80.0f,-45.0f);
NxVec3 globalAxis = NxVec3(0,0,1);
That should do it. Took a little to find out how it was built but it was middle as origin, so I did as I stated in earlier post. You can move across the z axis as much as you want since it is the global axis. Glad to help.
rootroot1
Posts: 44
Joined: Wed Nov 25, 2009 6:42 pm
Location: Odessa, Ukraine

Post by rootroot1 »

Thanks a lot friend !!!!!!

Now it looks like in PhysX SDK example.

Maybe it will be useful for someone like me )))))

Image
tinhtoitrangtay
Posts: 70
Joined: Tue Oct 28, 2008 12:59 pm

Post by tinhtoitrangtay »

IrrPhysx-v0.3 release at link http://sio2.g0dsoft.com/modules/wmpdown ... d=2&lid=29 but i can't download it. Somebody can download it please share. Thank you so much.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

That's not the real IrrPhysx unfortunately, 0.3 isn't ready for release yet.

rootroot1, i wasn't going to add any getActor/getScene functions to IrrPhysx as that's Physx specific stuff and I wanted to keep Physx pretty much hidden away from the user when using IrrPhysx. It should be easy enough for you to add those in if you need them for your project though.

Good work on the joints, has that come from SVN or something you've done yourself?
You commented out cloth object creation which isn't a good work around
not sure what you mean by that...?
Image Image Image
rootroot1
Posts: 44
Joined: Wed Nov 25, 2009 6:42 pm
Location: Odessa, Ukraine

Post by rootroot1 »

Hi, Chris !!!!!!

Joints was from PhysX SDK lesson, just modified for Irrlicht... but example need getActor method ^((

Could you help me with fluid, some ideas ?? Do you already have some code ?? I've tried to modify CFluidSceneNode, made by sio2, but nothing works !!! ( because of my bad knowledge in drawing VertexPrimitiveList )^(((((

I will be really happy If you give an advice, or some source code !!!!

my mail: generalkalmar@gmail.com
Post Reply