🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Ah, rotation problem

Started by
4 comments, last by Morgan 24 years ago
Since nobody ever answers these, I''ll try again. I have two points. I want to know the rotation around the y & z axes which would be applied to a line from point 1 to pass through point two. My code is as follows: rotation[Z] = atanf( ( p2[Y] - p1[Y] )/( p2[X] - p1[X] ) ); rotation[Y] = atanf( ( p2[Z] - p1[Z] )/( p2[X] - p1[X] ) ); Is that right?
Advertisement
Subtracting the source position from the target position will give you a directed vector pointing from the source to the target (which may need to be normalized).

I.e., in pseudocode terms, you would do this:

    vector3 soure, target, dir;dir = target - source; //basic vector subtractiondir.normalize();    


Edited by - revolver on July 1, 2000 1:31:12 AM
Creativity is a bloody nuisance and an evil curse that will see to it that you die from stress and alcohol abuse at a very early age, that you piss off all your friends, break appointments, show up late, and have this strange bohemian urge (you know that decadent laid-back pimp-style way of life). The truly creative people I know all live lousy lives, never have time to see you, don't take care of themselves properly, have weird tastes in women and behave badly. They don't wash and they eat disgusting stuff, they are mentally unstable and are absolutely brilliant. (k10k)
I know all about vectors, I am essentially finding the vector in my code already, what I want to do is rotate an object so it matches the vector. I want to rotate the object around the y & x axes, so is my code right or does someone know what the correct way of doing this is?

Morgan

Edited by - Morgan on July 1, 2000 11:21:28 AM
Hi Morgan
ok i think your code isn''t totaly false but try this:

#define pi 3.141592654

rotation[Z] = ( atanf( ( p2[Y] - p1[Y] )/( p2[X] - p1[X] ) ) ) / 2 / pi * 360 ;
rotation[Y] = ( atanf( ( p2[Z] - p1[Z] )/( p2[X] - p1[X] ) ) ) / 2 / pi * 360 ;

i think it works so

cose these sin cos and tan functions uses rad where 360 degree are 2 * pi. That was my problem but now it works. Don''t now if i''m right but i make it the other way:
(sin((rotation[y])*2*pi/360)); and this works 100% but i don''t now what it''s in your case. Think about it and try. Good luck )

cu

Shadow
Oh, yeah, that''s actually already implemented in my code using a #define macro, but I forgot to include it. But, using arctan for both will provide the right results?

Morgan
hi
i thougt the a in atanf stands for cotangens, cose i dont know about this a but if it stands for radiant then you must write:

rotation[Z] = atanf( ( p2[X] - p1[X] )/( p2[Y] - p1[Y] ) ) ;
rotation[Y] = atanf( ( p2[X] - p1[X] )/( p2[Z] - p1[Z] ) ) ;

or not??

cu

Shadow

This topic is closed to new replies.

Advertisement