问题是:我的三角形不旋转!为什么?我做错了什么?
这是代码:
主文件
#include <iostream>
#include <GL/glut.h>
#include <GL/gl.h>
#include "myobject.h"
using namespace std;
Vector3f position = Vector3f(0.0f,0.0f,0.0f);
myobject *Ob = new myobject(position);
float _angle = 0.1f;
void render(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
_angle += 0.4f;
glPushMatrix();
glTranslatef (0.0f, -0.0f, -0.2f);
glRotatef(_angle, 1.0f, 0.0f, 0.0f);
Ob->draw();
glPopMatrix();
glutSwapBuffers();
}
void init(){
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(640, 480);
glutCreateWindow("test");
glutDisplayFunc(render);
glutMainLoop();
}
int main(int argc, char * argv[]) {
glutInit(&argc, argv);
init();
return 0;
}
我的对象.cpp
#include <iostream>
#include <GL/glut.h>
#include <GL/gl.h>
#include "myobject.h"
using namespace std;
myobject::myobject(Vector3f pos)
{
_position = pos;
_size = 0.0f;
}
myobject::~myobject()
{
}
void myobject::draw()
{
glBegin(GL_TRIANGLES);
glColor3f(0.2f,0.2f,0.5f);
glVertex3f( 0.0f, 0.0f, 0.5f);
glVertex3f(-1.0f,-0.5f, 0.0f);
glVertex3f( 0.5f,-0.5f, 0.0f);
glEnd();
}