<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>angles | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/tag/angles/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Wed, 01 Jul 2020 19:36:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>angles | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Thrusting in different directions</title>
		<link>https://learncgames.com/thrusting-in-different-directions/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=thrusting-in-different-directions</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Mon, 06 Jul 2020 23:00:06 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Ebook]]></category>
		<category><![CDATA[Excerpt]]></category>
		<category><![CDATA[angles]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=945</guid>

					<description><![CDATA[<p>When you press the control key, the player&#8217;s ship will accelerate in whatever direction (0-23) it is facing. To make this possible, I pre-populated a couple of float arrays with values x and y for thrust in any of the 24 directions. This function populate the two arrays. These are declared as float thrustx[24]; float [&#8230;]</p>
The post <a href="https://learncgames.com/thrusting-in-different-directions/">Thrusting in different directions</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:636,&quot;href&quot;:&quot;https:\/\/pixabay.com\/users\/dognamedseven-1619308\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1034657&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:637,&quot;href&quot;:&quot;https:\/\/pixabay.com\/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1034657&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260205102120\/https:\/\/pixabay.com\/?utm_source=link-attribution&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 17:03:33&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-09 22:43:15&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-21 05:41:42&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-31 00:00:18&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-03 19:46:00&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-08 06:34:22&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-12 09:32:39&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-16 11:11:02&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-20 08:07:59&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-20 08:07:59&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;}]'></div>
<figure id="attachment_948" aria-describedby="caption-attachment-948" style="width: 300px" class="wp-caption alignleft"><img fetchpriority="high" decoding="async" class="size-medium wp-image-948" src="https://learncgames.com/wp-content/uploads/2020/07/math-1034657_640-300x284.png" alt="Trigonometry" width="300" height="284" srcset="https://learncgames.com/wp-content/uploads/2020/07/math-1034657_640-300x284.png 300w, https://learncgames.com/wp-content/uploads/2020/07/math-1034657_640.png 640w" sizes="(max-width: 300px) 100vw, 300px" /><figcaption id="caption-attachment-948" class="wp-caption-text">Image by <a href="https://pixabay.com/users/dognamedseven-1619308/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1034657">dognamedseven</a> from <a href="https://pixabay.com/?utm_source=link-attribution&amp;utm_medium=referral&amp;utm_campaign=image&amp;utm_content=1034657">Pixabay</a></figcaption></figure>
<p>When you press the control key, the player&#8217;s ship will accelerate in whatever direction (0-23) it is facing. To make this possible, I pre-populated a couple of float arrays with values x and y for thrust in any of the 24 directions.</p>
<p>This function populate the two arrays. These are declared as</p>
<pre><code class="language-c" data-line="">float thrustx[24];
float thrusty[24];

void InitThrustAngles() {
    const float pi = 3.14159265f;
    const float degreeToRad = pi / 180.0f;
    float degree = 0.0f;
    for (int i = 0; i&lt;24; i++) {
        float radianValue = degree * degreeToRad;
        thrustx[i] = (float)sin(radianValue);
        thrusty[i] = (float)-cos(radianValue);
        degree += 15;
    }
}</code></pre>
<p>It uses trigonometry to calculate the horizontal and vertical amounts for any of the angles 0,15,30..345 degrees. As sin and cos functions work in radians rather than degrees, the variable radianValue is calculated from the degree angle by multiplying by the value degreesToRad. If you remember your school trigonometry, one radian = 180/pi degrees. So the code divides by this value (or multiplies by its inverse in this case).</p>
<p>Then when you press the control key, it just adds the appropriate thrustx and thrusty value to the vx and vy variables. Simple and fast.</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/thrusting-in-different-directions/">Thrusting in different directions</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">945</post-id>	</item>
	</channel>
</rss>
