OpenGl中模拟走动效果

模拟走动效果;
1、相应VK_UP按键消息,并作出如下处理
    if (keys[VK_UP])
    {

     xpos -= (float)sin(heading*piover180) * 0.05f;
     zpos -= (float)cos(heading*piover180) * 0.05f;
     if (walkbiasangle >= 359.0f)
     {
      walkbiasangle = 0.0f;
     }
     else
     {
      walkbiasangle+= 10;
     }
     walkbias = (float)sin(walkbiasangle * piover180)/20.0f;
    }
2、在Draw函数中画图之前作如下处理
 GLfloat xtrans = -xpos;
 GLfloat ztrans = -zpos;
 GLfloat ytrans = -walkbias-0.25f;
 glRotatef(lookupdown,1.0f,0.0f,0.0f);
注:各变量的定义如下:
 const float piover180 = 0.0174532925f;
 float heading;
 float xpos;
 float zpos;

 GLfloat yrot;    // Y Rotation
 GLfloat walkbias = 0;
 GLfloat walkbiasangle = 0; 

你可能感兴趣的:(OpenGL)