简体   繁体   English

Android GLES2.0:基本矩阵问题

[英]Android GLES2.0 : Basic matrix problems

I'm beginning in OpenGL ES on Android (Java); 我开始使用Android(Java)上的OpenGL ES; I'm following this tutorial : http://developer.android.com/training/graphics/opengl/projection.html 我正在关注本教程: http : //developer.android.com/training/graphics/opengl/projection.html

Things basically go well, except that I have some trouble with matrix-multiplication that I didn't have on desktop OpenGL (where I used GLM instead of java/android framework) My projection+view matrix does'nt work correctly when I do projection * view * vec4(..coords..) The only way for my geometry to be shown is to multiply by right : vec4(...) * MVP, where MVP is Projection*View. 一切基本顺利,除了我在台式机OpenGL上没有遇到的矩阵乘法问题(我使用GLM而不是Java / android框架)时,投影时我的投影+视图矩阵无法正常工作* view * vec4(.. coords ..)显示我的几何图形的唯一方法是向右乘:vec4(...)* MVP,其中MVP是Projection * View。 It shouldn't work (as far as I'm concerned) but... it does. 就我而言,它不应该工作,但是...可以。 At least a little bit. 至少一点点。 I get massive clipping problems by using this way, but it's still better than nothing :D 通过这种方式,我遇到了很多裁剪问题,但总比没有好:D

My problem is kinda similar to this (and same tutorial, but it looks like it got updated) : Android OpenGL weirdness with the setLookAtM method 我的问题有点类似于此(和相同的教程,但看起来好像已经更新了): 使用setLookAtM方法的Android OpenGL怪异

But it looks like I have the opposite problem now. 但是看来我现在有相反的问题。 And I've tried every combination I've imagined to solve this (transpose MVP in GLSL, multiply view by projection and not the other way around, etc.) 我已经尝试过想像中的每种组合来解决此问题(在GLSL中转置MVP,通过投影而不是反过来乘以视图,等等)

Here's my code 这是我的代码

 //GLSL :
 gl_Position =  vec4(vPosition, 1.0) * MVP;

Where MVP is mMVPMatrix, which is defined as ... 其中MVP是mMVPMatrix,定义为...

 Matrix.setLookAtM(mCameraMatrix, 0, 8, 8, -8, 0f, 0f, 0f, 0.0f, 1.0f, 0.0f);
 Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mCameraMatrix, 0);

And projection is 投影是

float ratio = (float) width / height;

android.opengl.Matrix.frustumM(mProjectionMatrix, 0, -ratio, ratio, -1, 1, 3, 7);

Any idea ? 任何想法 ?

解决的问题:我只需要在计算MVP矩阵之前将其设置为Identity,然后每一帧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM