glMatrix无法正常工作?

时间:2013-06-29 16:59:58

标签: javascript google-chrome

当我记录this.kernel时,值不会改变。但我认为他们应该。 根据文档,它应该有效,http://glmatrix.net/docs/2.2.0/symbols/vec3.html#.normalize

    this.kernel = [];
    this.kernelSize = 16.0;
    var max = 1.0;
    var min = -1.0;
    var a = Math.random(); 

for (var i = 0; i < this.kernelSize; i++){
    this.kernel.push(Math.random() * (max - min) + min); // random float, range -1..1
    this.kernel.push(Math.random() * (max - min) + min);
    this.kernel.push(Math.random()); //random float, range 0..1

    vec3.normalize([this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 + 2]], [this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 +2]]);
    console.log(this.kernel);
    vec3.multiply([this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 + 2]], a, 1.0);
    console.log(this.kernel);

}

1 个答案:

答案 0 :(得分:0)

只需检查API,您就会面临一个相当基本的问题,例如x = f(x);

vec3.normalize()返回输入内核的修改版本(见下文)

来自http://glmatrix.net/docs/2.2.0/symbols/src/gl-matrix_src_gl-matrix_vec3.js.%3Chtml

333 /**
334  * Normalize a vec3
335  *
336  * @param {vec3} out the receiving vector
337  * @param {vec3} a vector to normalize
338  * @returns {vec3} out
339  */
340 vec3.normalize = function(out, a) {
341     var x = a[0],
342         y = a[1],
343         z = a[2];
344     var len = x*x + y*y + z*z;
345     if (len > 0) {
346         //TODO: evaluate use of glm_invsqrt here?
347         len = 1 / Math.sqrt(len);
348         out[0] = a[0] * len;
349         out[1] = a[1] * len;
350         out[2] = a[2] * len;
351     }
352     return out;
353 };

只做

this.kernel = vec3.normalize([this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 + 2]], [this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 +2]]);
this.kernel = vec3.multiply([this.kernel[i * 3], this.kernel[i * 3 + 1], this.kernel[i * 3 + 2]], a, 1.0);