开发者

openGL moving camera

开发者 https://www.devze.com 2023-02-05 22:48 出处:网络
I m trying to move my camera. I am using gluLookAt function. I have some variables for this. float x,y,z ==> is camera location

I m trying to move my camera. I am using gluLookAt function. I have some variables for this.

float x,y,z ==> is camera location
float lx,ly,lz ==> is point that camera looks.

I try to move on x axis

x= x+0.01
gluLookAt(x,y,z, lx,ly,lz, 0.0 1.0, 0.0);

it is work.

When i try to move on z axis as same as above

z = z +0.01
gluLookAt(x,y,z, lx,ly,lz, 0.0 1.0, 0.0);

nothing change. Also when i invoke this function several times, first half of object dissapear (corners of object) and after next calling gluLookAt object dissapear completely.

I want the object looks bigger when camera move forward and smaller when camera move backward. But any changes is occured when i move camera on z axis.

What is the problem? Why object dissapear? How can i achieve开发者_运维技巧 that object get bigger when moving camera forward.

I know i can solve it by glTranslate or increasing size of object. But i want to use gluLookAt.

Thanks you for answers.


Sounds like you haven't set up your projection matrix correctly. Use gluPerspective (gl http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml) and make sure the zNear and zFar parameters will accommodate your object.


Your default projection matrix is probably an orthographic projection matrix, meaning that objects do not get bigger when they are near the camera.

The object finally disappears if the camera gets through it (crosses the zNear plane).

As Michael mentionned, you should install a perspective projection matrix, by using gluPerspective.


As mentioned by Michael, this sounds like a projection matrix problem. When using a perspective transform, depth is transformed so as to provide better depth-testing accuracy nearer to the camera than in the distance. As part of this transform the z-coordinates (in viewport coordinates) are divided by zNear (the near plane distance) - zFar (the far plane distance). To minimise depth-fighting the zNear distance (the distance in front of the camera at which objects become invisible) must be as large as you can get away with, so as you move towards objects they will eventually cross the plane and the front of the object will be clipped (which generally appears as if the front of the object has been cut off and you can see inside/through it).

0

精彩评论

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