PDA

View Full Version : Problems with the J3DIMath.js library used in demos

manixrock
11-02-2010, 06:04 PM
There are several tutorials which use the J3DI.js and J3DIMath.js libraries, for example: http://www.khronos.org/webgl/wiki/Tutorial

There are problems I found (with some help) with this library. I'm not sure where I should be posting these bugs so I'll put them here:

In J3DIMath.js in J3DIMatrix4.prototype.lookat() the following code:

matrix.\$matrix.m11 = xx;
matrix.\$matrix.m12 = xy;
matrix.\$matrix.m13 = xz;
matrix.\$matrix.m14 = 0;

matrix.\$matrix.m21 = yx;
matrix.\$matrix.m22 = yy;
matrix.\$matrix.m23 = yz;
matrix.\$matrix.m24 = 0;

matrix.\$matrix.m31 = zx;
matrix.\$matrix.m32 = zy;
matrix.\$matrix.m33 = zz;
matrix.\$matrix.m34 = 0;

must be changed to:

matrix.\$matrix.m11 = xx;
matrix.\$matrix.m12 = yx;
matrix.\$matrix.m13 = zx;
matrix.\$matrix.m14 = 0;

matrix.\$matrix.m21 = xy;
matrix.\$matrix.m22 = yy;
matrix.\$matrix.m23 = zy;
matrix.\$matrix.m24 = 0;

matrix.\$matrix.m31 = xz;
matrix.\$matrix.m32 = yz;
matrix.\$matrix.m33 = zz;
matrix.\$matrix.m34 = 0;

In J3DIVector3.prototype.cross(), J3DIVector3.prototype.combine() and probably others, variables are used after they are changed when temporary values should be used to store the original values.

I'm posting this here because it has wasted a lot of my time trying to find the problem. If anyone knows where these should go, let me know. Hope it helps someone.

einSelbst
01-29-2011, 05:07 PM
manixrock,

I know exactly what you mean. The last 3 days I spent on that problem exclusively. I even wrote an interactive website to test the effects of what happens when I calculate the matrices in different order.
The worse thing is, I knew about your post and I was in the belief, that I had changed the function. Turned out I had the file twice on my computer.

What a realization.

peace,
einSelbst

pion
02-11-2011, 08:23 AM
I ran across similar problem.

I am switching to mjs. Please see

A list of available matrix library
http://learningwebgl.com/cookbook/index.php/Main_Page#Matrix_libraries

mosfet
08-17-2011, 05:15 PM
I'm no expert JS coder, but isn't there also a problem with the cross product function? Currently it's as follows:

J3DIVector3.prototype.cross = function(v)
{
this[0] = this[1] * v[2] - this[2] * v[1];
this[1] = -this[0] * v[2] + this[2] * v[0];
this[2] = this[0] * v[1] - this[1] * v[0];
}