简体   繁体   English

WebGL代码生成与预制库相同的矩阵,但不显示相同的矩阵

[英]WebGL code produces same matrices as pre-made library but does not display the same

I am working on a 3D function library (for fun) and am unable to find the error in my code. 我正在开发一个3D函数库(为了好玩),我无法在我的代码中找到错误。 From what I can see, the matrices produced by my code and a pre-made library are exactly the same. 从我所看到的,我的代码和预制库产生的矩阵完全相同。 I am using the same vertex positions but nothing is showing and it's driving me crazy. 我使用相同的顶点位置,但没有任何显示,这让我发疯。

My Version: 我的版本:
http://robjte.de/webgl/notworking.html http://robjte.de/webgl/notworking.html
http://jsfiddle.net/uh9574z0/ http://jsfiddle.net/uh9574z0/

The pre-made working version (target output): 预制工作版(目标输出):
http://robjte.de/webgl/working.html http://robjte.de/webgl/working.html
http://jsfiddle.net/5daae976/ http://jsfiddle.net/5daae976/

I have console logged the matrices on each version. 我有控制台记录每个版本的矩阵。

Main segment (my version): 主要部分(我的版本):

var translate = [0.5, 0, 0];
var modelMatrix = identity(4);
modelMatrix.setXY(3, 0, translate[0]);
modelMatrix.setXY(3, 1, translate[1]);
modelMatrix.setXY(3, 2, translate[2]);

var eye = createVector([0, 0, 2.25]);
var focus = createVector([0, 0, 0]);
var up = createVector([0, 1, 0]);

modelMatrix = modelMatrix;
var viewMatrix = lookAt(eye, focus, up);
var projectionMatrix = perspective(canvas, 50 * Math.PI / 180, 1, 10);


Main segment (working version): 主要部分(工作版):

// local coords -> world space
var modelMatrix = mat4.create();
mat4.translate(modelMatrix, modelMatrix, vec3.fromValues(0.5, 0.0, 0.0));

// world space -> camera space
var eye = vec3.fromValues(0, 0, 2.25);
var lookAt = vec3.fromValues(0, 0, 0);
var up = vec3.fromValues(0, 1, 0);
var viewMatrix = mat4.create();

mat4.lookAt(viewMatrix, eye, lookAt, up);

var projMatrix = mat4.create();
mat4.perspective(projMatrix, 50 * Math.PI / 180, canvas.clientWidth / canvas.clientHeight, 1, 10);

I don't think your math lib is actually generating the same results. 我不认为你的数学库实际上产生了相同的结果。 I used the WebGL Inspector to look at the state of the program in each of your links. 我使用WebGL Inspector来查看每个链接中程序的状态。 There's a few very significant differences. 有一些非常显着的差异。

不一样

I figured it out. 我想到了。 My arrays were in row major order instead of column major order as required by GLSL. 我的数组按行主要顺序而不是GLSL要求的列主要顺序。 This helped a lot: Correct OpenGL matrix format? 这有很大帮助: 正确的OpenGL矩阵格式?

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

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