我想知道如何正确放大OpenGL ES 2.0
。我已经成功绘制了一个模型,但它非常小,我无法放大这个模型。我喜欢的是放大“通过”这个模型。
该模型是具有不同楼层的建筑物 - 我想放大到每个楼层的每个房间。但是要么对象因为视锥而消失,要么我无法非常“接近”这个对象。
我正在使用缩放触摸手势并获得一个值“比例” - 我现在应该如何处理这个值?
到目前为止我尝试了什么:
更改近平面和远平面距离并更改 Matrix.setLookAtM(....) 中的 eyeZ-Value 但我只实现缩小...它在放大后消失...所以我'无法放大到某些特殊部分(“那”远....)
我怎样才能做到这一点?
所以最大的问题是通过 eyeZ-Value 结合缩放的近平面。它根本行不通。如果我放大,物体会因为近平面而消失。但我看不出这背后有什么逻辑。
目前我正在使用:
/*
* Set the camera position (View matrix)
*/
Matrix.setLookAtM(mViewMatrix, offset, eyeX, eyeY, eyeZ / mZoomLevel,
centerX, centerY, centerZ, upX, upY, upZ);
其中 mZoomLevel 是我通过 onTouch-Zooming 获得的因素。
我的整个矩阵运算都显示在这里:
@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);
}
任何一些重要的变量:
private float nearPlaneDistance = 1f;
private float farPlaneDistance = 200f;
private float eyeZ = -1;
我在 Github 上上传了一个只有 OpenGL 部分的虚拟项目——以防你想更好地查看源代码
我有的:
我需要的: