Problems with the J3DIMath.js library used in demos

• 11-02-2010, 07:04 PM
manixrock
Problems with the J3DIMath.js library used in demos
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:
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:

Code :

``` 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.
• 01-29-2011, 06:07 PM
einSelbst
Re: Problems with the J3DIMath.js library used in demos
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
• 02-11-2011, 09:23 AM
pion
Re: Problems with the J3DIMath.js library used in demos
• 08-17-2011, 06:15 PM
mosfet
Re: Problems with the J3DIMath.js library used in demos
I'm no expert JS coder, but isn't there also a problem with the cross product function? Currently it's as follows:

Code :

```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]; }```

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