void handle_simple_display(void) { Vec3 focus = camera->get_focalvector(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(camera->aperture, camera->screenwidth/(double) camera->screenheight, 0.1, 10000.0); glViewport(0, 0, camera->screenwidth, camera->screenheight); // Create the model gluLookAt(camera->vpos.x, camera->vpos.y, camera->vpos.z, focus.x, focus.y, focus.z, camera->vup.x, camera->vup.y, camera->vup.z); glShadeModel(GL_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_DEPTH_TEST); glEnable(GL_LINE_SMOOTH); CreateWorld(); if (windowdump || movierecord) { WindowDump(camera->screenwidth, camera->screenheight); windowdump = 0; } glutSwapBuffers(); }
void cart_pole_loop() { int i; static int m = 0; static int cycle = 0; // counter // static int writeFrameCnt = 1200; // # of frames to write static int writeFrameCnt = 500; // # of frames to write static int writtenFrameCnt = 0; // # of frames written so far // static int writePer = 110; // period of writing static int writePer = 2; // period of writing //25Hz // extern int writeImg; glutPostRedisplay(); simulation_loop();//------------------------------------------------------------- CALL CONTROLLER //#if 0 /*************************************/ /* Wait for visualization */ /*************************************/ req.tv_sec = 0; req.tv_nsec = 1000; memcpy(&rem, &req,sizeof(req)); memset(&req,0,sizeof(req)); nanosleep(&req,&rem); //#endif if (writeImg){ if (cycle % writePer == 0){ WindowDump(0,0,Width,Height); writtenFrameCnt++; if (writtenFrameCnt == writeFrameCnt){ writeImg = 0; printf("Written %d frames.\n", writtenFrameCnt); } } cycle ++; } }
/* This is the basic display callback routine It creates the geometry, lighting, and viewing position In this case it rotates the camera around the scene */ void Display(void) { XYZ r,eyepos; double dist,ratio,radians,scale,wd2,ndfl; double left,right,top,bottom; /* Do we need to recreate the list ? */ if (geometrydirty != NOTDIRTY) { MakeGeometry(); geometrydirty = NOTDIRTY; } /* Clip to avoid extreme stereo */ near = 0.1; far = 1000; if (stereo) near = camera.focallength / 5; /* Misc stuff */ ratio = camera.screenwidth / (double)camera.screenheight; radians = DTOR * camera.aperture / 2; wd2 = near * tan(radians); ndfl = near / camera.focallength; /* Clear the buffers */ glDrawBuffer(GL_BACK_LEFT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if (stereo) { glDrawBuffer(GL_BACK_RIGHT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } if (stereo) { /* Derive the two eye positions */ CROSSPROD(camera.vd,camera.vu,r); Normalise(&r); r.x *= camera.eyesep / 2.0; r.y *= camera.eyesep / 2.0; r.z *= camera.eyesep / 2.0; eyepos = VectorAdd(camera.vp,r); glMatrixMode(GL_PROJECTION); glLoadIdentity(); left = - ratio * wd2 - 0.5 * camera.eyesep * ndfl; right = ratio * wd2 - 0.5 * camera.eyesep * ndfl; top = wd2; bottom = - wd2; glFrustum(left,right,bottom,top,near,far); glMatrixMode(GL_MODELVIEW); glDrawBuffer(GL_BACK_RIGHT); glLoadIdentity(); gluLookAt(eyepos.x,eyepos.y,eyepos.z, eyepos.x + camera.vd.x, eyepos.y + camera.vd.y, eyepos.z + camera.vd.z, camera.vu.x,camera.vu.y,camera.vu.z); MakeLighting(); glCallList(1); eyepos = VectorSub(r,camera.vp); glMatrixMode(GL_PROJECTION); glLoadIdentity(); left = - ratio * wd2 + 0.5 * camera.eyesep * ndfl; right = ratio * wd2 + 0.5 * camera.eyesep * ndfl; top = wd2; bottom = - wd2; glFrustum(left,right,bottom,top,near,far); glMatrixMode(GL_MODELVIEW); glDrawBuffer(GL_BACK_LEFT); glLoadIdentity(); gluLookAt(eyepos.x,eyepos.y,eyepos.z, eyepos.x + camera.vd.x, eyepos.y + camera.vd.y, eyepos.z + camera.vd.z, camera.vu.x,camera.vu.y,camera.vu.z); MakeLighting(); glCallList(1); } else { glMatrixMode(GL_PROJECTION); glLoadIdentity(); left = - ratio * wd2; right = ratio * wd2; top = wd2; bottom = - wd2; glFrustum(left,right,bottom,top,near,far); glMatrixMode(GL_MODELVIEW); glDrawBuffer(GL_BACK_LEFT); glLoadIdentity(); gluLookAt(camera.vp.x,camera.vp.y,camera.vp.z, camera.vp.x + camera.vd.x, camera.vp.y + camera.vd.y, camera.vp.z + camera.vd.z, camera.vu.x,camera.vu.y,camera.vu.z); MakeLighting(); glCallList(1); } /* glFlush(); This isn't necessary for double buffers */ glutSwapBuffers(); if (record || windowdump) { WindowDump(camera.screenwidth,camera.screenheight,stereo); windowdump = FALSE; } if (demomode && iterationdepth < 1000) { iterationdepth++; geometrydirty = ADDONE; if (debug) fprintf(stderr,"Iteration: %d\n",iterationdepth); } }
void handle_display(void) { Vec3 focus = camera->get_focalvector(); Vec3 right = camera->get_sidevector(); glDrawBuffer(GL_BACK); glReadBuffer(GL_BACK); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(camera->aperture, camera->screenwidth/(double) camera->screenheight, 0.1, 10000.0); glViewport(0, 0, camera->screenwidth, camera->screenheight); // Left eye filter glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); switch (glassestype) { case REDBLUE: case REDGREEN: case REDCYAN: glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE); break; case BLUERED: glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE); break; case GREENRED: glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE); break; case CYANRED: glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE); break; } // Create the model glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(camera->vpos.x - right.x, camera->vpos.y - right.y, camera->vpos.z - right.z, focus.x, focus.y, focus.z, camera->vup.x, camera->vup.y, camera->vup.z); CreateWorld(); //glFlush(); //glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); glDrawBuffer(GL_BACK); glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(camera->aperture, camera->screenwidth/(double) camera->screenheight, 0.1, 10000.0); glViewport(0, 0, camera->screenwidth, camera->screenheight); // Right eye filter glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); switch (glassestype) { case REDBLUE: glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_TRUE); break; case REDGREEN: glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_TRUE); break; case REDCYAN: glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE); break; case BLUERED: case GREENRED: case CYANRED: glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_TRUE); break; } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(camera->vpos.x + right.x, camera->vpos.y + right.y, camera->vpos.z + right.z, focus.x, focus.y, focus.z, camera->vup.x, camera->vup.y, camera->vup.z); CreateWorld(); glFlush(); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); if (windowdump || movierecord) { WindowDump(camera->screenwidth, camera->screenheight); windowdump = 0; } glutSwapBuffers(); }