//设置视图与透视投影矩阵 void CCDirector::setMVP(){ setViewport(); CCSize size = m_obWinSizeInPoints; //获得眼睛位置 //float zeye = this->getZEye(); float zeye = m_obWinSizeInPoints.height / 1.1566f; // float zeye = 480.0f / 1.1566f;//算出来是1.1547 不知道哪里算错了 Matrix44 matrixPerspective, matrixLookup; //设置当前矩阵为投影矩阵,对投影矩阵进行操作 mglMatrixMode(KM_GL_PROJECTION); mglLoadIdentity(); // matrixPerspective = mgluPerspective(60.0f/180.0f*M_PI, 640/480.0f, 0.1f, 2*zeye); matrixPerspective = mgluPerspective(60.0f/180.0f*M_PI, size.width/size.height, 0.1f, 2*zeye); mglMultMatrix(&matrixPerspective); //设置观察矩阵 mglMatrixMode(KM_GL_MODELVIEW); mglLoadIdentity(); // matrixLookup = mglLookAt(640.0f/2, 480.0f/2, zeye, 640.0f/2, 480.0f/2, 0.0f, 0, 1, 0.0f); matrixLookup = mglLookAt(size.width/2, size.height/2, zeye, size.width/2, size.height/2, 0.0f, 0.0f, 1.0f, 0.0f); mglMultMatrix(&matrixLookup); }
/** * Sets up the camera for the context. * * The current OpenGL matrix is modified. * * @param context * The context. */ static void camera_setup(Context *context) { glMatrixMode(GL_MODELVIEW); mgluPerspective(45, context->gl.ratio, CAMERA_Z - 1.5, CAMERA_Z + 1.0); mgluLookAt( context->camera.x, context->maze.data->height - context->camera.y, CAMERA_Z, context->target.x, context->maze.data->height - context->target.y, TARGET_Z, 0.1, 1.0, 0.0); }