//以下是我的程序,但是我想让画出的图形按规律旋转,但是它始终不变啊?怎么回事?// s.cpp
// Demonstrates a simple animated rectangle program with GLUT
// OpenGL SuperBible, 3rd Edition
// Richard S. Wright Jr.
// [email protected]#include "../../shared/gltools.h" // OpenGL toolkit#include "stdafx.h"
#include "s.h"
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <GL/glut.h>
int i,j;
float n;
float t;
float tex[K];
float x,y,z,angle;
float dx,dy,dz,dangle;
float x00=0.0f;
float y00=0.0f;
float z00=0.0f;
float x01=0.5f;
float y01=0.0f;
float angle00=0;void myInit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(250.0f,1.0f,1.0f);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5.0,5.0,-5.0,5.0,-5.0,5.0); }
void myDisplay1(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.2f,0.5f,0.3f);
glutSolidTeapot(200);
glColor3f(0.5f,0.5f,0.5f);
glutSolidTeapot(2);
glRecti(0,0,1,1);
glFlush();
}int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("my first attempt");
for (i=0;i<2;i++)
{
t=i/100;
x=t*t+2*t+0.03;
y=t+0.02;
z=t*t*3+0.2;
angle=i*90;
//计算增量
dx=x-x00;
dy=y-y00;
dz=z-z00;
dangle=angle-angle00; glTranslatef(dx,dy,dz);//平移
glRotatef(dangle,0.0f,0.0f,1.0f);//旋转
glutDisplayFunc(myDisplay1);
myInit();
for (j=0;j<400000000;j++)
{
}
} glutMainLoop();
}
// Demonstrates a simple animated rectangle program with GLUT
// OpenGL SuperBible, 3rd Edition
// Richard S. Wright Jr.
// [email protected]#include "../../shared/gltools.h" // OpenGL toolkit#include "stdafx.h"
#include "s.h"
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <GL/glut.h>
int i,j;
float n;
float t;
float tex[K];
float x,y,z,angle;
float dx,dy,dz,dangle;
float x00=0.0f;
float y00=0.0f;
float z00=0.0f;
float x01=0.5f;
float y01=0.0f;
float angle00=0;void myInit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(250.0f,1.0f,1.0f);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5.0,5.0,-5.0,5.0,-5.0,5.0); }
void myDisplay1(void){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.2f,0.5f,0.3f);
glutSolidTeapot(200);
glColor3f(0.5f,0.5f,0.5f);
glutSolidTeapot(2);
glRecti(0,0,1,1);
glFlush();
}int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("my first attempt");
for (i=0;i<2;i++)
{
t=i/100;
x=t*t+2*t+0.03;
y=t+0.02;
z=t*t*3+0.2;
angle=i*90;
//计算增量
dx=x-x00;
dy=y-y00;
dz=z-z00;
dangle=angle-angle00; glTranslatef(dx,dy,dz);//平移
glRotatef(dangle,0.0f,0.0f,1.0f);//旋转
glutDisplayFunc(myDisplay1);
myInit();
for (j=0;j<400000000;j++)
{
}
} glutMainLoop();
}
解决方案 »
- sendmessage如何彻底关闭窗口
- 当TAB数量达到8个时客户区会变大
- 调用dll函数时出现Debug Assertion Faild?
- VC中调用VB生成的DLL(java调用VB的DLL)
- 入门第一个问题:VC编译的程序,必须带MFC40.DLL才能运行吗?
- 如何给类的函数创建线程?
- 文件和系统都是小端,怎么直接取出数据放入内存里?
- 我编了一个CMyCTreeCtrl,派生自CTreeCtrl,有一个问题请教,我将把该类送给你
- .msi文件是不是结构上比.exe更复杂呢?
- 150分:"error LNK2001" 是咋回事!!!
- com方式操作word,怎样用AddPolyline函数画封闭多边形?
- InstallShield(IS脚本工程)我新建了窗体叫Dlg_CustomStart,但是不知道如何goto到这个窗体上
不过你确定
glRotatef(dangle,0.0f,0.0f,1.0f);//旋转
这句执行到了并且dangle的值有变化么?
循环改大点试试看,有可能是已经旋转了但是看不出来效果
// s.cpp
// Demonstrates a simple animated rectangle program with GLUT
// OpenGL SuperBible, 3rd Edition
// Richard S. Wright Jr.
// [email protected]#include "../../shared/gltools.h" // OpenGL toolkit#include "stdafx.h"
#include "s.h"
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <GL/glut.h>
int i=0,j=0;
float n=0;
float m=0;
float x,y,z,angle;
float dx,dy,dz,dangle;
float x00=0;
float y00=0;
float z00=0;
float angle00=0;void myInit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(250.0f,1.0f,1.0f);
glPointSize(1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5.0,5.0,-5.0,5.0,-5.0,5.0);
}void myDisplay1(void)
{
glTranslatef(dx,dy,dz);//平移
glRotatef(dangle,0.0f,1.0f,1.0f);//旋转
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.2f,0.5f,0.3f);
glutSolidTeapot(200);
glColor3f(0.5f,0.5f,0.5f);
glutSolidTeapot(2);
glRecti(0,0,1,1);
glFlush();
}int main(int argc,char**argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(100,150);
glutCreateWindow("my first attempt");
for (i=0;i<3;i++)
{
m=i*0.1;
x=m*m+2*m+0.03;
y=m+0.02;
z=m*m*3+0.2;
angle=i*27;
//计算增量
dx=x-x00;
dy=y-y00;
dz=z-z00;
dangle=angle-angle00;
printf("%f\t%f\t%f\t%f\n",dx,dy,dz,dangle);
//画模型或者载入模型
glutDisplayFunc(myDisplay1);
myInit();
//延时
for (j=0;j<40000000;j++)
{
}
} glutMainLoop();
}
你参考一下吧int nAngle = 0;void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(nAngle, 1.,0.,0.);
glScalef (0.5, 0.5, 0.5);
glColor3f(0.5f,0.5f,0.5f);
glutSolidTeapot(2);
nAngle += 2; glPopMatrix();
glFlush();
}void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective (45.0, (GLdouble)w/(GLdouble)h, 3.0, 8.0); glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef (0.0, 0.0, -5.0);
}int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (/*GLUT_SINGLE | */GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow(argv[0]);
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutIdleFunc(display);
glutMainLoop();
return 0;
}