11 มิถุนายน 2553

ทดลองฉายภาพจากโปรเจ็คเตอร์ลงบนภาพ 3 มิติ

ทดลองฉายภาพจากโปรเจ็คเตอร์ลงบนภาพ 3 มิติ

จัดองค์ประกอบการทดลองดังนี้
ระยะระหว่างกล่องถึงprojector 110 ซม.
พารามิเตอร์ของ projector คือ
    fovy =33.5
    อัตราส่วน 4/3
    อยู่ห่างจากวัตถุ 190 ซม.
   

ได้ sourc code ดังนี้
#include <GL/glut.h>
void init(void)
{
    //glEnable (GL_DEPTH_TEST); //enable the depth testing
 //   glEnable (GL_LIGHTING); //enable the lighting
 //   glEnable (GL_LIGHT0); //enable LIGHT0, our Diffuse Light
 //   glShadeModel (GL_SMOOTH); //set the shader to smooth shader
    
    glClearColor (0.0, 0.0, 0.0, 0.0);

    glShadeModel (GL_FLAT);
    


    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective(33.5, 4.0/3.0, 140.0, 190);

}
void cube (void) {
    float i;
    for (
i=0;i<50;i++)
    {
    glTranslated(1, 0, 1);
    glPushMatrix();
    glutSolidCube(2); //draw the cube
    glPopMatrix();
    }
}
void display(void)
{
        glMatrixMode(GL_MODELVIEW);
    glLoadIdentity ();
    gluLookAt
    (
        0.0, 0.0, 190.0,/* camera */
        0.0, 0.0, 0.0,    /* lens towards */
        0.0, 1.0, 0.0   /* up-vector */
    );
    glClear (GL_COLOR_BUFFER_BIT);

    glPolygonMode(GL_FRONT,GL_FILL);
    glPolygonMode(GL_BACK, GL_LINE);
 
    glColor3f (1.0, 0., 0.);
    glutWireSphere(1, 32, 32);
   
    glColor3f (1.0, 1.0, 1.0);
    glRotatef(45.0, 0.0, 1.0, 0.0);
    glutWireCube (50);

    //glTranslatef(0., 0., 10.);
    glutWireSphere(10, 32, 32);
               /* drawing Cube */
    //cube();
    //glutSwapBuffers(); //swap the buffers

    glFlush ();
}

void reshape (int w, int h)
{
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode (GL_MODELVIEW);
}

void keyboard (unsigned char key, int x, int y) {
    /*
    * Press ESC Key
    */
    if (key==27)
    {
    glutLeaveGameMode(); //set the resolution how it was
    exit(0); //quit the program
    }
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    //glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    //glutInitDisplayMode  (GLUT_DOUBLE  | GLUT_DEPTH);
    /*
    * the settings for fullscreen mode
    */
    //glutGameModeString( "1024x768:32@75" );
    /*
    * set glut to fullscreen using the settings in the line above
    */
    //glutEnterGameMode();
    /*
    * Seting Screen Position
    */
    glutInitWindowPosition (0, 0);
    glutInitWindowSize (800, 600);
    glutCreateWindow (argv[0]);
    glutFullScreen();

    init ();

    glutDisplayFunc (display); //use the display function to draw everything
    /*
    * update any variables in display,
    * display can be changed to anyhing, as long as you move the
    * variables to be updated, in this case, angle++;
    * glutIdleFunc (display);
    */
    glutIdleFunc (display);
    glutReshapeFunc (reshape);
    glutKeyboardFunc (keyboard);
    glutMainLoop();

    return 0;
}

ติดตั้งอุปกรณ์การทดลองดังภาพ


ภาพที่ฉายลงบนวัตถุจริง ซึ่งมีการเหลี่อมเพียงเล็กน้อยเท่านั้น

ไม่มีความคิดเห็น: