我使用ScaleM(modelMatrix, offset, x, y, z)方法增加了对象的大小。
...
protected val projectionMatrix = FloatArray(16)
protected val modelMatrix = FloatArray(16)
protected val modelViewMatrix = FloatArray(16)
protected val mvpMatrix = FloatArray(16)
...
Matrix.setIdentityM(modelMatrix, 0)
Matrix.translateM(modelMatrix, 0, 1.0f, 0.0f, 100.0f)
Matrix.rotateM(modelMatrix, 0, angle, 0.0f, 0.5f, 0.0f)
Matrix.scaleM(modelMatrix, 0, 15f, 15f, 15f) // enlarge object
Matrix.multiplyMM(modelViewMatrix, 0, viewMatrix, 0, modelMatrix, 0)
Matrix.multiplyMM(mvpMatrix, 0, projectionMatrix, 0, modelViewMatrix, 0)
...
物体增大了,但这影响了它的显示效果(在我的例子中,亮度增加,虹彩减少)。是否有一个简单的方法来避免这种情况,或者我需要重新配置着色器和输入参数?
先谢谢你
也许还有更好的方案,但我找到了下面的解决方案。
private val modelViewMatrixForShader = FloatArray(16)
...
Matrix.translateM(modelMatrix, 0, 0.0f, 0.0f, -100.0f)
Matrix.rotateM(modelMatrix, 0, angle, 0.0f, 0.5f, 0.0f)
Matrix.multiplyMM(modelViewMatrixForShader, 0, viewMatrix, 0, modelMatrix, 0)
Matrix.scaleM(modelMatrix, 0, 15f, 15f, 15f)
Matrix.multiplyMM(modelViewMatrix, 0, viewMatrix, 0, modelMatrix, 0)
Matrix.multiplyMM(mvpMatrix, 0, projectionMatrix, 0, modelViewMatrix, 0)
...
fun getMVMatrixAsFloatBuffer(): FloatBuffer = floatBuffer(modelViewMatrixForShader)
...
GLES20.glUniformMatrix4fv(mvMatrixLink, 1, false,
view.getMVMatrixAsFloatBuffer());