2022年6月6日 星期一

week16 內插 攝影機

 1.excel學習內插

t:0 0.1 0.2 .... 1
alpha:0 0.1 0.2 ...1
algle:13......90
內插公式alpha*新的+(1-alpha)*舊的


內插實做



攝影機
打開windows/projection
eye是看出去的
center是看的中心
up是攝影機本身旋轉

如果將畫面拉寬他會變胖

調整aspect可調整長寬比

aspect ratio=寬度/高度

#include<GL/glut.h>

void motion(int x,int y)
{
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt((x-150)/15.0,(y-150)/15.0,3,
              0,0,0,
              0,1,0);
    glutPostRedisplay();
}
 void reshape(int w, int h)
{///aspect ratio
    const float ar = (float) w / (float) h;

    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);///投影,把3D投影到2D
    glLoadIdentity();
    gluPerspective(60,ar,0.1,100);
    //glFrustum(, ar, -1.0, 1.0, 2.0, 100.0);
    ///3D經過轉換到你最後的攝影機

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity() ;
    gluLookAt(0,0,3,0,0,0,0,1,0);
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    //glColor3f(1,1,0);
    glutSolidTeapot(1);
    glutSwapBuffers();
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("week16 camera lookat");



glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutMotionFunc(motion);



glutMainLoop();
}










沒有留言:

張貼留言