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;
}

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


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

10 มิถุนายน 2553

Real-Time Markerless 3D Tracking

http://www.youtube.com/watch?v=_Dln257k2Sc&NR=1

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




30 เมษายน 2553

Coordinate Transformation ใน OpenGL

Coordinate Transformation ใน OpenGL
ใน OpenGl มี Transformation 5 แบบคือ
Transformation
การใช้งาน
Viewing
ใช้เซ็ตตำแหน่งกล้องหรือตา
Modeling
ใช้กับตำแหน่งของวัตถุ
ModelView
อธิบายความสัมพันธ์ระหว่า View กับ Model
Projection
กำหนด Viewing Volume
Viewport
Scales ภาพบนก่อนฉายบนจอ

สามารถแสดงเป็นขั้นตอนดังนี้

Eye Coordinate คือ ไม่ใช่ Coordinateจริงๆ แต่เอาไว้อ้างอิงเพื่อสร้างภาพขึ้นมา โดยการเคลื่อนย้ายวัตถุแต่ละอย่างก็เช่นจะทำการหมุน ก็จะใช้ Eye Coordinate ตัวนี้แหละเป็นตัวอ้างอิง

ภาพการหมุน 45องศาโดยอ้างอิงจากeye coordinate

Viewing Transformation คือ Transformation แรกของ OpenGl ทำหน้าที่ย้ายจุดจาก Coordinate ที่ใช้อยู่ อ้างอิงกับแกนของ Eye Coordinate

Modeling Transformations ใช้สร้าง Model ทำการย่อขยาย เลื่อน หมุน

Projection Transformations ใช้สร้างภาพบนจอจาก Model หรือการแปลงจาก 3 มิติ ให้เหลือ 2 มิติ มีแบบ Orthographic และแบบ Perspective ซึ่งใน Thesis จะใช้แบบ Perspective เท่านั้น คือภาพจะใหญ่เมื่อใกล้ตา และจะเล็กเมื่ออยู่ไกลตา เราควบคุมเมตริซ์นี้โดยการกำหนด Viewing Volume

Viewport Transformations
ใช้ย่อขยายปรับ aspect ratio ของภาพ 2 มิติ ให้เหมาะสมกับขนาดของ Windows ที่แสดงผล จะmap ระหว่าง logical กับจอภาพที่เป็น Physical


เยี่ยมชมศูนย์ศึกษาการพัฒนาอ่าวคุ้งกระเบนอันเนื่องมาจากพระราชดำริจังหวัด จันทบุรี

เยี่ยมชมศูนย์ศึกษาการพัฒนาอ่าวคุ้งกระเบนอันเนื่องมาจากพระราชดำริจังหวัดจันทบุรี

ภาพอ่าวคุ้งกระเบนจาก google maps

สภาพชายหาดได้รับการอนุรักษ์ไว้อย่างดี สังเกตุได้จาก

ปูลมบริเวณชายหาดมีจำนวนมาก จับเล่นได้สบายๆ

เราได้เดินเที่ยวอควอเรี่ยม แม้จะไม่ใหญ่แต่ทางเจ้าหน้าที่บอกว่าพันธ์สัตว์น้ำที่จัดแสดงมีความหลากหลายมากกว่าที่บึงฉวากอีก

ปลาเยอะมากแต่ดันชอบหอยที่เกาะตู้ปลาอยู่

ปลากระเบนตัวนี้เป็นสีสันของงานเลยก็ว่าได้

การให้อาหารกระเบน ค่อนข้างยุ่งยากเพราะมันมีตาอยู่บ้านบน แต่ปลาอยู่ด้านล่าง เค้าเลยต้องเอามาป้อนให้ถึงที่อย่างนี้


หลังจากนั้นไปได้เที่ยวชมป่่าชายเลนต่อ เจ้าหน้าที่บอกว่าเมื่อก่อนเป็นป่าชายเลนเสื่อมโทรม ชาวบ้านเข้าตัดต้นไม้ไปเผาถ่าน
ป่าชายเลนที่เห็นเป็นป่าชายเลที่ปลูกเสริมขึ้นมาใหม่ทั้งหมด ซึ่งจะไม่มีการปลูกเพิ่มอีกแล้วเพราะเพียงพอแล้ว ถ้าหากปลูกเพิ่มจะเป็นการกีดขวางทางเดินของน้ำ จะมีก็แต่การปลูกเสริมเมื่อต้นเก่าตายไปเท่านั้น
ป่าชายเลนที่เห็นก็ดูสมบูรณ์มากมีลิงปีนต้นแสมด้วย

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










29 เมษายน 2553

ลำดับการทำ Transformation ของ Vertex หรือจุด ที่เราสร้างขึ้นใน Op

ลำดับการทำ Transformation ของ Vertex หรือจุด ที่เราสร้างขึ้นใน OpenGL

ซึ่งในการ Set Matrix ในแต่ละขึ้นตอนมีคำสั่งที่เกี่ยวข้องดังนี้
glMatrixMode ใช้เปลี่ยนโหมดเมทริกซ์ทั้ง 4 Mode
glLoadIdentity หลังจากใช้ glMatrixMode สามารถรีเซ็ตค่าเมทริกซ์ให้เป็น Identity ซึ่งจะทำให้ไม่มีผลต่อ Vertex ในโหมดนั้นๆ

เมื่อใช้ 2 คำสั่งก่อนหน้าแล้ว เราสามารถกำหนดค่าในเมตริกซ์โดยใช้คำสั่ง
glLoadMatrix ใช้โหลดเมทริกซ์ที่เราคำนวณเองทั้งหมดลงไปได้เลย
glMultMatrix คูณเมตริซ์ที่ใช้อยู่กับเมตริกซ์ที่ให้ไป เหมาะกับการเอาไปใช้ในการแบ่งหลายๆ ขั้นตอน เช่นเอา Scale คูณ Rotate คูณ Translate ทำให้อ่านง่ายด้วย
 
นอกจากนี้ OpenGL ยังมีคำสั่งเฉพาะของแต่ละโหมด เพื่อปรับค่าเมตริกซ์ เพื่อให้เราไม่ต้องมาคิดคำนวณเอง

glViewport ปรับเมตริกซ์ในโหมด Viewport ปรับ aspect ratio เป็นส่วนใหญ่

glFrustum ปรับเมตริกซ์ในโหมด Perspective ใช้ปรับ Volumn การฉายภาพปรับแทนเลนส์ wide หรือ tele ได้

นอกจากนี้ยังใช้เมตริกซ์คล้าย stack เราสามารถ save Transformation Matrix ที่เราใช้งานอยู่ไว้ได้โดยการ Push เก็บไว้ใน Stack และ Pop Matrix ที่ไม่ใช้ออกไป
glPushMatrix ใช้ save ค่าเก็บไว้ใน matrix
glPopMatrix ใช้ ดึงค่า matrix ที่ save ไว้ก่อนหน้ากลับมาใช้



10 เมษายน 2553

แปลงไฟล์ Fasta ให้อยู่ในรูปแบบ Genbank

แปลงไฟล์ Fasta ให้อยู่ในรูปแบบ Genbank
เขียนโดยใช้ Python นะครับ

ก่อนจะนำไปรัน ให้แก้ตัวแปร 2 ตัวคือ
path คือ Directory ที่ไฟล์อยู่
filename คือ ชื่อไฟล์ ไม่ต้องใส่ .fa
path = "C:\Users\Naymin Suksen\Desktop\\"
filename = "chr15"
f = open(path + filename + ".fa", "r")
g = open(path + filename + ".txt", "w")
f.readline()
text = f.read(10)
count = 1
while text != "" :
    g.write(str(count))
    g.write('\t')
    for i in range(0,6):
        for i in range (0,10):
            text = f.read(1)
            while text == '\n':
                text = f.read(1)
            g.write(text)
        g.write(' ')
    g.write('\n')
    count += 60
    print "count: " + str(count)
f.close()
g.close()
print "Done!!!"