#### Archived

This topic is now archived and is closed to further replies.

# What's wrong with my code ?

This topic is 6864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

When I use this code for only rotating around the Y-as works it GOOD(It's a walk around in 3d space application).

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 ?

1. 1
2. 2
3. 3
4. 4
5. 5

• 14
• 9
• 10
• 12
• 17
• ### Forum Statistics

• Total Topics
632909
• Total Posts
3009172
• ### Who's Online (See full list)

There are no registered users currently online

×