elefher / glmatrix

Automatically exported from code.google.com/p/glmatrix
0 stars 0 forks source link

.str() issue... you are not printing what you think you want to print. #50

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
if you create a matrix, then modify it, then print it, then modify it again and 
print it to console... you will see both logs being identical (to the latest 
state of the matrix you have been modifying) despite the matrix not being the 
same in both logging statements.
A workaround is to call the first console.log() like this:

console.log(mat4.create(testMat));

this way we know that the value printed out to console is the value the matrix 
had at that point in the JavaScript program.

Defining the following helper function is another workaround:

function printVec3 (v) {
    console.log(vec3.create(v));
}

function printVec4 (v) {
    console.log(vec4.create(v));
}

function printMat3 (m) {
    console.log(mat3.create(m));
}

function printMat4 (m) {
    console.log(mat4.create(m));
}

Original issue reported on code.google.com by Pana...@gmail.com on 6 Apr 2011 at 1:55

GoogleCodeExporter commented 8 years ago
Please close this issue as the following code sample verifies that the library 
is indeed working correctly (I was doing something wrong before):

            var zoomFactor = 0.88;
            var scaleFactorX = 1.0 * zoomFactor;
            var scaleFactorY = 1.0 * zoomFactor;

            mat4.translate(mTranslate, [0.0, -1.0, 0.0]);
            mat4.scale(mScale, [scaleFactorX, scaleFactorY, 1.0]);

            //Model * Translate * Scale
            mat4.identity(mModel);
            mat4.identity(this.mPMVMatrix);

            console.log("mPMVMatrix = " + mat4.str(this.mPMVMatrix));

            /////////////////////////////////////////////
            mat4.multiply(mTranslate, mModel, mModel);
            mat4.multiply(mScale, mModel, mModel);

            mat4.lookAt(eye, target, up, mView);

            mat4.set(mModel, this.mPMVMatrix);
            console.log("mPMVMatrix = " + mat4.str(this.mPMVMatrix));
            mat4.multiply(mView, this.mPMVMatrix, this.mPMVMatrix);
            console.log("mPMVMatrix = " + mat4.str(this.mPMVMatrix));
            mat4.multiply(mProjection, this.mPMVMatrix, this.mPMVMatrix);
            console.log("mPMVMatrix = " + mat4.str(this.mPMVMatrix));

...

that produces the following output:

[13:10:54.581] "mPMVMatrix = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]"
[13:10:54.585] "mPMVMatrix = [0.8799999952316284, 0, 0, 0, 0, 
0.8799999952316284, 0, 0, 0, 0, 1, 0, 0, -0.8799999952316284, 0, 1]"
[13:10:54.589] "mPMVMatrix = [0.8799999952316284, 0, 0, 0, 0, 
0.8799999952316284, 0, 0, 0, 0, 1, 0, 0, -0.8799999952316284, 
-2.7474775314331055, 1]"
[13:10:54.594] "mPMVMatrix = [1.8133351802825928, 0, 0, 0, 0, 
2.4177801609039307, 0, 0, 0, 0, -3.444444417953491, -1, 0, -2.4177801609039307, 
-0.31424403190612793, 2.7474775314331055]"

Original comment by Pana...@gmail.com on 12 Apr 2011 at 11:15

GoogleCodeExporter commented 8 years ago
This does indeed seem to be functioning correctly. I'm closing this unless a 
better example of defective code can be provided.

Original comment by Tojiro@gmail.com on 24 Apr 2011 at 4:19