贴贴代码,看懂别人的代码也是一项好技能。

来源:互联网 发布:php 支付码 编辑:程序博客网 时间:2024/06/15 14:30


// Test1_3_P16.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "../include/GL/freeglut.h"static GLfloat spin = 0.0;void init(void){glClearColor(0.0,0.0,0.0,0.0);glShadeModel(GL_FLAT);}void display(void){glClear(GL_COLOR_BUFFER_BIT);glPushMatrix();glRotatef(spin,0.0,0.0,1.0);glColor3f(1.0,1.0,1.0);glRectf(-25.0,-25.0,25.0,25.0);glPopMatrix();glutSwapBuffers();}void spinDisplay(){spin = spin+0.1;if (spin>360.0){spin = spin -360.0;}glutPostRedisplay();}void reshape(int w,int h){glViewport(0,0,static_cast<GLsizei>(w),static_cast<GLsizei>(h));glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(-50.0,50.0,-50.0,50.0,-1.0,1.0);//我没有看到这个具体计算?待续。求教  看链接2glMatrixMode(GL_MODELVIEW);glLoadIdentity();}void mouse(int button,int state,int x,int y){switch (button){case GLUT_LEFT_BUTTON:if (state==GLUT_DOWN){glutIdleFunc(spinDisplay);}break;case GLUT_RIGHT_BUTTON:if (state==GLUT_DOWN){glutIdleFunc(NULL);}break;case GLUT_MIDDLE_BUTTON:break;default:break;}}int _tmain(int argc, char* argv[]){glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);glutInitWindowSize(250,250);glutInitWindowPosition(100,100);glutCreateWindow("Test_1_3_double");init();glutDisplayFunc(display);glutReshapeFunc(reshape);//我以为窗口变形才调用,实际上不止。。。glutMouseFunc(mouse);glutMainLoop();return 0;}





glOrtho(-50.0,50.0,-50.0,50.0,-1.0,1.0);//我没有看到这个具体计算?待续。求教  看链接2
分别对应(左,右,下,上,近,远),所以正确的坐标应该是:glOrtho(-50.0,50.0,-50.0,50.0,1.0,-1.0);但是我的图形是2D的,所以没什么问题。







下面是转载内容。

链接2:点击打开链接



转载:点击打开链接1

glRotatef(GLfloat angle,GLfloat x,GLfloat y,GLfloat z)

glRotatef(45,1,0,0)

物體如何旋转?想象:从 坐标(0,0,0)即原点,引出一条线到(1,0,0),用右手握住这条线,这时,你会问,如何握?右手大拇指指向 (0,0,0)至(1,0,0)的方向 才握。另外四个手指的弯曲指向 即是物体旋转方向。

0 0
原创粉丝点击