2022年6月6日 星期一

Week16-陳俊銘

                                                       

OldAngle[i]=NewAngle[i];
        fscanf(fin,"%f",&NewAngle[i]);


void myInterpolate(float alpha)
{
    for(int i=0;i<20;i++)
    {
    angle[i]=alpha*NewAngle[i]+(1-alpha)*OldAngle[i];
    printf("%.2f",angle[i]);
    }
    printf("\n");
    glutPostRedisplay();
}





void timer(int t)
{
    float alpha =(t%50)/50.0;
    if(t%50==0)myRead();
    myInterpolate(alpha);
    glutTimerFunc(33,timer,t+1);
}


eye是看出去的
center是看的中心
up是攝影機的旋轉



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


沒有留言:

張貼留言