Skip to main content
gamedev.net
🔒 Locked

Problem With Angles

Started by jrmiller84 Aug 28, 2005 at 8:25 PM 9 replies 1k views
Original Post
jrmiller84
jrmiller84
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.
I will forever be a student.
chaosgame
chaosgame
where Ø is the angle
∆X=cos(Ø)∆Y=sin(Ø)
"Are you threatening me, Master Jedi?" - Chancellor Palpatine
jrmiller84
jrmiller84
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.
I will forever be a student.
Zakwayda
Zakwayda
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 :-)
jrmiller84
jrmiller84
Ahhh, I bet that's what I'm doing wrong. Let me try that out and I'll let you know what happens. Thanks!
I will forever be a student.
jrmiller84
jrmiller84
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
I will forever be a student.
DvDmanDT
DvDmanDT
#define DEG2RAD(a) ((a)*PI/180)
#define RAD2DEG(a) ((a)*180/PI)
dyerseve
dyerseve
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
the_dannobot
the_dannobot
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? =)

Sneftel
Sneftel
In this instance, the type coercion happens to work out okay (except for certain very large, unusual, and well-chosen angles). That's purely a matter of luck, though.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.