void balk::rotate(double angle)
{
int t;
double alpha;
double distancexz;
for (t=0; t<8;t++)
{
distancexz=sqrt(x[t]*x[t]+z[t]*z[t]);
alpha = asin(z[t]/distancexz);
if (x[t]<0) alpha=PI-alpha;
alpha = alpha + angle;
x[t] = cos(alpha)*distancexz;
z[t] = sin(alpha)*distancexz;
}
}
But when I and some code for rotation around Y-as AND X-as works it realy bad:
The points of my objects move in comparision to other points of the same object ???
Here is the BAD working code:
void balk::rotate(double angley, double anglez)
{
int t;
double alpha;
double distance;
for (t=0; t<8;t++)
{
distance=sqrt(x[t]*x[t]+z[t]*z[t]+y[t]*y[t]);
alpha = asin(z[t]/sqrt(z[t]*z[t]+x[t]*x[t]));
if (x[t]<0) alpha=PI-alpha;
alpha = alpha + anglex;
beta = acos(y[t]/distance);
if (y[t]<0) beta=-beta;
beta = beta + angley;
x[t] = cos(alpha)*(sqrt(x[t]*x[t]+z[t]*z[t]));
y[t] = distance * cos(beta);
z[t] = sin(alpha)*(sqrt(x[t]*x[t]+z[t]*z[t]));
}
}
Even when I call this function "object.rotate(rot,0);" what will normaly gives just the same result as the good code are there still the same problems.
Anyone know what I have done wrong ?