I like to know about how to correctly zoom in OpenGL ES 2.0
. I've successfully drawn a model but it's pretty small and I'm not able to zoom into this model. What I like to have is to zoom "through" this model.
The model is a building with different floors - I'd like to zoom to every room of every floor. But either the object disappears because of the view frustum or I'm not able to get very "near" to this object.
I'm using the zoom-touch gesture and get a value "scale" - what should I now do with this value?
What I tried so far:
Changing the near-plane and far-plane distance and changing the eyeZ-Value within Matrix.setLookAtM(....) but what I only achieve is zooming out... It disappears in zooming in after a bit... So I'm not able to zoom in to some special parts ("THAT" far....)
How I can I achieve this?
So the biggest problem is the near-plane combined with zooming via the eyeZ-Value. It simply doesn't work. If I zoom in, the object disappears because of the nearplane. But I don't see any logic behind this.
Currently I'm using:
/*
* Set the camera position (View matrix)
*/
Matrix.setLookAtM(mViewMatrix, offset, eyeX, eyeY, eyeZ / mZoomLevel,
centerX, centerY, centerZ, upX, upY, upZ);
where mZoomLevel is the factor I get through the onTouch-Zooming.
My whole Matrix-Operations are shown here:
@Override
public void onDrawFrame(GL10 unused) {
LoggerHelper.calculateFPS();
/*
* Draw background color
*/
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
/*
* scale model down to smaller values
*/
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.scaleM(mModelMatrix, 0, model3d.getRatio() * scaleFactor,
model3d.getRatio() * scaleFactor, model3d.getRatio()
* scaleFactor);
/*
* rotate and translate model in dependence to the user input
*/
Matrix.translateM(mModelMatrix, 0, translateX, translateY, translateZ);
Helper.rotateModel(mModelMatrix, rotationX, rotationY, rotationZ, true,
model3d.getWidth(), model3d.getLength(), model3d.getHeight());
/*
* Set the camera position (View matrix)
*/
Matrix.setLookAtM(mViewMatrix, offset, eyeX, eyeY, eyeZ / mZoomLevel,
centerX, centerY, centerZ, upX, upY, upZ);
/*
* combine the model with the view matrix
*/
Matrix.multiplyMM(mMVMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
/*
* this projection matrix is applied to object coordinates in the
* onDrawFrame() method
*/
Matrix.frustumM(mProjectionMatrix, 0, -ratio, ratio, 1, -1,
nearPlaneDistance, farPlaneDistance);
/*
* Calculate the projection and view transformation
*/
float[] mMVPMatrix = new float[16];
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVMatrix, 0);
/*
* all the drawing stuff inside the model-object (otherwise
* translation/rotation wouldn't affect every object)
*/
model3d.draw(mMVPMatrix);
}
Any some important variables:
private float nearPlaneDistance = 1f;
private float farPlaneDistance = 200f;
private float eyeZ = -1;
What I have:
What I need:
One of my solutions (not working very good):
But this is not the best approach (see coments below this answer)