PDA

View Full Version : First time experimenting with Javascript and 3D...a bit nervous


kungfu
08-09-2002, 10:59 AM
Hi,

I've been working on a little Javascript page that rotates Divs in 3D. It's easier if you look as i can't explain very well.

http://www.emptystring.com/3d3.htm

If you watch it for about 10 seconds it starts to shrink and it's really not supposed to as it's z coordinate is constant throughout.

From what i've read it's a rounding error and i need to normalise the vectors every 10th rotation to correct this error. I've tried this on a copy and it just warps the box. Anyone have any ideas on how to stop it shrinking.....please?....Anyone?

Thanks for your time

Kerry

joh6nn
08-10-2002, 10:02 AM
well, can you point out the parts of the code where you round things, and show how you tried to normalize it? there's a lot of code to wade through there, and if, like me, you're not real sure what you're looking at (math, especially with vectors and such, was never my strong point), then it's hard to to be sure if you know how to fix it.

kungfu
08-10-2002, 11:38 AM
Ok thanks for looking, i've uploaded the page where i've tried to normalise the vectors. It now looks more like a bowl but it's supposed to be a cube!!

http://www.emptystring.com/3d3.htm

These are the two functions i use. Each vector is a Javascript object with an x,y,z value. At the moment i'm running them through the normalise function on every rotation but i've tried it after 10 and it still looks warped but it jumps a lot.

function magnitude(x, y, z){
res = Math.sqrt((x*x) + (y*y) + (z*z));
return res;
}

function normalise(x, y, z){
tempm = magnitude(x,y,z);
if (tempm != 0.0){
resultvec = new vector(x/tempm, y/tempm, z/tempm);
return resultvec;
} else {
resultvec = new vector(x, y, z);
return resultvec;
}
}


The worse thing of all is that not only are the coordinates warped but it still shrinks after i've normalised it.

I was hoping someone had done something similar and that this might be a common problem rotating things.