我把旋转函数放在哪里
where do i put in my rotate function
#include "std_lib_facilities.h"
#include <GL/glut.h>
static float dx=0.0;
static float dz=10;
static float points[2];
static float cx=0.0;
static float cy=0.0;
static float cz=0.0;
static float spin=0.0;
static float rotation=1.0;
int readObject()
{
ifstream inputFile("spikeBall.ogl");
if(!inputFile)
{
cerr << "cannot open file spikeBall.ogl" << endl;
return -1;
}
int count = 0;
float x,y,z;
do{
inputFile >> count;
glBegin(GL_POLYGON);
for(int i=0;i<count;i++)
{
inputFile >> x >> y >> z;
glVertex3f(((x/5)+cx),((y/5)+cy),((z/5)+cz));
}
glEnd();
}while(count!=0);
inputFile.close();
}
void init(void)
{
glClearColor(0.0,0.0,0.0,0.0);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glLoadIdentity();
gluLookAt (0,0,20, 0.0,0.0,0.0, 0.0,1.0,0.0);
glPushMatrix();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
GLfloat aMaterial[]={0.1745,0.01175,0.01175,1.0};
GLfloat bMaterial[]={0.61424,0.04136,0.04136,1.0};
GLfloat cMaterial[]={0.727811,0.626959,0.626959,1.0};
GLfloat dMaterial=40;
glMaterialfv(GL_FRONT,GL_AMBIENT,aMaterial);
glMaterialfv(GL_FRONT,GL_DIFFUSE,bMaterial);
glMaterialfv(GL_FRONT,GL_SPECULAR,cMaterial);
glMaterialf(GL_FRONT,GL_SHININESS,dMaterial);
readObject();
glRotatef(spin,0.0,1.0,0.0);
glPopMatrix();
glFlush();
}
void idleFunc(void)
{
spin+=rotation;
if(spin>360.0)
{
spin-=360.0;
}
cz+=0.1;
if(cz==20)
{
srand((unsigned int) time(NULL));
for(int i=0;i<2;i++)
{
points[i] = (rand()%20)-10;
}
cx = points[0];
cy = points[1];
cz = 0;
GLfloat lightPos[] = {cx,cy,(cz+2),1.0};
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
std::cout << "cx:" << cx;
std::cout << "cy:" << cy;
std::cout << "cz:" << cz;
}
else
{
}
glutPostRedisplay();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0,20.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(300,300);
glutInitWindowPosition(0,0);
glutCreateWindow("3ds Max loader");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
init();
glutIdleFunc(idleFunc);
glutMainLoop();
return(0);
}
目前它只是向前移动,我想让它也旋转,但无论我把它放在哪里,它要么不旋转,要么让球体看起来像刚刚爆炸(就像我把它放在glEnd()之后)
我将创建一个更新循环,您可以调用所有的逻辑函数,并创建一个新的单独的Rotate()函数,然后调用它。我通常遵循的游戏编程格式是:
main()
{
init();
while(gameOn)
{
update();
draw();
}
}
init()
{
//create textures, etc.
}
update()
{
//do logic
}
draw()
{
//display on screen after update
}
相关文章:
- 在哪里放置我的函数?进入我的母语 Gui 还是进入我的演示者?
- 此递归函数的每次迭代的值存储在哪里?
- 在哪里放置函数声明?
- _Pass_fn:构造函数在哪里?
- 标准在哪里指定类中定义的函数是内联的?
- 当我们在C++中创建类的对象时,为成员函数分配的内存在哪里?
- 在哪里调用主函数(dev c ++)
- 为什么访问器函数必须是常量?漏洞在哪里?
- 如果对象是通过 new 创建的,则成员函数的局部变量在哪里创建?
- 虚拟函数在哪里使用 vpointer to vtable 来解析方法调用,非虚拟方法存储在哪里以及如何解析它们?
- 此模板函数在哪里生成?可以通过g++编译,但不能在Visual Studio中编译
- C++ - 函数中的局部指针变量具有什么类型的存储持续时间以及它们存储在哪里?
- 我在哪里可以从C 中的单链接列表中创建此函数到搜索元素时犯了错误
- C NT2库文档在哪里,并且它具有默认的爆米花函数
- 在哪里放置 PRIVATE 嵌套(内部)类的非成员函数定义
- C++谷歌测试在哪里放置测试夹具构造函数定义
- 如果我在我的函数中返回一个类,它存储在哪里
- c 中的uint()函数在哪里
- Arduino中的串行函数在哪里定义
- 在哪里可以找到哪些函数名称代表?C++