gpt4 book ai didi

android - 放大 OpenGL ES 2.0 - 对象消失

转载 作者:太空宇宙 更新时间:2023-11-03 10:47:27 24 4
gpt4 key购买 nike

我想知道如何正确放大 OpenGL ES 2.0。我已经成功地绘制了一个模型,但是它非常小,我无法放大这个模型。我想要的是缩放“通过” 这个模型。

模型是一栋不同楼层的建筑 - 我想放大到每一层的每个房间。但是要么对象因为视锥体消失了,要么我不能非常“靠近”这个对象。

我正在使用缩放触摸手势并获得一个值“scale”——我现在应该如何处理这个值?

到目前为止我尝试了什么:

更改近平面和远平面距离并在 Matrix.setLookAtM(....) 中更改 eyeZ-Value 但我唯一实现的是缩小......它在放大后消失了...... . 所以我无法放大到某些特殊部分(“那个”很远......)


我怎样才能做到这一点?

所以最大的问题是近平面与通过 eyeZ 值进行缩放相结合。它根本行不通。如果我放大,物体会因为近平面而消失。但我看不出这背后有任何逻辑。

目前我正在使用:

/*
* Set the camera position (View matrix)
*/
Matrix.setLookAtM(mViewMatrix, offset, eyeX, eyeY, eyeZ / mZoomLevel,
centerX, centerY, centerZ, upX, upY, upZ);

其中 mZoomLevel 是我通过 onTouch 缩放获得的因素。

我的整个矩阵操作显示在这里:

@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;

I uploaded a dummy-project with only the OpenGL-part on Github - in case you want to have a better look into the sourcecode

我有什么:

My current view

我需要什么:

My desired view

最佳答案

我的一个解决方案(效果不是很好):

public void setZoom(float zoom) {
// this projection matrix is applied to object coordinates
// in the onDrawFrame() method
float ratio = (float) width / height;
Matrix.frustumM(mProjectionMatrix, 0, -ratio / zoom, ratio / zoom, -1
/ zoom, 1 / zoom, nearPlaneDistance, farPlaneDistance);
}

但这不是最好的方法(请参阅此答案下方的评论)

关于android - 放大 OpenGL ES 2.0 - 对象消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20517703/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com