Physics Application from scratches

I created an application and I would like to add physics inside.

After few attempts I decided to make an empty application and try it from scratches.

So, first of all :

to use physics do I have to extend SimplePhysicsGame mandatory ?

I tried with BaseGame obtaining physycspace with PhysicsSpace.create()

generating the node as in Lesson1 and updating the scene with physicsSpace.update(interpolation);

but nothing appears on the screen.

Added manually a box outside physic system is correctly rendered, seems like is not enabled physic system in app.

Some ints ?

Thanks to anyone have the patience to support me, leave the address below and I'll send a chcolate bar to anyone :smiley:

elettrozero said:

to use physics do I have to extend SimplePhysicsGame mandatory ?

No, you can use any app.

Even if you create a node with a physics space you still have to add it to some displayed node (e.g. rootNode).
irrisor said:

Even if you create a node with a physics space you still have to add it to some displayed node (e.g. rootNode).


It's what i've done.
Root
  |____ staticPhysicNode
  |____dynamicPhysicNode
  |____standardBox

the standardBox is the only thing rendered.

Physics Nodes don't have a graphical representation unless you add a model to them.  For example you could attach a box:



Root

  |staticPhysicsNode

  |                  |
Box

  |___dynamicPhysicsNode

  |                  |___Box

  |___standardBox



… then you'll need to call generatePhysicsGeometry() to have the node's representation in the physics engine take the shape of the box/model you added.



If you want to just see the physics you can add this to your rendering method: PhysicsDebugger.drawPhysics(PhysicsSpace ps, Renderer r )

As written I've replicated the Lesson1 tutorial :


scene          = new Node("Scene graph node");
      
      physicsSpace = PhysicsSpace.create();

Cloning from Lessonn2 magically the elements are displayed.

But now it seems that no collision is managed.

Do have I to add an event handler myself ?

My understandings is that a PhysicsBox is a model which only exists in the physics world… it is used to calculate physics, but isn't rendered.



Try attaching a box to your dynamic and static nodes, rather than using createBox (which would make a physics box)



Also, if you do this you'll need to call generatePhysicsGeometry after you attach the box.



I think that just attaching physicsboxes can come in handy if you want to make an invisible wall, or a similar object