I started another thread using the global variable “height” to control a force output. The performance is very bad–vibration happens. If I just use win32’s GDI to demo the 2-D picture instead of RenderSence(), the performance is very good. Why? Because of the time-consuming RenderSence()?
RenderScene() will be called in
WM_PAINT:
RenderScene();
And in
WM_TIMER://here timer is 20ms
Invalidate(hwnd,NULL,1);
void RenderScene(void)
{
float fZ,bZ;
GLdouble baserad=25;
GLdouble toprad=25;
GLint slices=16;
GLint piece=4;
GLfloat angle, x, y;
GLUquadricObj* quadr;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
fZ = 30;//100.0f;
bZ = -30;//-100.0f;
glPushMatrix();
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
// Set material color, Red
glRGB(192, 192, 192);
glBegin(GL_QUADS);
// Pointing straight out Z
glNormal3f(0.0f, 0.0f, 1.0f);
glVertex3f(50.0f, 50.0f, fZ);
glVertex3f(-50.0f,50.0f,fZ);
glVertex3f(-50.0f,-50.0f,fZ);
glVertex3f(50.0f,-50.0f,fZ);
glNormal3f(0.0f, 1.0f, 0.0f);
glVertex3f(-50.0f,50.0f,fZ);
glVertex3f(50.0f, 50.0f, fZ);
glVertex3f(50.0f, 50.0f, bZ);
glVertex3f(-50.0f,50.0f,bZ);
// Bottom section
glNormal3f(0.0f,-1.0f,0.0f);
glVertex3f(-50.0f,-50.0f,fZ);
glVertex3f(-50.0f,-50.0f,bZ);
glVertex3f(50.0f, -50.0f,bZ);
glVertex3f(50.0f, -50.0f,fZ);
// Left section
glNormal3f(1.0f, 0.0f, 0.0f);
glVertex3f(50.0f, 50.0f,fZ);
glVertex3f(50.0f, -50.0f,fZ);
glVertex3f(50.0f, -50.0f,bZ);
glVertex3f(50.0f, 50.0f, bZ);
// Right Section
glNormal3f(-1.0f, 0.0f,0.0f);
glVertex3f(-50.0f, 50.0f,fZ);
glVertex3f(-50.0f, 50.0f,bZ);
glVertex3f(-50.0f,-50.0f,bZ);
glVertex3f(-50.0f,-50.0f,fZ);
glEnd();
glFrontFace(GL_CW); glBegin(GL_QUADS);
glNormal3f(0.0f,0.0f,-1.0f);
glVertex3f(50.0f, 50.0f, bZ);
glVertex3f(-50.0f,50.0f,bZ);
glVertex3f(-50.0f,-50.0f,bZ);
glVertex3f(50.0f,-50.0f,bZ);
glEnd();
glRGB(255, 0, 0);
glBegin(GL_TRIANGLE_FAN);
glVertex3f(0.0,0.0,height);
for(angle=0.0f; angle<(2.01*PI);angle+=(PI/slices))
{
x=baserad*sin(angle);
y=baserad*cos(angle);
glVertex3f(x,y,height);
}
glEnd();
glFrontFace(GL_CCW); quadr=gluNewQuadric();
gluCylinder(quadr, baserad, toprad, height, slices, piece);
// Restore the matrix state
glPopMatrix();
// Flush drawing commands
glFlush();
}