<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Rotating Cube Problem</title>
		<link>http://www.allegro.cc/forums/view/618641</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 08 Apr 2022 04:09:15 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi all:</p><p>  Please find above files I have been working on. The file cube_test2 shows</p><p>a 3D cube rotating right of center. Here is my problem: I want the cube to</p><p>rotate as shown but also to rotate around the center of the screen. The file</p><p>cube_test1 shows one rotating but that is all I could do with it. If anyone</p><p>could take a look at my files and show me what to do I would appreciate it.</p><p>3D rotation is a bear and I could use some help, Thanks and have a great day!</p><p>This was done using Linux.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Scooter)</author>
		<pubDate>Wed, 06 Apr 2022 00:35:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><span class="k1">float</span> dist <span class="k3">=</span> <span class="n">14</span>.<span class="n">0</span><span class="k2">;</span>  <span class="c">//distance from origin</span>
...
glTranslatef<span class="k2">(</span>dist, <span class="n">0</span>, <span class="k3">-</span><span class="n">45</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
It&#39;s to the right because you translated it to the right. Set it to 0 if you want in the center. Or maybe I misunderstood the problem.</p><p>Rotation basics:<br />1. determine a point of center of rotation (x, y, z)<br />2. Translate all vertices of cube so that point (From step 1) is now at 0,0,0 (vec[i].x -= x, vec[i].y -= y, vec[i].z -= z)<br />3. Rotate all vertices<br />4. Inverse translate all vertices (vec[i].x += x, vec[i].y += y, vec[i].z += z)</p><p>If your cube is already at center then no need for translation.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Wed, 06 Apr 2022 01:18:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>We’ve been here before and I provided full code…
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dizzy Egg)</author>
		<pubDate>Wed, 06 Apr 2022 04:15:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Dizzy:</p><p>  I have absolutely no idea what you are talking about. If you are insinuating</p><p>this is a duplicate post you are dead wrong. I have NEVER posted this problem</p><p>before. Please provide proof. In the future please get your facts straight</p><p>before replying to my post. Thank you kindly for my consideration!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Scooter)</author>
		<pubDate>Wed, 06 Apr 2022 16:17:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><a href="https://www.allegro.cc/forums/thread/618420">Rubik Cube</a></p><p>You already had it rotating in the centre.</p><p>And you&#39;re still using 7 bitmaps instead of 6.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dizzy Egg)</author>
		<pubDate>Wed, 06 Apr 2022 19:35:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hey Dizzy:</p><p>    I see you will never forget I made a mistake! Big deal! Actually you are wrong</p><p>again! It was 5 and should have been 6! Can&#39;t believe you forgot that! Especially</p><p>since you have never made a mistake! Please read my post carefully! I told you this</p><p>was different and it is!</p><p>    The cube is NOT supposed to be in the center! Oh my! Could that be the reason</p><p>it is plotted 14 units right of center? Could very well be that is where I intend</p><p>it to be! So at the center of the screen if you would draw a circle 28 units in</p><p>diameter you would find that the circle would be drawn thru the center of the</p><p>rotating 3D cube. That circle is the path that I want the ROTATING cube to follow.</p><p>That&#39;s all it is to it! Being you think I am so STUPID, I could NOT find a way to</p><p>solve the problem. I hate to admit to you that I need help with it! I waited days</p><p>before I posted this because when I do, I always regret it! Sometimes it is </p><p>necessary! I am very sorry about that! Have a great day!!!!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Scooter)</author>
		<pubDate>Wed, 06 Apr 2022 21:17:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, take a breath. Count to 10.</p><p>Scooter, if what I said didn&#39;t work, draw a picture so I have a better understanding of what the problem is.</p><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/618641/1052042#target">Scooter</a> said:</div><div class="quote"><p>I want the cube to rotate as shown</p></div></div><p>

Nothing was shown. I don&#39;t really understand the problem.</p><p>Like I said before: If the origin is not the center of rotation then find the point at the center of rotation (x, y, z). Everything that you want to be rotated will need to be translated (-= x, -= y, -=z). Now that center of rotation is at the origin. Do the rotation. Translate everything back the inverse amount (+= x, += y, += z).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Wed, 06 Apr 2022 22:34:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi DanielH:</p><p>   Thanks for the reply and an offer to help me. If you ran cube_test2 file</p><p>you should see a 3D cube rotating on the left side of the screen. This file</p><p>was part of a zip file. Hope you are with me so far. This rotating 3D cube is</p><p>located 14 units to the direct left of screen center (0, 0, 0). This is what</p><p>you should be looking at right now, nothing else. Now go back to (0, 0, 0) at</p><p>screen center. At this point draw, in your mind, a circle 28 units in diameter.</p><p>This circle will pass directly thru the center of the 3D rotating cube. This</p><p>is the path I want the 3D rotating cube to follow around the center of the</p><p>screen. The 3D cube is ALWAYS rotating. Hope this helps, but if something is</p><p>NOT clear, please let me know and I will be happy to fix an image for you.</p><p>Thanks for your time. Have a great day!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Scooter)</author>
		<pubDate>Thu, 07 Apr 2022 01:34:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So if I understand you correctly, you want the cube to rotate around itself, and you also want the cube to move along a circular path?</p><p>Without looking at your code, it appears that the rotating-around-itself-bit does already work the way you want it to.<br />You also seem to have managed translating the center of the cube while maintaining the rotating-around-itself-bit.</p><p>What&#39;s missing now is to move the center-translation around on a circular path. Correct?</p><p>For the future, the likelihood of quickly receiving helpful answers increases with how easy it is to grasp your problem. A picture/sketch of what you&#39;re trying to accomplish, and probably a screenshot of your actually running application (that outlines the difference).</p><p>That being said, everyone makes mistakes; there&#39;s no shame in admitting you&#39;re stuck and in asking for help. The community here usually goes overboard in providing aid.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Indeterminatus)</author>
		<pubDate>Thu, 07 Apr 2022 02:02:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi Indeterminatus:</p><p>   You are correct. Please check out file cube_test2. This will show where I am</p><p>at this time. Translating the rotating cube around the circle path is what I am</p><p>having a problem with. I have tried everything I can think to do but no go. I</p><p>tried using two timers with two different angle variables but codeblocks would</p><p>would not compile it. I tried a separate loop for translating around the </p><p>circular path but again a no go. I think one of these two is probably the </p><p>answer. </p><p>I have been working on this for quite some time and finally decided I was not</p><p>going to figure this out myself. If you still need an image let me know.</p><p>Thanks for your time and have a great day.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Scooter)</author>
		<pubDate>Thu, 07 Apr 2022 16:31:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The attached file will get you started. It rotates the cube around itself, and also around a circle in the centre.</p><p>If you want to increase the size of the circle, you can increase the values:</p><div class="source-code snippet"><div class="inner"><pre>    <span class="k1">double</span> x <span class="k3">=</span> <span class="n">1</span>.<span class="n">0</span> <span class="k3">*</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_113.html" target="_blank">cos</a><span class="k2">(</span>radius<span class="k2">)</span><span class="k2">;</span> <span class="c">//Increase 1.0 for bigger circle</span>
    <span class="k1">double</span> y <span class="k3">=</span> <span class="n">1</span>.<span class="n">0</span> <span class="k3">*</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_113.html" target="_blank">cos</a><span class="k2">(</span>radius<span class="k2">)</span><span class="k2">;</span> <span class="c">//Increase 1.0 for bigger circle</span>
</pre></div></div><p>

on lines 312, 313.</p><p>To change the speed increase/decrease the line <span class="source-code">alpha <span class="k3">+</span><span class="k3">=</span> <span class="n">0</span>.<span class="n">05</span></span> on line 308.</p><p>The deltaX and deltaY positions (used in the translate) are calculated using the cosine function, which uses the radius and the alpha (0-360):</p><div class="source-code snippet"><div class="inner"><pre>    <span class="k1">double</span> x <span class="k3">=</span> <span class="n">1</span>.<span class="n">0</span> <span class="k3">*</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_113.html" target="_blank">cos</a><span class="k2">(</span>radius<span class="k2">)</span><span class="k2">;</span>
    <span class="k1">double</span> y <span class="k3">=</span> <span class="n">1</span>.<span class="n">0</span> <span class="k3">*</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_113.html" target="_blank">cos</a><span class="k2">(</span>radius<span class="k2">)</span><span class="k2">;</span>
    <span class="k1">double</span> deltaX <span class="k3">=</span> x <span class="k3">*</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_113.html" target="_blank">cos</a><span class="k2">(</span>alpha<span class="k2">)</span> <span class="k3">-</span> x <span class="k3">*</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_728.html" target="_blank">sin</a><span class="k2">(</span>alpha<span class="k2">)</span><span class="k2">;</span>
    <span class="k1">double</span> deltaY <span class="k3">=</span> y <span class="k3">*</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_113.html" target="_blank">cos</a><span class="k2">(</span>alpha<span class="k2">)</span> <span class="k3">+</span> y <span class="k3">*</span> <a href="http://www.delorie.com/djgpp/doc/libc/libc_728.html" target="_blank">sin</a><span class="k2">(</span>alpha<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>


It works as expected, but you&#39;d probably want to clean it up, create proper methods or timers, but should be enough to get you started.</p><p>I&#39;m sure someone else can provide a more elegant solution.</p><p>[EDIT] actually no need for a timer, you can control the speed by increasing/decreasing the amount you add to alpha.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dizzy Egg)</author>
		<pubDate>Thu, 07 Apr 2022 19:54:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There are easier ways to do this. Ones that don&#39;t involve moving or rotating the cube at all. Do it with transformations.</p><p>First step to a 3D scene is the projection matrix and the camera matrix.</p><p>If you have both of those, then setup your view matrix and alter like so for the cube :</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><a href="http://www.allegro.cc/manual/ALLEGRO_TRANSFORM"><span class="a">ALLEGRO_TRANSFORM</span></a> old <span class="k3">=</span> <span class="k3">*</span><a href="http://www.allegro.cc/manual/al_get_current_transform"><span class="a">al_get_current_transform</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  2</span>
<span class="number">  3</span><a href="http://www.allegro.cc/manual/ALLEGRO_TRANSFORM"><span class="a">ALLEGRO_TRANSFORM</span></a> t<span class="k2">;</span>
<span class="number">  4</span><a href="http://www.allegro.cc/manual/al_identity_transform"><span class="a">al_identity_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>t<span class="k2">)</span>
<span class="number">  5</span><span class="c">/// We are at the camera. To move or rotate the world, we need to translate and then scale or rotate, and then translate back.</span>
<span class="number">  6</span>
<span class="number">  7</span>al_translate_transform_3d<span class="k2">(</span><span class="k3">&amp;</span>t , <span class="k3">-</span>cubex , <span class="k3">-</span>cubey , <span class="k3">-</span>cubez<span class="k2">)</span><span class="k2">;</span><span class="c">/// This centers the view on our cube</span>
<span class="number">  8</span>al_rotate_transform_3d<span class="k2">(</span><span class="k3">&amp;</span>t , <span class="n">1</span>.<span class="n">0</span> , <span class="n">0</span> , <span class="n">0</span>.<span class="n">0</span> , <span class="n">360</span>.<span class="n">0</span><span class="k3">*</span>M_PI<span class="k3">/</span><span class="n">2</span>.<span class="n">0</span><span class="k3">*</span><span class="n">60</span>.<span class="n">0</span><span class="k2">)</span><span class="k2">;</span><span class="c">/// This will spin your cube around the x axis</span>
<span class="number">  9</span>al_translate_transform_3d<span class="k2">(</span><span class="k3">&amp;</span>t , <span class="k3">-</span><span class="n">14</span> , <span class="n">0</span> , <span class="n">0</span><span class="k2">)</span><span class="k2">;</span><span class="c">/// This moves our cube 14 left</span>
<span class="number"> 10</span>al_rotate_transform_3d<span class="k2">(</span><span class="k3">&amp;</span>t , <span class="n">1</span>.<span class="n">0</span> , <span class="n">0</span> , <span class="n">0</span> , radians around <a href="http://www.allegro.cc/manual/circle"><span class="a">circle</span></a><span class="k2">)</span><span class="k2">;</span><span class="c">/// This will move our cube in a circle</span>
<span class="number"> 11</span>al_translate_transform_3d<span class="k2">(</span><span class="k3">&amp;</span>t , <span class="n">14</span> , <span class="n">0</span> , <span class="n">0</span><span class="k2">)</span><span class="k2">;</span><span class="c">/// This moves the camera back</span>
<span class="number"> 12</span>al_translate_transform_3d<span class="k2">(</span><span class="k3">&amp;</span>t , cubex , cubey , cubez<span class="k2">)</span><span class="k2">;</span><span class="c">/// This moves the camera back to its original place</span>
<span class="number"> 13</span><a href="http://www.allegro.cc/manual/al_use_transform"><span class="a">al_use_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>t<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span><span class="c">/// Draw cube</span>
<span class="number"> 15</span><a href="http://www.allegro.cc/manual/al_use_transform"><span class="a">al_use_transform</span></a><span class="k2">(</span><span class="k3">&amp;</span>old<span class="k2">)</span><span class="k2">;</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Thu, 07 Apr 2022 21:24:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;d be tempted to follow Edgars advice, as his knowledge of this stuff is greater than mine.</p><p>To give you options for playing around though, I&#39;ve updated the attached version with a function you can call (just above draw_scene) that lets you rotate the cube by sending a circle size and speed.</p><p>Have fun!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dizzy Egg)</author>
		<pubDate>Thu, 07 Apr 2022 22:10:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi Dizzy:</p><p>   Thanks, absolutely beautiful! Works fine! I agree, Edgar has this figured</p><p>out completely! You are also good at this, much better than I am.</p><p>Thanks again and please forgive me for my actions!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Scooter)</author>
		<pubDate>Fri, 08 Apr 2022 00:13:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You’re welcome, and no need for forgiveness, it was me that was in the wrong!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Dizzy Egg)</author>
		<pubDate>Fri, 08 Apr 2022 04:09:15 +0000</pubDate>
	</item>
</rss>
