Jump to content
  • Advertisement

Archived

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

YodaTheCoda

help with my function

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


    
#define ToDegree(x) ((x) * (180.0f / PI))
float Angle(Vector v1, Vector v2)
{
	return ToDegree(atanf((v2.y-v1.y)/(v2.x-v1.x)));
}
    
why does this not gi ve me the angle?

Share this post


Link to post
Share on other sites
Advertisement
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
i am grateful for yuor help kind suirs
however i am compeled to point out that define is not rubish! it is very acuiesent in reusing code sizeas

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

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

  • 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!