Login  Register

Re: Rotate an opengl shape as box2d body rotates

Posted by bobbyrne01 on Apr 11, 2014; 10:43am
URL: https://forum.jogamp.org/Rotate-an-opengl-shape-as-box2d-body-rotates-tp4032158p4032164.html

It returned angle in radians, so i converted to degrees and it works now ..

    gLDrawable.getGL().getGL2().glTranslatef(this.body.getPosition().x, this.body.getPosition().y, -6.0f);
    gLDrawable.getGL().getGL2().glRotated(Math.toDegrees(this.body.getAngle()), 0, 0, 1);
    gLDrawable.getGL().getGL2().glBegin(GL2.GL_QUADS);
    gLDrawable.getGL().getGL2().glTexCoord2f(0.0f, 0.0f);
    gLDrawable.getGL().getGL2().glVertex3f(-this.width, -this.height, 0.0f);
    gLDrawable.getGL().getGL2().glTexCoord2f(0.0f, 1.0f);
    gLDrawable.getGL().getGL2().glVertex3f(-this.width, this.height, 0.0f);
    gLDrawable.getGL().getGL2().glTexCoord2f(1.0f, 1.0f);
    gLDrawable.getGL().getGL2().glVertex3f(this.width, this.height, 0.0f);
    gLDrawable.getGL().getGL2().glTexCoord2f(1.0f, 0.0f);
    gLDrawable.getGL().getGL2().glVertex3f(this.width, -this.height, 0.0f);
    gLDrawable.getGL().getGL2().glEnd();
    gLDrawable.getGL().getGL2().glFlush();