Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 9th, 2005, 5:11 PM   #1
Konnor
Newbie
 
Join Date: Aug 2005
Posts: 23
Rep Power: 0 Konnor is on a distinguished road
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,
Konnor is offline   Reply With Quote
Old Dec 9th, 2005, 6:27 PM   #2
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Look up the atan2() function.
grumpy is offline   Reply With Quote
Old Dec 10th, 2005, 1:02 PM   #3
Konnor
Newbie
 
Join Date: Aug 2005
Posts: 23
Rep Power: 0 Konnor is on a distinguished road
cheers managed to sort it
Konnor is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:35 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC