# 用glut库实现旋转，平移，缩放

glTranslatef(3.0,2.0f,0.0f);

theta,vx,vy,vz指定这个旋转物体的矩阵，物体将绕着(0,0,0)到(x,y,z)的直线以逆时针旋转，参数 theta表示旋转的角度。取正时为逆时针。对于二维情形，tx=0.0 ty=0.0 tz=1.0.

glRotatef(30.0,0.0,0.0,1.0);

把当前矩阵和一个表示缩放物体的

glScalef(1.0,2.0,1.0);

#include<GL/glut.h>
#include "math.h"

void init(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);//投影视图
gluOrtho2D(-5.0,5.0,-5.0,5.0);//设置显示的范围是X:-5.0~5.0,Y:-5.0~5.0
glMatrixMode(GL_MODELVIEW);//设置当前操作的矩阵为“模型视图矩阵”
}

void drawDiamond(void)//绘制中心在原点的菱形，一个顶角60度。
{
glBegin(GL_POLYGON);//顶点指定需要按逆时针方向
glVertex2f(0.0f,-1.0f);//下点
glVertex2f(sqrt(3),0.0f);//右点
glVertex2f(0.0f,1.0f);//上点
glVertex2f(-sqrt(3),0.0f);//左点
glEnd();
}

void myDraw(void)
{
glClear(GL_COLOR_BUFFER_BIT);//清空

glPushMatrix();
glScalef(1.0,1.0,1.0);
glRotatef(-90.0,0.0,0.0,1.0);//绕（0,0,1）点顺时针旋转90度
glTranslatef(-sqrt(3),0.0f,0.0f);
glColor3f(1.0,0.0,0.0);
drawDiamond();//上方的红色棱形
glPopMatrix();

glPushMatrix();
glScalef(1.0,1.0,1.0);
glRotatef(30,0.0,0.0,1.0);
glTranslatef(-sqrt(3),0.0,0.0);
glColor3f(0.0,0.0,1.0);
drawDiamond();//右下蓝色矩形
glPopMatrix();

glPushMatrix();
glScalef(1.0,1.0,1.0);
glRotatef(-30,0.0,0.0,1.0);//逆时针旋转30角度
glTranslatef(sqrt(3),0.0,0.0f);
glColor3f(0.0,1.0,0.0);
drawDiamond();//左下绿色矩形
glPopMatrix();

glFlush();
}

void main(int argc,char* *argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowPosition(0,0);
glutInitWindowSize(600,600);
glutCreateWindow("几何变换函数");
init();
glutDisplayFunc(myDraw);
glutMainLoop();
}

glScalef(1.0,1.0,1.0);
glRotatef(30,0.0,0.0,1.0);
glTranslatef(-sqrt(3),0.0,0.0);