Ортогональная камера WebGL

Может кто-нибудь, пожалуйста, помогите мне со следующим кодом:

gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
mat4.ortho(pMatrix, 0, gl.viewportWidth, 0, gl.viewportHeight, 0.1, 100);
mat4.identity(mvMatrix);
mat4.lookAt(mvMatrix, [0, 0, -40], [0, 0, 0], [0, 1, 0]);

Полный исходный код http://jsfiddle.net/bepa/2QXkp/

Я пытаюсь отобразить куб с помощью орфографической камеры, но все, что я вижу, это черный цвет. Куб должен быть в (0, 0, 0), камера (0, 0, -40) и взгляд в (0,0,0).

Для всех матричных преобразований я использую gl-matrix 2.2.0.

РЕДАКТИРОВАТЬ:

Это отлично работает:

mat4.perspective(pMatrix, 45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0);
mat4.identity(mvMatrix);
mat4.lookAt(mvMatrix, [0, 40, -40], [0, 0, 0], [0, 1, 0]);
mat4.rotate(mvMatrix, mvMatrix, degToRad(45), [0, 1, 0]);

Это не работает:

mat4.ortho(pMatrix, 0, gl.viewportWidth, 0, gl.viewportHeight, 0.1, 100);
mat4.identity(mvMatrix);
mat4.lookAt(mvMatrix, [0, 40, -40], [0, 0, 0], [0, 1, 0]);
mat4.rotate(mvMatrix, mvMatrix, degToRad(45), [0, 1, 0]);

person coda    schedule 10.06.2014    source источник


Ответы (1)


 mat4.ortho(pMatrix, -1.0, 1.0, -1.0, 1.0, 0.1, 100);

Дает результат, который не черный ;)

Документация mat4.ortho():

/**
 * Generates a orthogonal projection matrix with the given bounds
 *
 * @param {mat4} out mat4 frustum matrix will be written into
 * @param {number} left Left bound of the frustum
 * @param {number} right Right bound of the frustum
 * @param {number} bottom Bottom bound of the frustum
 * @param {number} top Top bound of the frustum
 * @param {number} near Near bound of the frustum
 * @param {number} far Far bound of the frustum
 * @returns {mat4} out
 */
mat4.ortho = function (out, left, right, bottom, top, near, far) {

Ширина и высота холста не нужны для ортопроекции. Но я недостаточно знаком с проекционными матрицами, чтобы дать вам подробное объяснение, почему.

person Heinzlmaen    schedule 11.06.2014
comment
Спасибо большое, наконец-то я вижу некоторые цвета :) - person coda; 11.06.2014