Jump to content
  • Advertisement
Sign in to follow this  
jrmiller84

Problem With Angles

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

Hey guys, I've got a rather easy question for all of you veterans out there. I finally got all of my classes set up for my pong game but I am having a tough time working out the equations to effectively pass an angle to a function and have it generate the change in x and y (slope I presume) for my vertices. I bought a book on game physics, but it starts out a little further than this basic concept. Couldnt find anything on google either about converting angles to slope. Any help I can get would be greatly appreciated. Thanks everyone.

Share this post


Link to post
Share on other sites
Advertisement
Hmm, ive tried that and I must be doing something wrong. Here's the line of code I am using:

Rect->Set_Position(Rect->myX plus (float) cos(90), Rect->myY plus (float) sin(90));


Change the word plus to a plus sign, for some reason it filtered that character. If I understand this correctly, depending on which way the coordinates of the screen are oriented with angles, it should go either straight up, down, left or right. It actually did none of those, it went in sort of a south south west angle. I could be doing something completely wrong. Oh BTW, the Set_Position function takes two arguements, x and y and in that order. This just sets the position of the object. Thanks guys.

Share this post


Link to post
Share on other sites
c++ math functions work with radians, not degrees. (I assume this is c++.)

Also, although +'s are for some reason filtered in the preview, they actually show up in the post :-)

Share this post


Link to post
Share on other sites
That works, awesome! I tried finding some documentation on the cos and sin methods but was short on information. I was about to pull my hair out. Thanks a million.

Just as reference for others in the future:

1 degree = 0.0174532925 Radians

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
macros suck

Share this post


Link to post
Share on other sites
Although I don't see any way that specific macro could be bad (I'm sure the gurus will find some) I prefer to multiply by:
const float DegToRadf = whatever

Share this post


Link to post
Share on other sites
Quote:

#define fPI 3.14156f
#define fDEG2RAD(a) ((a)*fPI/180.0f)
#define fRAD2DEG(a) ((a)*180.0f/fPI)

#define dPI 3.14156
#define dDEG2RAD(a) ((a)*dPI/180.0)
#define dRAD2DEG(a) ((a)*180.0/dPI)

If you used 180, it would cast the answer to an integer.
Does this mean I'm a finally a guru? =)

Share this post


Link to post
Share on other sites
Sign in to follow this  

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