Reputation: 100
I am using a sample code and not able to understand a function Frustumf()
.
I want to change far
argument value in it. my mean I want to see my object smaller then current view.
This is part of Myrenderer
class in android.
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
float aspect = (float)width / height;
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustumf(-aspect, aspect, -1.0f, 1.0f, 1.0f, 50.0f);
}
Upvotes: 0
Views: 83
Reputation: 54592
The far
argument has no effect on the size of the object. It only controls the far clipping plane.
As the fancy diagram in @datenwolf's answer shows, the left
, right
, bottom
and top
values are measured at the near plane. So it's the relationship of those values with the near
value that control the field of view, which in turn controls the size of your object.
More precisely, if bottom
and top
have the same magnitude, the field of view in the vertical direction is calculated as:
fovAngle = 2 * atan(top / near)
This means that making the near
value smaller or making the top
value larger increases the field of view angle, and making the near
value larger or the top
value smaller decreases the field of view.
To make your object smaller using the projection matrix, without changing the clipping planes, you can multiply the first 4 arguments by a factor. E.g.:
gl.glFrustumf(-2.0f * aspect, 2.0f * aspect, -2.0f, 2.0f, 1.0f, 50.0f);
Since you're increasing the field of view angle, this will also result in a stronger perspective effect. Which may or may not be desirable.
The more standard way of controlling the size of your objects is by modifying the view matrix, while leaving the projection unchanged. For example, to scale by a factor of 2:
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glScalef(2.0f, 2.0f, 2.0f);
Upvotes: 1
Reputation: 162164
Here's a picture produced by the program https://github.com/datenwolf/codesamples/tree/master/samples/OpenGL/frustum
The grid is in the XY plane with Z=0, the labeled measure arrows depict the parameters for the frustum.
Upvotes: 1