Login  Register

Re: Creating objects with simple drawing methods of JOGL

Posted by jmaasing on Dec 31, 2015; 9:16am
URL: https://forum.jogamp.org/Creating-objects-with-simple-drawing-methods-of-JOGL-tp4035938p4035953.html

You should not design you application/game in such a way. The best way in my opinion is to design your application so that physics and visuals are separate from the game logic. That means you will have some game entity that has variables and logic only related to game play and that have nothing to do with visuals or physics.

The game entity is then used to create a physics body that is added to dyn4J, the same game entity is then also used to create something that is used for rendering (for example triangle mesh and shader). So you end up with separate classes dealing with different aspects of the game.

In my game I use a lot of game entities, they have a polygon definition using just plain math objects. The polygon definition is used to create Dyn4J bodies (usually polygons but also circles and so on). I put a reference in the "user data" part of Dyn4J-body to the game entity and I let the game entity have a reference to the Dyn4J body.
When for example Dyn4J detects a collision I have a collision listener, it looks at the Dyn4J body and retrieves the game entity reference from the user data to inform about collisions. When the game entity decides it should be removed from physics it has a reference to the Dyn4J body and can remove that from physics.

This works out really well and separates concerns. In this way you can for example change the rendering without changing anything in the physics and game logic. Especially if you later want to leave the deprecated OpenGL calls and move to the current generation using shaders.