Issue overlaying two arms for robot manipulator

Hello anybody,

I have a (hopefully) very simple question to ask.

I have an assignment were I have to build a 3 joint (2 arm) robot manipulator, I’ve done all coding and all the maths etc works fine. I’m using fltk to provide all the opengl libraries I need. Each arm is drawn into a seperate window.

When I try to view the final product in an opengl window I can only see 1 arm (not both, due to seperate windows… because each arm has to have different glrotates and gltranslates performed on it).

If anyone can help me to ‘overlay’ these two windows ontop of each other it would be great. I assume this is relatively simple stuff, my opengl knowledge is very low.

Thanks in advance

Joel.

p.s I have attached my cpp code (in txt format) for your viewing pleasure…

Me again,

I tried to click on my txt file, thats handy.

If you need the cpp i can email…

thanks again

Joel

instead of rendering into two separate windows, either render both arms to the same window (saving the modelview matrix between rendering each arm), or use a separate viewport to split the screen (like you see on Playstation with multiplayers)

Thanks,

I have got both windows running in the kind of playstation mode at the moment, i’m pretty novice but my code firstly transforms an identity matrix then draws…

void arm_box::draw()
{
//
if (!valid()) {
glLoadIdentity();
glViewport(0,0,w(),h());
glEnable(GL_DEPTH_TEST|GL_STENCIL_TEST);

glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
glDepthRange(0.0f, 1.0f);

glFrustum(-1,1,-1,1,2,10000);
glTranslatef(0,0,-10);
gl_font(FL_HELVETICA_BOLD, 16 );

}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0,0,(baseHeight));
glRotatef(rotBase,0,0,1);
glRotatef(swivPoint,0,1,0);
glRotatef(rotPoint,0,0,1);
glTranslatef(0,0,-(baseHeight));
drawarm();
glPopMatrix();
}

with drawing done here…

void drawbase() {

glBegin(GL_LINE_LOOP);
glColor3ub(0,0,255); v3f(v0); v3f(v1); v3f(v2); v3f(v3); //BOTTOM OF BASE
glEnd();

glBegin(GL_LINE_LOOP);
glColor3ub(0,0,255); v3f(v4); v3f(v5); v3f(v6); v3f(v7); //TOP OF BASE
glEnd();

… and so on for all the vertices, how do i save the ‘modelview’ matrix in this case?

p.s the main code continuously calls redraw()

use either glpushmatrix with glpopmatrix, or use your own matrix (16 floats) to save the modelview matrix:

glGetFloatv(GL_MODELVIEW_MATRIX, @save)

and you can restore with

glLoadMatrixf (@save)

Using the latter is more flexible, So the program flow may go something like this:

DrawLoop:
Save modelview
draw arm in viewport 1
restore modelview
draw arm 2 in viewport 2
restore modelview

…what this leads upto is the fact that you should already know what the modelview matrix should be at anyone time. After all you did create it. Therefore you can be more efficient by not having to save the modelview matrix at the start of every frame if you use a variable to track what the value is supposed to be. Instead every frame begins with a glLoadMatrix. In this way you are applying your ‘camera’ to the scene.

The next thing is to remove the glloadidentity from the start of the arm_box::draw method.
This resets the ‘camera’ back to the default. That’s OK as long as you always want to draw to a known and fixed position right infront of the camera. However, should you wish to add a moving camera to the scene and pan,zoom and strafe then this will not work. The draw code should just use the camera as is - ie leave the modelview matrix intact.