Archived

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

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.

Recommended Posts


#define ToDegree(x) ((x) * (180.0f / PI))
float Angle(Vector v1, Vector v2)
{
}

why does this not gi ve me the angle?

Share on other sites
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 on other sites
It might just be giving you a reference angle instead of the true angle.

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 on other sites
well, if i were you i''d use inline functions instead of define.

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 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 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 on other sites
Well, correct that last comment I made. You certainly seem inclined to give a person a reason to be insulting.

Share on other sites
Use:

A . B = |A| x |B| cos Theta

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.

This topic is now closed to further replies.

1. 1
Rutin
19
2. 2
3. 3
JoeJ
15
4. 4
5. 5

• 18
• 19
• 10
• 13
• 17
• Forum Statistics

• Total Topics
631694
• Total Posts
3001751
×