PDA

View Full Version : Help with rotation math



mrbendel
09-05-2012, 11:46 AM
Hey Guys,

I'm having trouble figuring out the math to rotate faces on a sphere. Here is an image of where I'm at so far (faces placed around sphere and rotated on the y-axis correctly:

https://dl.dropbox.com/u/5257679/sphere.png

I'm trying to figure out how I need to rotate the x and z axis and can't seem to figure it out. If I do the same process as I did above I get this:

https://dl.dropbox.com/u/5257679/sphere_wrong.png

You can see that only one strip of the sphere is rotated correctly whereas everything else starts to get all wonky.

The code I have for the y axis is:



var xProgress = (i%this.resX/this.resX);
var pi2 = Math.PI*2;
tmp.rotation.y = xProgress*-pi2+(Math.PI * 0.5);


the x axis is:



var row = Math.floor(i/this.resY);
var yProgress = (row/this.resY);
tmp.rotation.x = yProgress*-Math.PI+(Math.PI*0.5);


I know part of the reason that it's not working is that i'm affecting the rotation of rows instead of columns, but I feel that i'm missing something fundamental here. There should be a way to calculate the rotation based on x,y,z of the sphere...

Any ideas? Thanks!