View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# What's wrong with my code ?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1Anonymous Poster_Anonymous Poster_*  Guests

Posted 30 December 1999 - 12:24 AM

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 ?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.