gpt4 book ai didi

android - 无法在屏幕上绘制带 Z 轴的顶点

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:13:28 24 4
gpt4 key购买 nike

我需要在屏幕上绘制几个坐标,不显示 Z 轴的坐标,但不显示具有 Z 轴值的坐标。在绘制有效的坐标之前,我尝试对坐标进行归一化。归一化后,所有坐标都会被绘制出来。但在非归一化坐标的情况下,Z 轴的顶点被隐藏。

OpenGL 版本:ES 2.0

坐标:

float squareCoords[] = {
202.00002f, 244.00002f, 0.0f,
440.00003f, 625.00006f, 0.0f,
440.00003f, 625.00006f, 0.0f,
690.00006f, 186.0f,0.0f,

202.00002f, 244.00002f, 50.0f,
440.00003f, 625.00006f, 50.0f,
440.00003f, 625.00006f, 50.0f,
690.00006f, 186.0f, 50.0f
};

指数:

short[] drawOrder = {
0,1,2,3,
0,4,
1,5,
2,6,
4,5,6,7
};

绘制代码:

 GLES20.glDrawElements(
GLES20.GL_LINES, drawOrder.length,
GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

在 Surface 上更改代码:

public void onSurfaceChanged(GL10 unused, int width, int height) {
mWidth = width;
mHeight = height;

GLES20.glViewport(0, 0, mWidth, mHeight);

float ratio = (float) mWidth / mHeight;

// this projection matrix is applied to object coordinates
// in the onDrawFrame() method
Matrix.orthoM(mProjMatrix, 0, 0f, width, 0.0f, height, 0, 50);

}

开画:

public void onDrawFrame(GL10 unused) {
Square square = new Square();
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT|GLES20.GL_DEPTH_BUFFER_BIT);

if (mFirstDraw)
mFirstDraw = false;

long time = SystemClock.uptimeMillis() % 4000L;
float angle = 0.090f * ((int) time);
// float angle = 90;
// Matrix.setRotateM(mRotationMatrix, 0, angle, 0, 0, -1.0f);
// angle += 0.7f;
if (angle > 360f)
angle = 0f;
Matrix.setLookAtM(mVMatrix, 0, 0f, 0f, 4f, 0f, 0f, 0f, 0f, 1f, 0f);
// projection x view = modelView
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
// Creating rotation matrix
Matrix.setRotateM(rotationMatrix, 0, angle, -1f, 0f, 0f);

// rotation x camera = modelView
float[] duplicateMatrix = Arrays.copyOf(mMVPMatrix, 16);

Matrix.multiplyMM(mMVPMatrix, 0, duplicateMatrix, 0, rotationMatrix, 0);

square.draw(mMVPMatrix);
}

我正在旋转图表以确定是否绘制了 Z 轴上的顶点。

我个人认为这条线是罪魁祸首,这里我给远值50和近值0。我想知道这些值应该是什么

Matrix.orthoM(mProjMatrix, 0, 0f, width, 0.0f, height, 0, 50);

最佳答案

这里的问题是 far 的值不够高。我放了500

Matrix.orthoM(mProjectionMatrix, 0, 0f, width, 0.0f, height,0, 500);

并将坐标更改为:

float squareCoords[] = {
202.00002f, 244.00002f, 0.0f,
440.00003f, 625.00006f, 0.0f,
440.00003f, 625.00006f, 0.0f,
690.00006f, 186.0f,0.0f,

202.00002f, 244.00002f, 200.0f,
440.00003f, 625.00006f, 200.0f,
440.00003f, 625.00006f, 200.0f,
690.00006f, 186.0f, 200.0f
};

它现在可以工作了。

关于android - 无法在屏幕上绘制带 Z 轴的顶点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42061341/

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