I like to know how to scale correctly OpenGL ES 2.0. I have successfully drawn a model, but it is quite small, and I can not enlarge this model. What I like is to scale through this model.
The model is a building with different floors - I would like to zoom in to each room on each floor. But either the object disappears due to the truncation representation, or I cannot get very “close” to this object.
I use the zoom-touch gesture and get the value "scale" - what should I do with this value now?
What I have tried so far:
Changing the distance between planes and far planes and changing the value of eyeZ in Matrix.setLookAtM (....), but what I only achieve is scaling ... It disappears when scaling after a bit ... Therefore, I cannot increase some special parts ("thats far" ....)
How can i achieve this?
Thus, the biggest problem is getting closer to the plane in combination with scaling through eyeZ-Value. It just doesn't work. If I zoom in, the object disappears due to proximity. But I do not see any logic in this.
I am currently using:
Matrix.setLookAtM(mViewMatrix, offset, eyeX, eyeY, eyeZ / mZoomLevel,
centerX, centerY, centerZ, upX, upY, upZ);
where mZoomLevel is the factor that I get through onTouch Scaling.
All my operations with matrices are displayed here:
@Override
public void onDrawFrame(GL10 unused) {
LoggerHelper.calculateFPS();
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
Matrix.setIdentityM(mModelMatrix, 0);
Matrix.scaleM(mModelMatrix, 0, model3d.getRatio() * scaleFactor,
model3d.getRatio() * scaleFactor, model3d.getRatio()
* scaleFactor);
Matrix.translateM(mModelMatrix, 0, translateX, translateY, translateZ);
Helper.rotateModel(mModelMatrix, rotationX, rotationY, rotationZ, true,
model3d.getWidth(), model3d.getLength(), model3d.getHeight());
Matrix.setLookAtM(mViewMatrix, offset, eyeX, eyeY, eyeZ / mZoomLevel,
centerX, centerY, centerZ, upX, upY, upZ);
Matrix.multiplyMM(mMVMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
Matrix.frustumM(mProjectionMatrix, 0, -ratio, ratio, 1, -1,
nearPlaneDistance, farPlaneDistance);
float[] mMVPMatrix = new float[16];
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVMatrix, 0);
model3d.draw(mMVPMatrix);
}
Any important variables:
private float nearPlaneDistance = 1f;
private float farPlaneDistance = 200f;
private float eyeZ = -1;
I downloaded a dummy project with only the OpenGL part in Github - if you want to study the source code better
:

:
