Advertisement

Translating vectors and that...

Started by August 26, 2001 12:10 PM
12 comments, last by Ryanza 23 years, 5 months ago
It does return a value in radians, but here''s a question: are you using the same axes I am in the same order? (e.g., your X-axis is my X-axis, Y for Y, and Z for Z) Here''s mine...

         ^ Y       |   Facing this direction       |  O       | /       |/        X-------O--------->      /|   Z / |    L  |  


Oh, maybe that''s my goof. You''re FACING the -Z-axis to begin with...

Well, let''s try this for yrot instead...

yrot = (-xDiff, -zDiff);

That might do the trick...

~ Dragonus
nope.. that doesnt help

Ill post the code here, its a bit messy now though, been changing it this way and that for ages now
maybe Im just missing something small...

-- heres movement along the line using the bearings, works 100%
spaceship[loop].pos.x += (double)sin(spaceship[loop].headingy*piover180) * sin(spaceship[loop].headingx*piover180) * .005 * spaceship[loop].speed;

spaceship[loop].pos.z += (double)sin(spaceship[loop].headingy*piover180) * cos(spaceship[loop].headingx*piover180) * .005 * spaceship[loop].speed;

spaceship[loop].pos.y += (double)cos(spaceship[loop].headingy*piover180) * .005 * spaceship[loop].speed;

-- heres what Im trying to use to rotate the headings to face the new point

xDiff=spaceship[loop].fpos.x-spaceship[loop].pos.x;
yDiff=spaceship[loop].fpos.y-spaceship[loop].pos.y;
zDiff=spaceship[loop].fpos.z-spaceship[loop].pos.z;
spaceship[loop].headingx = atan2(xDiff, zDiff);
spaceship[loop].headingy = atan2(yDiff, sqrt(xDiff * xDiff + zDiff * zDiff));
// I also tryed the * by piOver180 thing... def no good, made the numbers tiny (0.0000432 and that)

// to convert radians to degrees...
spaceship[loop].headingx*= 180;
spaceship[loop].headingy*= 180;
spaceship[loop].headingx/= (4 * atan(1));
spaceship[loop].headingx/= (4 * atan(1));

Advertisement
quote:
Original post by Ryanza
spaceship[loop].headingx = atan2(xDiff, zDiff);
spaceship[loop].headingy = atan2(yDiff, sqrt(xDiff * xDiff + zDiff * zDiff));
// I also tryed the * by piOver180 thing... def no good, made the numbers tiny (0.0000432 and that)

// to convert radians to degrees...
spaceship[loop].headingx*= 180;
spaceship[loop].headingy*= 180;
spaceship[loop].headingx/= (4 * atan(1));
spaceship[loop].headingx/= (4 * atan(1));



Oh I see what''s going on. You got what I said wrong. I said 180overPi not piOver180.

spaceship[loop].headingx = atan2(xDiff, zDiff) * 180overPi;
spaceship[loop].headingy = atan2(yDiff, sqrt(xDiff * xDiff + zDiff * zDiff)) * 180overPi;


That does the conversion to radians to degrees. Then you shouldn''t have need the four lines after it that multiply by 180 and divide by whatever.

~ Dragonus
aah, ok.. but theyr still going in the wrong dir
Doh!
well changing to 180overpi is pretty much the same as * by 180 then div by pi...

This topic is closed to new replies.

Advertisement