The Daily Click ::. Forums ::. Non-Klik Coding Help ::. c++ & angles
 

Post Reply  Post Oekaki 
 

Posted By Message

Zane



Registered
  09/09/2003
Points
  1183
4th October, 2004 at 12:51:28 -

heres my problem.
Im making a tank game in allegro, and i want the turret to always point towards the mouse pointer
i have a forumla to work out the angle, to rotate too, somthing like this:
a=pow(sin((y_dist / x_dist)/180),-1);

//Basically the same as
a=sin^-1(y_dist / x_dist)


unfortunatly, its not working.
dose anyone know the correct formula / another way to work out the angles (in c/c++ format)
thanks

edit: god damnit, you should really have an option to turn off smileys for a post

Image Edited by the Author.

 
www.klikforever.co.uk
GO THERE!!!

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
4th October, 2004 at 13:25:00 -

try atan2(abs(y1-y2),abs(x1-x2)) ... allegro should have its own function for this, but failing that just use the math.h one

I dunno how that formula is supposed to work but if you're sure its a real one then you're probably using the wrong type of angle measurement (sin() probably uses radians rather than degrees)



Image Edited by the Author.

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Long John Kickbag



Registered
  26/08/2002
Points
  148
4th October, 2004 at 14:13:03 -

Inverse Sine/ArcSine doesn't mean Sine^-1. That formula is wrong anyway (assuming the variables are named appropriately), use what Kris wrote (without the abs though).

Kris: Don't use abs() that'll prevent it getting the correct angle.

 
Resize! - www.clicksplat.com/comparison.html

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
4th October, 2004 at 14:24:19 -

whoops, yeah

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Zane



Registered
  09/09/2003
Points
  1183
4th October, 2004 at 15:13:51 -

ok thanks. ill try that soon

the formula is one off a maths website, i probably just missinterprited(eeek, how do you spell that) it.

Image Edited by the Author.

 
www.klikforever.co.uk
GO THERE!!!

Zane



Registered
  09/09/2003
Points
  1183
4th October, 2004 at 15:35:26 -

nope didnt work (this is kinda pissing me off).
the gun just twitched when i moved the mouse past it

Image Edited by the Author.

 
www.klikforever.co.uk
GO THERE!!!

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
4th October, 2004 at 15:40:36 -

are you checking your angle measurements like i said?

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Zane



Registered
  09/09/2003
Points
  1183
4th October, 2004 at 15:45:45 -

yup

 
www.klikforever.co.uk
GO THERE!!!

Kris

Possibly Insane

Registered
  17/05/2002
Points
  2017
4th October, 2004 at 16:32:35 -

dunno what else it could be, could you show your code?

 
"Say you're hanging from a huge cliff at the top of mt. everest and a guy comes along and says he'll save you, and proceeds to throw religious pamphlets at you while simultaniously giving a sermon." - Dustin G

Dogzer



Registered
  07/02/2011
Points
  1029
4th October, 2004 at 18:27:40 -

have you tried any other klik site to ask this c++ question? maybe they'll know

 
n/a

Lazernaut



Registered
  08/09/2002
Points
  1103

VIP MemberThe Cake is a LieIt's-a me, Mario!Wii OwnerPokemon Ball!
5th October, 2004 at 03:20:42 -

try the boards at cprogramming.com . They have a special section of their boards for game programmers.

 
n/a

Zane



Registered
  09/09/2003
Points
  1183
5th October, 2004 at 03:29:22 -

it worked
i used your was kris, it just hadent compiled properly.
thanks all

 
www.klikforever.co.uk
GO THERE!!!
   

Post Reply



 



Advertisement

Worth A Click