Author Topic: LUA & Physx  (Read 5489 times)

0 Members and 1 Guest are viewing this topic.

shadow

  • Capo Regime
  • ***
  • Posts: 353
LUA & Physx
« on: January 16, 2008, 01:28:51 AM »
Hello,
I have an issue with a small Physix demo.
The aim is to be able to generate large sets of dominos with LUA scripting, and to use Physx with them.
Here is my scene :
Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<hyperion version="1.0">

<!--
+++++++++++++++++++++++++++++++++++++++[ SCENE ]
-->

<scene name="hypergraph_41" display_fps="TRUE" show_ref_grid="TRUE" vsync="FALSE" nx_physics_simulation="TRUE" nx_collision_detection="TRUE">
<window_size width="1024" height="768" />
<background_color r="0.0" g="0.0" b="0.0" />
<global_ambient_light r="0.2" g="0.2" b="0.2" />
</scene>

<!--
+++++++++++++++++++++++++++++++++++++++[ CAMERAS ]
-->
<camera name="myCamera" fov="70.0" active="TRUE" navigation_mode="FLY" >
       
<position x="0.0" y="900.0" z="2050.0" />
<lookat x="0.0" y="0.0" z="0.0" />
</camera>


<!--
+++++++++++++++++++++++++++++++++++++++[ DYNAMIC LIGHTS ]
-->
<light name="light_01" type="OMNI" render="TRUE" >
<position x="0.0" y="40.0" z="0.0" />
<ambient r="0.2" g="0.2" b="0.2" a="1.0" />
<diffuse r="0.9" g="0.9" b="0.9" a="1.0" />
<specular r="0.9" g="0.4" b="0.4" a="1.0" />
</light>


<!--
+++++++++++++++++++++++++++++++++++++++[ TEXTURES ]
-->


<!--
+++++++++++++++++++++++++++++++++++++++[ MATERIALS ]
-->
<material name="myMaterial" >
<ambient r="0.85" g="0.5" b="0.5" a="1.0" />
<diffuse r="0.8" g="1.0" b="0.3.0" a="1.0" />
<specular r="1.0" g="1.0" b="1.0" a="1.0" exp="60.0" />
</material>

<!--
+++++++++++++++++++++++++++++++++++++++[ MESHS ]
-->
<mesh name="box01" shape_type="BOX" render="TRUE"
  lighting="TRUE" back_face_culling="FALSE" polygon_mode="SOLID" nx_add_to_physics_engine="TRUE">  

<box width="5.0" height="30.0" depth="10.0" w_segs="10" h_segs="10" d_segs="10" />
<attach_material name="myMaterial" />
<position x="0.0" y="50.0" z="0.0" />
</mesh>
<!--
+++++++++++++++++++++++++++++++++++++++[ SCRIPTS ]
-->
<script name="init_scene" run_mode="EXECUTE_ONCE" >
<raw_data>
<![CDATA[
clone_id = -1;

for j=0,10 do

z = -100.0 + j*20.0;

for i=0,10 do
clone_id = HYP_Object.Clone("box01");
x = -100.0 + i*20.0;
HYP_Object.SetRenderState( clone_id, 1);
HYP_Object.SetLightingState( clone_id, 1 );
HYP_Object.SetTexturingState( clone_id, 1 );
HYP_Object.RemoveSeam( clone_id );
HYP_Object.SetVBOState( clone_id, 1 );
HYP_Object.SetPosition( clone_id, x, 15.0, z);
HYP_Nx_Physics.AddBoxActorToScene(clone_id,2,10,5);

end
end
]]>
</raw_data>
</script>

</hyperion>

The issue is in the script : if I use the "HYP_Nx_Physics.AddBoxActorToScene(clone_id,2,10,5);" line, I get this :



Basically, a huge explosion. :mrgreen:
Unfortunately that's not what I try to do. I just want my set of dominos (a square, just like in code sample 41) to be added in the physics engine.
Any idea of what is wrong ? And why ?
3D, photos panoramiques : http://www.shadows.fr

JeGX

  • Global Moderator
  • Capo Crimine
  • *****
  • Posts: 2357
    • oZone3D.Net
Re: LUA & Physx
« Reply #1 on: January 16, 2008, 08:57:24 AM »
With PhysX, you have to use PhysX's functions to set position, orientation:
Code: [Select]
clone_id = -1;

for j=0,10 do

z = -100.0 + j*20.0;

for i=0,10 do
clone_id = HYP_Object.Clone("box01");
x = -100.0 + i*20.0;
HYP_Object.SetRenderState( clone_id, 1);
HYP_Object.SetLightingState( clone_id, 1 );
HYP_Object.SetTexturingState( clone_id, 1 );
HYP_Object.RemoveSeam( clone_id );
HYP_Object.SetVBOState( clone_id, 1 );

-- HYP_Object.SetPosition( clone_id, x, 15.0, z);

ACTOR_DYNAMIC = 2;
density = 10.0;
mass = 5.0;
HYP_Nx_Physics.AddBoxActorToScene(clone_id, ACTOR_KINEMATIC, density, mass );
HYP_Nx_Physics.SetActorGlobalPosition( clone_id, x, 15.0, z );

end
end

With a closer camera:



Good luck with the rest  ;)



shadow

  • Capo Regime
  • ***
  • Posts: 353
Re: LUA & Physx
« Reply #2 on: January 16, 2008, 09:49:00 AM »
Thanks a lot !
If I understand well :
-everytime I change anything with Demoniak (position, for example), I must change it in Physx too.
-I suppose that this :
Quote
         ACTOR_DYNAMIC = 2;
         density = 10.0;
         mass = 5.0;
         HYP_Nx_Physics.AddBoxActorToScene(clone_id, ACTOR_KINEMATIC, density, mass );
would be equivalent to
HYP_Nx_Physics.AddBoxActorToScene(clone_id, 2,10,5);  ?
3D, photos panoramiques : http://www.shadows.fr

shadow

  • Capo Regime
  • ***
  • Posts: 353
Re: LUA & Physx
« Reply #3 on: January 16, 2008, 02:45:55 PM »
By the way, I have another issue... My dominos are very slow when they fall, even if I set gravity to ( 0, -250, 0 )   (with stronger gravity it works but dominos begin to "shake"  even at the beginning of the demo).
Do you have any clue about this, and, maybe, some good values for gravity, density and mass ?

3D, photos panoramiques : http://www.shadows.fr

JeGX

  • Global Moderator
  • Capo Crimine
  • *****
  • Posts: 2357
    • oZone3D.Net
Re: LUA & Physx
« Reply #4 on: January 17, 2008, 08:55:00 AM »
-everytime I change anything with Demoniak (position, for example), I must change it in Physx too.
No, forget the HYP_Object.SetPosition() when you deal with PhysX objects. Use only HYP_Nx_Physics.SetActorGlobalPosition(). When you use the physics engine, PhysX takes the control over the objects (position and rotation).


would be equivalent to
HYP_Nx_Physics.AddBoxActorToScene(clone_id, 2,10,5);  ?
Yes mate

JeGX

  • Global Moderator
  • Capo Crimine
  • *****
  • Posts: 2357
    • oZone3D.Net
Re: LUA & Physx
« Reply #5 on: January 17, 2008, 08:59:13 AM »
By the way, I have another issue... My dominos are very slow when they fall, even if I set gravity to ( 0, -250, 0 )   (with stronger gravity it works but dominos begin to "shake"  even at the beginning of the demo).
Do you have any clue about this, and, maybe, some good values for gravity, density and mass ?

Yes it's a problem with PhysX. I added the HYP_Nx_Physics.SetTimingParams() function to tweak this behavor. Play with it and with gravity/density up to find good values.

shadow

  • Capo Regime
  • ***
  • Posts: 353
Re: LUA & Physx
« Reply #6 on: January 17, 2008, 09:47:07 AM »
Ok, Thanks !  :med:
I will take a look at this.
3D, photos panoramiques : http://www.shadows.fr

JeGX

  • Global Moderator
  • Capo Crimine
  • *****
  • Posts: 2357
    • oZone3D.Net
Re: LUA & Physx
« Reply #7 on: January 17, 2008, 09:50:29 AM »

shadow

  • Capo Regime
  • ***
  • Posts: 353
Re: LUA & Physx
« Reply #8 on: January 17, 2008, 01:39:43 PM »
Quote
HYP_Nx_Physics.SetTimingParams(max_time_step,
max_iter,
is_timestep_fixed,
timestep_to_use);

    * max_time_step - [REAL] - Maximum size of a substep - .
    * max_iter - [INTEGER] - Maximum number of iterations to divide a timestep into.
    * is_timestep_fixed - [INTEGER] - use(1) or not use(0) a fixed time step.
    * timestep_to_use - [REAL] - time step to use when is_timestep_fixed=1.
Well...Looks like this is a little bit too complicated for me.  :neutral:
Do you have any example of "good" parameters ?
What about the units ? "size" , "time step"...  are they in seconds, ms, other ?
3D, photos panoramiques : http://www.shadows.fr

JeGX

  • Global Moderator
  • Capo Crimine
  • *****
  • Posts: 2357
    • oZone3D.Net
Re: LUA & Physx
« Reply #9 on: January 17, 2008, 04:44:50 PM »
Well...Looks like this is a little bit too complicated for me.  :neutral:
Ageia PhysX is complicated  :mrgreen:
This function is a direct wrapper of the one available in PhysX SDK.
Tweak the gravity, the density/mass, the timer params and... the object size.
Currently I didn't found yet the right params to get a nice simulation.

shadow

  • Capo Regime
  • ***
  • Posts: 353
Re: LUA & Physx
« Reply #10 on: January 17, 2008, 05:30:34 PM »
Quote
Currently I didn't found yet the right params to get a nice simulation.
Neither did I... :(

Quote
and... the object size
I had the same thought at first, then I asked myself what was the purpose of the density parameter.
If we set both mass and density, we also "set the size" of the object, don't we ?   :confused:
3D, photos panoramiques : http://www.shadows.fr