Objects inside objects? spheres bouncing inside Big sphere..

toglia

24-03-2008 22:53:20

Hey!

Well, the title says it all, how to make actors interact inside another actors?

Lets say you have this Big sphere and you need to put some other spheres inside! (everyone bouncing around like crazy!)

If I do something like this:

mScene->createBody("sphere.10m.mesh", new SphereShape(5.0f), Vector3(0,10,0));
mScene->createBody("sphere.2m.mesh", new SphereShape(1.0f), Vector3(0,10,0));

The little sphere seems to bounce out rapidly from the big one.

I have tried reversing the normals... (A simple guess...)

Normally I would read some documentation till I find something, in this case where there is so little, some code would be helpfull!

Another thing, is PhysX free to use on commercial games?
Thanks!!!

betajaen

24-03-2008 23:03:57

You can't do things like that. Well you can you use a triangle shape but it would be quite inaccurate and the bigger sphere couldn't move at all.

And yes there is documentation - quite a bit; Not just the Shortguide, but a massive PhysX Documentation file that Ageia wrote which would tell you these things.

Yes, PhysX is free for commercial use.

toglia

25-03-2008 01:12:32

That's weird, That situation didn't look that crazy, specially after seeing what can be done with soft bodies, fluids and cloth...

Anyway, I'm thinking maybe I can create the big sphere by revolving a double sided semi circle to give the sphere some thickness. Then I'd use the triangle shape for collision, no matter its not 100% accurate.

Haven't tried it thought, my copy of Maya is at work, what do you think? There must be a good workaround with this...

My question is why do you say the big sphere wouldn't move at all..

Thanks Betajaen,

betajaen

25-03-2008 09:25:14

Because triangle meshes can only be attached to static actors - which static actors cannot move.

Aiursrage2k

28-03-2008 19:04:04

Create two spheres the same size (sphere0,sphere1)
Sphere0: Raise the flag disable collision response.
Sphere1->Disable the collision between this actor sphere2 and sphere0
Sphere2->The smaller sphere
Every frame move sphere 0 to sphere1s pose

Now you can get the collision between sphere0 and sphere2 but you would have to handle the collision resolution yourself :(

toglia

04-04-2008 08:13:53

Ok, so I was kinda busy these days and couldn't do any testing...

I started adding simple code to a fresh Cake 3.0 application (NxOgre 0.9):

mScene->createBody("sphere10.mesh", new NxOgre::TriangleMeshShape("sphere10.mesh","material:bounce"), Vector3(0,10,0), "mass: 500");
(to create the Big hollow sphere).

Then I added some little spheres inside:

for (int i=0; i<25;i++){
mScene->createBody("sphere.2m.mesh", new SphereShape(1,"material:bounce"),
Vector3(
Math::RangeRandom(-4,4),
5+Math::RangeRandom(-4,4),
Math::RangeRandom(-4,4)), "mass: 1");
}

Now look what I get:
http://www.youtube.com/watch?v=Ity_qLZ4UtY

The big sphere can move!!!

So apparently this is what I wanted, but I'm thinking this is just a weird case where it works, I really don't know... What do you think Betajaen?

Also I have seen other weird things like some balls can get out if I tumble the transparent ball too much, another thing is that it doesn't respond to its material so in this case it doesn't bounce no matter what.

Aiursrage thanks for your response too, I will see what I can do, right now I don't know hot to code any of that but I will give it some time. What do you mean by having to handle the collision resolution myself, I'm also trying to get as high fps as I can.

I am going to put some obstacles inside the big sphere and rotate it so I don't know if sticking with the TriangleMeshShape on a moving object is a good idea? What do you guys think?

Any thoughts on this I am going to appreciate.

Thanks in advance.

betajaen

04-04-2008 11:17:33

What the...

Well it does work. But you won't be able to have a second bigger sphere collide with the first; they will pass through each other or the bigger sphere be able to collide on terrain or triangle meshes making up a level.

Also I would check to see if PhysX isn't spitting error messages out each frame about it being like that; which will cause a massive frame drop.

A slightly better approach is to model the sphere in your application. Make every quad of the sphere a separate model and extend them by the thickness of your sphere. Jot down the position of each quad and export them; convert them to Convex NXS's and load them in using a compound shape. At least then it may be less accuracte but you can have collisions with bigger spheres and let it roam free on terrains and triangle meshes.

toglia

05-04-2008 00:12:55

Betajaen, I hate to be handguided, but I googled nxs files quite a bit and didnt find much.

Could you please tell me how to convert those separte cubes to nxs files..?

Thanks again.

betajaen

05-04-2008 00:20:39

toglia

05-04-2008 14:40:38

Lol, you rock!

Aiursrage2k

06-04-2008 16:05:38

Thats pretty neat that you got it working!

toglia

07-04-2008 02:54:46

Well... the truth is that I did it using a dynamic triangled mesh shape, to do the big sphere, which teorically isn´t right or not completely supported by PhysX right now.

In fact, I was getting a warning message in the nxogre log but didn't cause the program to stop or lower the framerates. Later on I found out I could not add forces or torque to this big sphere, so this was not a valid solution...

I will be doing Betajaen's solution using Flour when I have some time.

Another thing, Betajaen, normally when I export something from my 3d modelling application with certain offset (position) then I dont have to re-position that thing by code, so... Is this valid with flour and convexShapes? cause, I wouldn't have to jot down the positions of all those cubes right?

BTW, that was truly a heck of idea! Thanks!

betajaen

07-04-2008 10:22:05

Another thing, Betajaen, normally when I export something from my 3d modelling application with certain offset (position) then I dont have to re-position that thing by code, so... Is this valid with flour and convexShapes? cause, I wouldn't have to jot down the positions of all those cubes right?

Well you don't have to. But personally I would because it's more neater, but I don't think it makes much of a difference to PhysX.