<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Rotating image in relation to mouse x and y</title>
		<link>http://www.allegro.cc/forums/view/586625</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 27 Jul 2006 03:24:51 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Im trying to rotate a gun so its always pointing towards the cursor.  im sortof limited in physics..  i figured i needed to use the tan function which is opposite over adjacent to find that angle. (y would be the opposite and the x would be the adjacent).  but its really not working out.  is there some other function that i need to get this working.  thanks for any help.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dothedru22)</author>
		<pubDate>Sun, 23 Jul 2006 06:56:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><span class="source-code"><a href="http://www.delorie.com/djgpp/doc/libc/libc_50.html" target="_blank">atan2</a></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Matthew Leverton)</author>
		<pubDate>Sun, 23 Jul 2006 07:05:48 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>not really giving the desired effect.  it sortof just stops when the cursor gets above the gun..which i guess is right because the angle is zero.. im also getting pretty bad movement becasue for some reason it has to be a fixed type.  i have to type cast the variable.  its sortof wierd..</p><p>if i do it as float or double i dont get any movement.</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">void</span> D_UpdateDraw<span class="k2">(</span>Player_S<span class="k3">*</span> p , <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span> b<span class="k2">)</span> <span class="k2">{</span>
     p-&gt;angle <span class="k3">=</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_50.html" target="_blank">atan2</a><span class="k2">(</span><span class="k1">float</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/mouse_y" target="_blank"><span class="a">mouse_y</span></a><span class="k2">)</span> , <span class="k1">float</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/mouse_x" target="_blank"><span class="a">mouse_x</span></a><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>

  <span class="k1">if</span> <span class="k2">(</span>p-&gt;keyCheck <span class="k3">=</span><span class="k3">=</span> D_KEYRIGHT<span class="k2">)</span> <span class="k2">{</span>
    
    <a href="http://www.allegro.cc/manual/draw_sprite" target="_blank"><span class="a">draw_sprite</span></a><span class="k2">(</span>b , p-&gt;playerImg , p-&gt;x <span class="k3">+</span><span class="k3">=</span> p-&gt;velX , p-&gt;y <span class="k3">+</span><span class="k3">=</span> p-&gt;velY<span class="k2">)</span><span class="k2">;</span>
  <span class="k2">}</span>
  <span class="k1">else</span> <span class="k2">{</span>
    <a href="http://www.allegro.cc/manual/draw_sprite_h_flip" target="_blank"><span class="a">draw_sprite_h_flip</span></a><span class="k2">(</span>b , p-&gt;playerImg , p-&gt;x <span class="k3">+</span><span class="k3">=</span> p-&gt;velX , p-&gt;y <span class="k3">+</span><span class="k3">=</span> p-&gt;velY<span class="k2">)</span><span class="k2">;</span>
  <span class="k2">}</span>
  <a href="http://www.allegro.cc/manual/rotate_sprite" target="_blank"><span class="a">rotate_sprite</span></a><span class="k2">(</span>b , p-&gt;gunImg , p-&gt;x <span class="k3">+</span> <span class="n">22</span> , p-&gt;y <span class="k3">+</span> <span class="n">20</span> , <a href="http://www.allegro.cc/manual/itofix" target="_blank"><span class="a">itofix</span></a><span class="k2">(</span>p-&gt;angle<span class="k2">)</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//gun</span>

  <a href="http://www.allegro.cc/manual/circle" target="_blank"><span class="a">circle</span></a><span class="k2">(</span>b , <a href="http://www.allegro.cc/manual/mouse_x" target="_blank"><span class="a">mouse_x</span></a> , <a href="http://www.allegro.cc/manual/mouse_y" target="_blank"><span class="a">mouse_y</span></a> , <span class="n">2</span> , WHITE<span class="k2">)</span><span class="k2">;</span>  <span class="c">//cursor           </span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dothedru22)</author>
		<pubDate>Sun, 23 Jul 2006 19:48:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The angle returned by atan2() is in radians. rotate_sprite wants fixed point 256 degree angles.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Sun, 23 Jul 2006 22:48:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>oh aight thanks.  if anybody has ever played madness interactive i sortof want to do somethign like that..where the gun rotates around the center of the body.  thats sortofg what im trying to do.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (dothedru22)</author>
		<pubDate>Thu, 27 Jul 2006 02:45:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This might help. It&#39;s targetted at Flash, but code is code, and maths is maths <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p><a href="http://www.codylindley.com/Tutorials/trigonometry/">http://www.codylindley.com/Tutorials/trigonometry/</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Thu, 27 Jul 2006 03:24:51 +0000</pubDate>
	</item>
</rss>
