0

当我记录我的 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);

}
4

1 回答 1

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);
于 2013-06-29T20:17:07.973 回答