![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Aug 2005
Posts: 23
Rep Power: 0
![]() |
quick maths problem
So I have this game screen represented in the picture. I'm trying to have a gun turret (at the moment represented by the green triangle) follow the ship round the screen (the turret is stationary at 0,0, it just rotates by an angle). The problem being when the ship crosses the middle axis (represented by the arrow and question mark in the picture), the turret doesnt follow, probably because my co-ordinate system goes from -50 to +50.
The screen looks like this... And the code I have for generating the angle is this.. void Turret::setAngle(float x, float y)
{
angle = (atan(y/x)*(180/PI)+90);
}the x and y parameters passed in are the co-ordinates of the ship (so running from -50 to 50, at the point of the screenshot they are -40, -40). I take the inverse tan of the opposite/adjacent and convert to degress. +90 puts it in the right quadrant. How might I solve this simple problem so the turret follows all the way round the screen as oppose to just the left hand side? taa, |
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
Look up the atan2() function.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Aug 2005
Posts: 23
Rep Power: 0
![]() |
cheers managed to sort it
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|