开发者

Converting Orthogonal Camera to Perspective OpenGL

开发者 https://www.devze.com 2023-02-28 01:55 出处:网络
I\'m having some troubles converting a orthogonal camera to a perspective one, using OpenGL. I currently have my orthogonal camera following a middle point of two objects, using:

I'm having some troubles converting a orthogonal camera to a perspective one, using OpenGL. I currently have my orthogonal camera following a middle point of two objects, using:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,_winWidth,0,_winHeight,150,-150);
glTranslated(-_middlePoint[0]+_winWidth/2, -_middlePoint[1]+_winHeight/2, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

The above code works perfectly, now i'm trying to use it like this:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, _winWidth/_winHeight, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 800, _middlePoint[0], _middlePoint[1], 50, 0, 0, 1);
glLoadIdentity();

And I simply get a black screen. Any thoughts? I've tried changing the up vector from 0,0,1 to 0,1,开发者_开发技巧0 and it stays the same.

Any help appreciated.


If you have code working using glOrtho already, you can normally switch to a perspective projection by simply changing that to glFrustum. If you're writing new code, gluPerspective and gluLookat may be easier, but for code that already works using an orthographic projection, it's easy to switch to perspective by just calling glFrustum with the same parameters.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号