Create arm with shapes

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Create arm with shapes

adam
I am trying to create a basic arm using triangles, i give a set of angles for the joins between the arms.
My only problem is how do i get the triangles to align properly. At the moment i move the first angle to the correct angle and then when i go to move the second, it is out of position as obviously it hasnt been rotated at the same angle as the previous triangle

At the moment i have to manually set the translation to position them properly, there must be an easier way?

public void drawArm(GL gl, int offset, float angle0, float angle1, float angle2)
    {
        gl.glPushMatrix();
        gl.glColor3f(255, 0, 0);
        drawTriangle(gl, 100,100,100,120,100+offset,110);
        gl.glPopMatrix();
       
        gl.glPushMatrix();
       
        gl.glTranslatef(200, 110, 0);
        gl.glRotatef(angle1, 0f, 0f, 1f);
        gl.glTranslatef(0, 0, 0);
        gl.glColor3f(0, 255, 0);
        drawTriangle(gl, 0,0,0,20,0+offset,10);
        gl.glPopMatrix();
       
        gl.glPushMatrix();
        gl.glTranslatef(280, 200, 0);
        gl.glRotatef(angle2, 0f, 0f, 1f);
        gl.glTranslatef(0, 0, 0);
        gl.glColor3f(0, 0, 255);
        drawTriangle(gl, 0,0,0,20,0+offset,10);
        gl.glPopMatrix();
       
       
    }