Jump to content
  • Advertisement

Archived

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

Guest Anonymous Poster

What's wrong with my code ?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Guest Anonymous Poster
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 ?

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!