2022年3月22日 星期二

week05

                                              主題:移動/旋轉/縮放/矩陣/鍵盤+滑鼠

#include <GL/glut.h>
#include <stdio.h>
float x=150,y=150,z=0,scale=1.0;
int oldX=0,oldY=0;
void display()
{
    glClearColor(0.5,0.5,0.5,1);///R,G,B,A 其中A半透明功能,目前沒開
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
        glTranslatef((x-150)/150.0,-(y-150)/150.0,z);
        glScalef(scale,scale,scale);///都縮放成scale倍
        glColor3f(1,1,0);///黃色的
        glutSolidTeapot(0.3);///茶壺
    glPopMatrix();
    glutSwapBuffers();
}
void keyboard(unsigned char key,int x,int y)
{
}
void mouse(int button,int state,int mouseX,int mouseY)
{
    oldX=mouseX;oldY=mouseY;
}
void motion(int mouseX,int mouseY)
{
    if(mouseX-oldX>0)scale*=1.01;
    if(mouseX-oldX<0)scale*=0.99;
   ///x+= (mouseX-oldX);y+=(mouseY-oldY);
    oldX=mouseX; oldY=mouseY;
    display();
}
int main(int argc,char** argv)
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH);
    glutCreateWindow("week05");

    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMotionFunc(motion);
    glutMainLoop();
}








沒有留言:

張貼留言

VERY BEAUTIFUL, VERY POWERFUL

一.     一樣先安裝且設定好freeglut,OpecCV, 開啟CodeBlocks建立新專案 week11_gundam,                 把 MyGundam.zip下載解壓縮後的data資料夾放到freeglut/bin裡面 把week09_openc...