30 พฤษภาคม 2553

เตรียมการสอนถ่ายภาพ วิดีโอและการจัดกา...

เตรียมการสอนถ่ายภาพ วิดีโอและการจัดการภาพถ่ายเบี้องต้น
ก่อนอื่นต้องกล่าวยินดีต้อนรับ FRA รุ่นที่ 8
ที่จะมาเรียน ป.โททางด้านวิทยาการหุ่นยนต์และระบบอัตโนมัติ ที่ ฟีโบ้นะครับ
คิดอีกทีก็เศร้านี่เราแก่ไปอีกแล้วเหรอเนี่ย ปี2 แล้ว

Download ไฟล์ MindMap ได้ที่นี่ http://www.upload-thai.com/download.php?id=5192bb7de80c541244a10b41a8cc0805

OpenGL สร้างสีเหลี่ยมที่ไม่ใช่ลูกบาศก์

OpenGL สร้างสีเหลี่ยมที่ไม่ใช่ลูกบาศก์ จากสีีเหลี่มลูกบาศก์
โดยปกติ glut จะมีฟังก์ชัน glutWireCube สำหรับสร้างลูกบาศก์ได้อย่างง่ายดายในคำสั่งเดียว
แต่หากเราต้องการสร้างรูปที่ไม่เป็นลูกบาศก์โดยวิธีดังเดิม
โดยการกำหนดจุด มุมแต่ละจุดของแล้วสร้างเป็น polygon มาต่อกัน
ดูได้จาก GL Manager ของ อ.สยาม
void CGLMgrDlg::Box(GLdouble x0, GLdouble x1, GLdouble y0, GLdouble y1,
        GLdouble z0, GLdouble z1, GLenum type)
{
    static GLdouble n[6][3] = {
        {-1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0},
        {0.0, -1.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, -1.0}
    };
    static GLint faces[6][4] = {
        { 0, 1, 2, 3 }, { 3, 2, 6, 7 }, { 7, 6, 5, 4 },
        { 4, 5, 1, 0 }, { 5, 6, 2, 1 }, { 7, 4, 0, 3 }
    };
    GLdouble v[8][3], tmp;
    GLint i;

    if (x0 > x1) {
        tmp = x0; x0 = x1; x1 = tmp;
    }
    if (y0 > y1) {
        tmp = y0; y0 = y1; y1 = tmp;
    }
    if (z0 > z1) {
        tmp = z0; z0 = z1; z1 = tmp;
    }
    v[0][0] = v[1][0] = v[2][0] = v[3][0] = x0;
    v[4][0] = v[5][0] = v[6][0] = v[7][0] = x1;
    v[0][1] = v[1][1] = v[4][1] = v[5][1] = y0;
    v[2][1] = v[3][1] = v[6][1] = v[7][1] = y1;
    v[0][2] = v[3][2] = v[4][2] = v[7][2] = z0;
    v[1][2] = v[2][2] = v[5][2] = v[6][2] = z1;

    for (i = 0; i < 6; i++) {
        glBegin(type);
        glNormal3dv(&n[i][0]);
        glVertex3dv(&v[faces[i][0]][0]);
        glNormal3dv(&n[i][0]);
        glVertex3dv(&v[faces[i][1]][0]);
        glNormal3dv(&n[i][0]);
        glVertex3dv(&v[faces[i][2]][0]);
        glNormal3dv(&n[i][0]);
        glVertex3dv(&v[faces[i][3]][0]);
        glEnd();
    }
}


void CGLMgrDlg::SolidBox(double width, double height, double depth)
{
    Box(-width/(GLdouble)2., width/(GLdouble)2., -height/(GLdouble)2., height/(GLdouble)2.,-depth/(GLdouble)2., depth/(GLdouble)2., GL_QUADS);
}



ซึ่งจะวุ่นวายมากแม้จะทำ Wrapper Class ให้ใช้งานได้ง่ายๆ แล้วก็ตามนอกจากนี้หากต้องการสร้างรูปแบบ Wire
เพื่อใช้ test เส้นขอบของวัตถุฉายลงมาตรงวัตถุหรือไม่ หากเป็นรูปทรงสี่เหลี่ยม ต้องสร้าง Line ให้ครบทุกด้านเลยทีเดียวซึ่งยุ่งยากมาก

แต่ในที่นี้เราจะใช้เทคนิคสร้างลูกบาศก์ขึ้นมาขนาด 1x1x1 แล้วใช้การขยายขนาดโดย Transformation Matrix
เช่นเราอยากให้สีเหลี่ยมขนาด กว้าง x ยาว x ลึก  เช่น 50 x 25 x 25
เราจะขยายมุมของกล่องโดยใช้ฟังกชัน glScaled
    /*
    * Wire Box + Scale
    */
    glPushMatrix ();
        glColor3f (1.0, 1.0, 1.0);
        glScaled (50.0, 25.0, 25.0);
        glutWireCube (1);
    glPopMatrix ();
ทำให้เขียนโปรแกรมได้ง่ายขึ้นมากโดยคำสั่งแค่ 2 บรรทัด ก็สามารถสร้างกล่องขนาดต่างๆกันได้มากมาย

เรนเดอร์ OpenGL ให้เป็น Full Screen ด...

เรนเดอร์ OpenGL ให้เป็น Full Screen ด้วย Game Mode
ในการจะฉายภาพลงไปในโดยใช้โปรเจ็คเตอร์เพื่อให้ภาพทั้งหมดเต็มพื้นที่ของโปรเจ็คเตอร์
เราจึงต้อง เรนเดอร์ภาพแบบเต็มจอ ซึ่งมีขั้นตอนมากกว่าการสั่งตำแหน่งจุดเริ่มต้นของ Viewport และขนาดไม่ได้
แต่ยังต้องเซ็ทเรื่องการใช้ Buffer และการสั่งเข้าหรือออกโหมด Full Screen ผ่านทาง Keyboard อีกด้วย
#include <GL/glut.h>
#include <math.h>

//angle of rotation
float xpos = 0, ypos = 0, zpos = 0, xrot = 0, yrot = 90, angle=0.0;

void init (void)
{
    glEnable (GL_DEPTH_TEST); //enable the depth testing
    /*
    * if enable lighting wire geometry some line don't display
    */
    //glEnable (GL_LIGHTING); //enable the lighting
    glEnable (GL_LIGHT0); //enable LIGHT0, our Diffuse Light
    glShadeModel (GL_FLAT); //set the shader to smooth shader

}


void drawing()
{
    /*
    * Wire Box
    */
    glPushMatrix ();
        glColor3f (1.0, 1.0, 1.0);
        glRotatef (45, 0.0, 1.0, 0.0);
        glutWireCube (50);
    glPopMatrix ();

}
void display (void)
{
    glClearColor (0.0,0.0,0.0,1.0); //clear the screen to black
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the color buffer and the depth buffer
    glLoadIdentity();  
    /*
    * camera position, x,y,z, looking at x,y,z, Up Positions of the camera
    */
    gluLookAt
    (
        0.0, 0.0, 190.0,/* camera */
        0.0, 0.0, 0.0,    /* lens towards */
        0.0, 1.0, 0.0   /* up-vector */
    );
    /*
    * start drawing object
    */
    drawing(); //call the cube drawing function

    glutSwapBuffers(); //swap the buffers
    angle+=0.1; //increase the angle
}


void reshape (int w, int h) {
    glViewport (0, 0, (GLsizei)w, (GLsizei)h); //set the viewport to the current window specifications
    /*
    * Projector Projection Parameter
    */
    glMatrixMode (GL_PROJECTION); //set the matrix to projection
    glLoadIdentity ();
    gluPerspective (33.5, 4.0/3.0, 140.0, 300); //set the perspective (angle of sight, width, height, , depth)

    glMatrixMode (GL_MODELVIEW); //set the matrix back to model

    
    
}

void keyboard (unsigned char key, int x, int y) {
    if (key=='q')
    {
    xrot += 1;
    if (xrot >360) xrot -= 360;
    }

    if (key=='z')
    {
    xrot -= 1;
    if (xrot < -360) xrot += 360;
    }

    if (key=='w')
    {
    float xrotrad, yrotrad;
    yrotrad = (yrot / 180 * 3.141592654f);
    xrotrad = (xrot / 180 * 3.141592654f);
    xpos += float(sin(yrotrad)) ;
    zpos -= float(cos(yrotrad)) ;
    ypos -= float(sin(xrotrad)) ;
    }

    if (key=='s')
    {
    float xrotrad, yrotrad;
    yrotrad = (yrot / 180 * 3.141592654f);
    xrotrad = (xrot / 180 * 3.141592654f);
    xpos -= float(sin(yrotrad));
    zpos += float(cos(yrotrad)) ;
    ypos += float(sin(xrotrad));
    }

    if (key=='d')
    {
    yrot += 1;
    if (yrot >360) yrot -= 360;
    }

    if (key=='a')
    {
    yrot -= 1;
    if (yrot < -360)yrot += 360;
    }
    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_DOUBLE | GLUT_DEPTH); //set the display to Double buffer, with depth
    glutGameModeString( "1024x768:32@30" ); //the settings for fullscreen mode
    glutEnterGameMode(); //set glut to fullscreen using the settings in the line above
    init (); //call the init function
    glutDisplayFunc (display); //use the display function to draw everything
    glutIdleFunc (display); //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++;
    glutReshapeFunc (reshape); //reshape the window accordingly

    glutKeyboardFunc (keyboard); //check the keyboard
    glutMainLoop (); //call the main loop
    return 0;
}

โดยมีฟังก์ชันสำคัญๆดังนี้
glutInitDisplayMode (GLUT_DOUBLE | GLUT_DEPTH); //set the display to Double buffer, with depth
ใช้สร้าง Buffer แบบคู่สำหรับเก็บภาพที่เกิดจากการเรนเดอร์

glutGameModeString( "1024x768:32@30" ); //the settings for fullscreen mode
เช็ทหน้าจอให้ใช้ความละเอียด 1024 x 768 สี 32 บิต อัตราการรีเฟตที่ 30 เฟรมต่อวินาที
ต้องเรียกฟังกชัน glutGameModeString ก่อน glutEnterGameMode

glutEnterGameMode(); //set glut to fullscreen using the settings in the line above
เริ่มเข้าสู่ภาพเต็มจอตามที่ได้เซ็ทไว้ในฟังก์ชัน glutGameModeString

glutLeaveGameMode(); //set the resolution how it was
ออกจากภาพเต็มจอ เมื่อเราส่ังภาพเต็มจอจะไม่มีกรอบวินโดวส์ทำให้ไม่มีปุ่ม กากบาท มุมขวาบนที่ใช้ปิดโปรแกรม
ทำให้เราต้องเพิ่งพาการใช้งาน Keyboard เมื่อกดคีย์ Esc ค่อยไปเรียกฟังก์ชันนี้อีกที

glutKeyboardFunc (keyboard); //check the keyboard
กำหนดให้เมื่อกดคีย์บอร์ดแล้วไปเรียกฟังก์ชัน keyboard();

ภายในฟังก์ชันคียบอร์ด ให้ทำการดักจับคีย์ที่ผู้ใช้กด
void keyboard (unsigned char key, int x, int y) {
    if (key==27)
    {
    glutLeaveGameMode(); //set the resolution how it was
    exit(0); //quit the program
    }
}
เช็คคีย์ว่าเท่ากับ 27 หรือไม่ซึ่งตรงกับ ASCII ของปุ่ม ESC

glutSwapBuffers(); //swap the buffers
เมื่อมีการวาดภาพต้องมีการสลับบัฟเฟอร์ระหว่าง Back ไปหา Front Buffer
หากฟังก์ชันนี้มีการทำ glFlush ให้อยู่แล้วไม่ต้องใช้หลายครั้งให้ซ้ำซ้อน

Airnergy แปลงสัญญาณ Wi-Fi เป็นพลังงาน...

Airnergy แปลงสัญญาณ Wi-Fi เป็นพลังงานแบตฯ
ผมได้ผ่านไปเห็นผลิตภัณฑ์ตัวหนึ่งที่ใช้พลังงานจาก Wireless Lan
ซึ่งถ้าเป็นในมหาวิทยาลัย
ก็คงมีครอบคลุมทั่วทั้งตึกแน่นอน วิธีใช้ก็ง่ายๆ เพียงนำตัวมันไปวางไว้ที่ ที่มีสัญญาณ Wireless
มันก็จะชาร์ตไฟเข้าไปข้างในแบตเตอร์รี่มือถือทันที

ดูวีดีโอได้ใน ที่มา http://gadget.siamphone.com/news-01911.html

จากเดิมนั้นผมก็ได้ติดตามเรื่องการส่งพลังงานแบบไร้สายพาพอสมควร
อ่านได้จาก http://en.wikipedia.org/wiki/Wireless_energy_transfer
ช่วงนึงมีความคิดจะทำโรงงานผลิตไฟฟ้าจากโซลาร์เซลล์ ที่ลอบอยู่นอกโลกแล้วส่งพลังงานที่ได้กลับมา
ในรูปของคลื่นไมโครเวฟ
หรือจะเป็น ของ MIT Media Lab
นอกจากนี้ก็มีมือถือของ Plam ที่ชารต์โดยแค่เอาไปวางไว้ใกล้ๆเครื่องชาร์ตเท่านั้น

22 พฤษภาคม 2553

แจกฟรีนิตยสารคู่หูเดินทาง ของบริษัท บขส. จำกัด

โหลดนิตยสารฉบับเก่าได้ฟรีในรูปแบบ E-book ที่
http://www.busbuddythailand.com/Back Issue.html
เป็นนิตยสารแนวท่องเที่ยว ภาพุถ่ายสวยๆน่าติดตาม

08 พฤษภาคม 2553

ถ่านอัลคาไลน์ สามารถชารต์ได้แล้ว


ถ่านอัลคาไลน์ สามารถชารต์ได้แล้ว
ได้ความรู้เรื่องนี้มาจากรายการ แบไต๋ไฮเทค ที่มีพี่หนุ่ยเป็นพิธีกรแนวกวนๆ
ที่เราเห็นแล้วรู้สึกว่าเทห์ มาก
เครื่องชารต์ Environ Power ราคา 1150 บาท
เป็นสินค้าที่ขึ้น อันดับ 1 ในเว็บ tarad.com

เค้าโฆษณาว่า ถ่านอัลคาไลน์ที่ชารต์แล้วสามารถใช้งานได้ถึง 20 ครั้งด้วยกัน
ดูวีดีโอโฆษณาได้ที่
http://www.youtube.com/watch?v=EYndAlO2oqk&feature=player_embedded#at=109


และวีดีโอที่ออกในรายการแบไต๋ ไฮเทค
http://www.youtube.com/watch?v=HbZGqhckWpI&feature=player_embedded#!















03 พฤษภาคม 2553

Parameter ของโปรเจคเตอร์ ที่ใช้ในการฉ...

Parameter ของโปรเจคเตอร์ ที่ใช้ในการฉายลงบน 3d Geometry
โปรเจคเตอร์รุ่น EPSON EB-S6
โดย Workspace ประมาณ 1 ตารางเมตร


โดยมีความสูง ประมาณ 82 Cm

และความกว้าง 108.5 cm

มุมในการฉายด้านกว้าง 43.5 องศา
มุมในการฉายด้านสูง 33.5 องศา

ข้อสังเกตุ
   โปรเจคเตอร์ที่วางอยู่บนพื้นระนาบมีมุมเอียงขึ้นเล็กน้อย คือไม่ได้ฉายแสงออกไปตรงๆ แต่มีการเบนลำแสงเล็กน้อย คาดว่าเนื่องมาจาก เพื่อให้เวลาฉายภาพ ภาพจะอยู่สูงกว่าโต๊ะที่วาง

มุมแหนจากพื้นระนาบ 12.5 องศา

จากพารามิเตอร์ทั้งหมดที่วัดได้มีผลอย่างมากในการกำหนด Viewing Volume