Hey, we started trigonometry in math this year. I sat down a few days ago and created a function calculating the angle, in degrees(0-360), from one point to another. I have tested my function thoroughly(in all "4 main directions"), and it seems to work. I started thinking about using this for direction of objects in games and I wondered what is the best way to go about doing this with SDL's coordinate system.
I made a simple drawing to kinda illustrate my question:
It's natural for me to think that 90 degrees is straight up, 0 is straight to the right, 135 is diagonally up to the left, 270 is straight down and so on. Should I translate the angle(in degrees) in my function so that 90 is in fact straight up( on-screen ) or should I keep it as it is, 90 = straight down, higher y value?
Degrees with SDL coordinate system
Moderator: Coders of Rage
- Sanshin77
- Chaos Rift Regular
- Posts: 160
- Joined: Tue Mar 10, 2009 9:36 am
- Current Project: C++/SDL engine, zaActionWizardMagic game
- Favorite Gaming Platforms: Xbox 360, Playstation 2, Nintendo DS, mac and PC
- Programming Language of Choice: C++
Degrees with SDL coordinate system
Check out videos of my C++ games as well as my "Amateur Game Dev" series over at
My YouTube Channel: http://www.youtube.com/user/Zanchill
My YouTube Channel: http://www.youtube.com/user/Zanchill
- xiphirx
- Chaos Rift Junior
- Posts: 324
- Joined: Mon Mar 22, 2010 3:15 pm
- Current Project: ******** (Unkown for the time being)
- Favorite Gaming Platforms: PC
- Programming Language of Choice: C++
- Contact:
Re: Degrees with SDL coordinate system
I would suggest that you make it so it seems natural to you...
So, going up would mean an angle of 90.
So, going up would mean an angle of 90.
StarCraft II Zerg Strategy, open to all levels of players!
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
Looking for paid work :< Contact me if you are interested in creating a website, need a web design, or anything else you think I'm capable of
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: Degrees with SDL coordinate system
I, personally, would be consistent with the unit circle.
Re: Degrees with SDL coordinate system
Agree.GyroVorbis wrote:I, personally, would be consistent with the unit circle.
So, just treat it the same as a Cartesian coordinate system, with the exception of an inverted y-axis.
So, if you want a projectile to fly NorthEast in SDL, I'd make my calls something like this:
Code: Select all
bullet.y+= sin( (-1)*(45) ) * bull.speed;
bullet.x+= cos( 0 ) * bullet.speed;
Code: Select all
bullet.y+= sin( (-1)*(bullet.direction) ) * bull.speed;
bullet.x+= cos( bullet.direction ) * bullet.speed;
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
- short
- ES Beta Backer
- Posts: 548
- Joined: Thu Apr 30, 2009 2:22 am
- Current Project: c++, c
- Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
- Programming Language of Choice: c, c++
- Location: Oregon, US
Re: Degrees with SDL coordinate system
when doing this just remember how computationally expensive sin and cos really are..
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
link: https://github.com/bjadamson
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Degrees with SDL coordinate system
Why use angles when you can use vectors? Yes, it could be an option to generate a vector at a certain angle, but other than that, there is little to no advantage (and plenty of disadvantages - mainly that trig is so expensive to calculate) that comes from using angles over vectors. I mean, it's cool and all, but it's not really a good idea in the long run.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
- Sanshin77
- Chaos Rift Regular
- Posts: 160
- Joined: Tue Mar 10, 2009 9:36 am
- Current Project: C++/SDL engine, zaActionWizardMagic game
- Favorite Gaming Platforms: Xbox 360, Playstation 2, Nintendo DS, mac and PC
- Programming Language of Choice: C++
Re: Degrees with SDL coordinate system
Sorry for not replying, my comp. was at repair for like a month (stupid ash-cloud preventing part transport) and now I had exams, so I haven't been around or devved a lot.
Yeah, I actually have a good system working with vectors now, I saw your reply and changed my mind. This will be featured in my next youtube video, the 4th episode of my Amateur Game Dev series, along with some simple collision/physics... :DGinto8 wrote:Why use angles when you can use vectors? Yes, it could be an option to generate a vector at a certain angle, but other than that, there is little to no advantage (and plenty of disadvantages - mainly that trig is so expensive to calculate) that comes from using angles over vectors. I mean, it's cool and all, but it's not really a good idea in the long run.
Check out videos of my C++ games as well as my "Amateur Game Dev" series over at
My YouTube Channel: http://www.youtube.com/user/Zanchill
My YouTube Channel: http://www.youtube.com/user/Zanchill