Re: Creating objects with simple drawing methods of JOGL
Posted by
jmaasing on
Dec 31, 2015; 5:37pm
URL: https://forum.jogamp.org/Creating-objects-with-simple-drawing-methods-of-JOGL-tp4035938p4035961.html
Lawa wrote
I don't think you understood what I'm trying to do here ..
for example lets say I have this in display() method :
gl.glBegin(GL2.GL_POLYGON);
gl.glVertex2i(0,0);
gl.glVertex2i(0,100);
gl.glVertex2i(100,100);
gl.glVertex2i(100,0);
gl.glEnd();
basically this is a rectangular shape (or any other shape) created using the basic methods of JOGL how do I implement physics engine to this particular shape ?
class MyGameEntity {
int[] vertices = [0,0 0,100, 100,100, 100,0] ;
}
...
class RenderableThing {
MyGameEntity drawThis ;
...
glVertex2i(drawThis.vertices[0], drawThis.vertices[1]) ;
glVertex2i(drawThis.vertices[2], drawThis.vertices[3]) ;
}
class PhysicsThing {
MyGameEntity makeThisPhysical ;
public void addToPhysics(World world) {
Body b = new Body(new BodyFixture(new Rectangle(//calculate the width & height from the makeThisPhysical object))) ;
world.add(b) ;
See how one class handles drawing, the other handles adding a physics object. Both are using the basic polygon data defined in MyGameEntity. You know what data you send to OpenGL - use the same data as input to drive the physics engine.