Dante-666 / bouncy-ball

hello world game for g3d development and learning
1 stars 0 forks source link

Incorporate physics in the game. #5

Closed Dante-666 closed 4 years ago

Dante-666 commented 4 years ago

I've decided to use PhysX as it has some already cool effects which we can use like cloth simulations. Also I took this up to show a use case of modelling via UML and this sounds like a good idea.

Dante-666 commented 4 years ago

I'm conflicted now on which library to use now and PhysX 5.0 seems great but throws a bunch of EULA at me. It's not even released now and the current version is NVIDIA PhysX SDK 4.1 released in 2019. 2020 is already ended and I guess Nvidia focused too much on the hardware this year. This needs to be dropped because I am smelling a lot of scam purely because of the license.

1) https://github.com/GPUOpen-Effects/FEMFX FEMFX which supports deformable meshes and takes care of #4 but apparently it doesn't work well with Rigid Bodies at the moment but AMD has plans to support that in the future(may never happen). Since the license is MIT and not going to change in the near future as AMD is owning the market now. Maybe PhysX and Nvidia will also budge and may create option 3)

2) https://github.com/bulletphysics/bullet3 There is always our trusty bulletphysics by MIT. This will always be in development but we won't be seeing all the FEMFX goodness, just plain old rigid bodies.

3) If Nvidia doesn't persist to be a dick PhysX

4) Explore some deep learning based physics engine

There are some Physics Abstraction Layers(PAL) out there but none of them are in active development. My idea is to design one that defines abstract methods for getting the job done and there would be plenty of design opportunities out there.

Limitations of an individual engine, https://www.youtube.com/watch?&v=IYClvszCCPA After watching this talk, I came to the understanding that a "Physics" engine is nothing but a solver algorithm(or a set of solver algorithms working in tandem) that take in a state and time evolve it to predict the next state which obey a certain set of constraints.

  1. Making two independent solvers(libraries) work in tandem is next to impossible as the math won't allow it. What I mean by that is you can't make Rigid bodies collide with a Deformable body and expect things to work without some major syncronization issues or undefined behaviors. FEMFX talks about this and maybe rigid bodies would be a part of FEMFX soon.
  2. Understanding 1. begs the question that how does fluid simulations work then? By this logic none of the simulations should be able to interact with a rigid body and thus work properly. Or we have a set of 2 collision surfaces, both for rigid interactions and fluid flow. This is the only way I can logically make sense of this since they seem to be separate problem classes cannot be handled by a single solver alone.
  3. PAL should be able to resolve and abstract these issues. I will work on the design and update this section.
  4. As I delve deeper into this, it seems more to me that we need this as a separate project. Or maybe bouncy-ball can serve that purpose. The application itself will be a demonstration of the PAL layer which will be the proprietary work that attempts to integrate all worthwile and "OpenSource" solvers in a universal format. OpenSource and monetizable licenses are what we should go after for.
Dante-666 commented 4 years ago
    /** 
        \brief Physical simulation callback.

        The default implementation animates the model pose (by calling
        simulatePose()) and moves the frame() along m_frameSpline.

        If setFrame() has been called since the last onSimulation call, then
        the previous frame is not updated to the current frame by onSimulation
        because it assumes some external logic is maintaining the Entity's position.

        \param deltaTime The change in time since the previous call to onSimulation. Two values are special:
         0 means that simulation is paused and time should not advance.  As much as possible, all state should
         remain unchanged. For example, anything computed by differentials such as velocity should remain at its
         current value (rather than becoming infinite!).  In particular, this allows freeze-frame rendering of 
         motion blur.  The default implementation leaves m_previousFrame and the previous pose unchanged.
         A value of nan() means that the time has been changed discontinuously, for example, by
         Scene::setTime.  In this case, all state should update to the new absolute time and differentials can
         be approximated as zero (or whatever other result is reasonable for this Entity).

         \sa Scene::setOrder
     */
    virtual void onSimulation(SimTime absoluteTime, SimTime deltaTime);

This looks interesting. By default G3D provides some methods that may be used to update an object by an external engine.

Dante-666 commented 4 years ago

Wao, plenty of design challenges have popped up and need to experiment with the libraries to come up with more information on how to do it with most efficiency and extensibility. I see little problems with rigid bodies and even soft bodies but deformable bodies which seem to manipulate the meshes looks challenging at first glance. Experiment with updating the state with a tightly coupled bullet engine and check if the deltaTimes are working fine and position updates check out. Then find a way to comminucate the pose information back to the engine. My guess is that the game engine should control the simulation by providing a deltaTime to stepSimulation(dT) in this case. How to communicate the pose back to the renderer with extensibility is one gray area which will become more clear with a simple implementation.

Dante-666 commented 4 years ago

G3D does a great fixed time simulation, I've created a RigidEntity by inheriting from VisibleEntity and overridden the method

onSimulation(SimTime absoluteTime, SimTime deltaTime)

which almost always result in a deltaTime=0.0166666675 and can be used for the physics simulation. Next step would be to just create a physicsWorld inside the RigidEntity and call some methods and see how they interact with gravity. Possibly take the simulation updates out and update the RigidEntity and make it fall with gravity for now. Next step would be to make a less mediocre version of the thing with external physics object and all the RigidEntities interacting with it. If there can be some callback based implementation, that would be really great. Looks like some major piece of work for now, but interesting.

Dante-666 commented 4 years ago

Closing this with a extendible version of PhysicsAbstractionLayer which is open to use any libraries for G3D Objects