Javascript 标量矩阵乘法

Javascript 标量矩阵乘法,javascript,object,matrix,scalar,Javascript,Object,Matrix,Scalar,我有一个叫做立方体的物体。它是这样设置的 //Cube object function Cube(vertices, color, scale) { //this.vertices = vertices; this.setColor(color); this.setScale(vertices, 1); } 我注释掉了//this.vertices=vertices因为我不确定是否必须在此处设置顶点或在setScale(

我有一个叫做立方体的物体。它是这样设置的

//Cube object
    function Cube(vertices, color, scale) 
    {
        //this.vertices = vertices;
        this.setColor(color);
        this.setScale(vertices, 1);
    }
我注释掉了
//this.vertices=vertices因为我不确定是否必须在此处设置顶点或在
setScale()函数中设置顶点。
我想在矩阵上设置一个刻度。矩阵为:

var verts = [
            // Front face
            -1.0, -1.0,  1.0,
             1.0, -1.0,  1.0,
             1.0,  1.0,  1.0,
            -1.0,  1.0,  1.0,

            // Back face
            -1.0, -1.0, -1.0,
            -1.0,  1.0, -1.0,
             1.0,  1.0, -1.0,
             1.0, -1.0, -1.0,

            // Top face
            -1.0,  1.0, -1.0,
            -1.0,  1.0,  1.0,
             1.0,  1.0,  1.0,
             1.0,  1.0, -1.0,

            // Bottom face
            -1.0, -1.0, -1.0,
             1.0, -1.0, -1.0,
             1.0, -1.0,  1.0,
            -1.0, -1.0,  1.0,

            // Right face
             1.0, -1.0, -1.0,
             1.0,  1.0, -1.0,
             1.0,  1.0,  1.0,
             1.0, -1.0,  1.0,

            // Left face
            -1.0, -1.0, -1.0,
            -1.0, -1.0,  1.0,
            -1.0,  1.0,  1.0,
            -1.0,  1.0, -1.0
        ];
我用于设置比例的函数如下所示:

Cube.prototype.setScale = function(vertices, scale) 
    {
        var length = vertices.length;
        for( var i = 0; i < length; i++)
        {
            //alert("before "+ vertices[i]+ " i "+ i);
            vertices[i] *= scale; 
            //alert("after "+ vertices[i]);
        }
Cube.prototype.setScale=函数(顶点,比例)
{
变量长度=顶点长度;
对于(变量i=0;i
我认为通过这样做,for循环应该采用矩阵长度并开始for循环。
在这个for循环中,我将得到I处的垂直度并将其乘以刻度。
当我这样做时,for循环将重复。即,当我达到72时,循环不会停止

我注释掉了
//this.vertices=vertices;
,因为我不确定是否必须在这里设置顶点

您要么需要设置它,要么在构造函数的末尾设置它。您的<代码> StStase函数与存储<代码>顶点< /代码>数组的位置非常好的分离,并且我会保持这种方式。但是您可以考虑重命名它“代码> SimeVielTeX()/<代码>。

当我这样做时,for循环将重复。即,当我达到72时,循环不会停止

真的吗?这很奇怪。我一定是遗漏了什么;代码看起来是正确的


不要使用
alert()
,顺便说一句,调试任何东西都会让你的生活陷入地狱。你最好使用
console.log()

我已经实现了名称更改,并取消了
此的注释。顶点
这已经修复了顶点并调整了它们的大小。