Archived

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

help with my function

This topic is 5379 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

First of all get rid of that #define rubbish.

Secondly try using atan2(v2.y - v1.y, v2.x - v1.x) * 180.0 / PI.

Thirdly what are the types of the x and y members of Vector?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
well, if i were you i''d use inline functions instead of define.

Share this post


Link to post
Share on other sites
I think his point was more that you shouldn''t be working within your program in degrees and should get used to radians. If you have to display degrees then that isn''t really a choice, but the define does no type checking. You shouldn''t really use defines for substitution anymore. Constants, inlined functions and templates should be your first choices. Simply because there is more error checking and less chance of introducing subtile errors due to how the generated code is interpretted. It was just an uncharacteristically sharp way for Squid to say that. I really doubt he intended to be offensive, but rather meant it as constructive critism.

It is not an industry known for putting things delicately and you need only look at a fan forum for a newly released game to fully appreciate that fact. That is commercial software developed by highly skilled programmers being called a complete piece of crap that wasn''t worth the whole $50 someone spent on it. Five years with a staff of 40 and a budget in the millions and it wasn''t worth $50. So you ignore that, look for what their actual complaint is and try to figure out how to resolve the problem. It may just be a design decision you made and it simply a differance of opinion. Using defines is a prime example. If that is your preferance then go right ahead, but be aware there are alternatives with advantages over it. You may still prefer defines, but if you are aware then at least that is a decision you made.

Share this post


Link to post
Share on other sites
well hes just a dumass cos defines are beter than inline functions dumass
they are easier to write and even give yuo erroors when yuo get it wrong!~
so yuo shoud not talk about things not understood poppet

thank yuo

Share this post


Link to post
Share on other sites
As far as I know, the usual way to get an angle from two vector isn''t with atan but with acos.

First, normalize your vectors, then compute their dot product. Finally, compute the inverse cosinus of the dot product.

Although it''s not related directly to your problem, you should set the parameters of your function as references to avoid nasty copies and make the function inline.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by YodaTheCoda
why does this not gi ve me the angle?


What angle is "the" angle? The angle you calculate is the angle between the positive x-axis and the vector (v2-v1). If this is not the angle you want then that is the reason you don''t get it.

Share this post


Link to post
Share on other sites
The way to find the angle (as already suggested by MDI and Prosper/LOADED) is:

  angle = acos( Dot( v1, v2 ) / ( Length(v1)*Length(v2) ) );  


Atan is a 2D fuction. You can use it in 3D, but it is very complicated.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Yuo shood not tok about things yuo cannot spel dumass

Share this post


Link to post
Share on other sites
YodaTheCoda is a troll.
He''s winding you all up, look at his profile for his past posts (he keeps telling beginners all C++ is compiled to Cobol and then to Assembly, for one).

Share this post


Link to post
Share on other sites
I''m closing this thread for the following reasons:

1) Without a better explanation of the desired angle I believe the problem has been properly solved by Prosper/LOADED, MDI, and Jambolo.

2) This thread is getting a bit out of hand. Any discussion of coding practices should happen in the general programming forum or the lounge.


Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites

This topic is 5379 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.

Guest
This topic is now closed to further replies.