| View previous topic :: View next topic |
| Author |
Message |
paupav Master Cheater
Reputation: 13
Joined: 15 Apr 2011 Posts: 314 Location: P. Sherman 42, Wallaby Way, Sydney
|
Posted: Mon Nov 23, 2015 12:47 pm Post subject: basic math problem |
|
|
so, I'm making a game in which player should rotate depending on where the cursor is placed.
In multimedia library that I'm using its asking for how much degrees it wants to rotate and that's where my problem is.
| Code: | click1Pos.x = (int)sf::Mouse::getPosition(cliff->window).x;
click1Pos.y = (int)sf::Mouse::getPosition(cliff->window).y;
moveToCursor = true;
double one = playerYposition - mouseYposition;
double two = playerX - mouseXposition;
double tanges = (tan(one/two)* RAD);
player1.setRotation(tanges);
|
for some reason it isn't working properly
|
|
| Back to top |
|
 |
panraven Grandmaster Cheater
Reputation: 62
Joined: 01 Oct 2008 Posts: 958
|
Posted: Mon Nov 23, 2015 1:38 pm Post subject: |
|
|
I guess, at least
| Code: | double tanges = (tan(one/two)* RAD);
//should be?
double tanges = (atan(one/two)* RAD); // atan is inverse of tan,ie. tan(angle)==ydiff/xdiff => atan(ydiff/xdiff)==angle |
and atan should already give radian unit (-pi<->pi, instead of -180<->180)??,
unless RAD mean RAD2DEGREE and setRotation accept degree unit instead of radian.
_________________
- Retarded. |
|
| Back to top |
|
 |
paupav Master Cheater
Reputation: 13
Joined: 15 Apr 2011 Posts: 314 Location: P. Sherman 42, Wallaby Way, Sydney
|
Posted: Tue Nov 24, 2015 7:28 am Post subject: |
|
|
| panraven wrote: | I guess, at least
| Code: | double tanges = (tan(one/two)* RAD);
//should be?
double tanges = (atan(one/two)* RAD); // atan is inverse of tan,ie. tan(angle)==ydiff/xdiff => atan(ydiff/xdiff)==angle |
and atan should already give radian unit (-pi<->pi, instead of -180<->180)??,
unless RAD mean RAD2DEGREE and setRotation accept degree unit instead of radian. |
RAD means RAD2DEGREE and setRotation accepts degree units.
thank you, that was the problem
|
|
| Back to top |
|
 |
|