<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Need help calculating a frustum with a fixed centralized plane</title>
		<link>http://www.allegro.cc/forums/view/618642</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 10 Apr 2022 17:34:49 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What’s working:</p><p>So I have a basic tile map that is 25 tiles across and 15 tiles high.  The tiles themselves are 16x16 pixels making the full size of the tilemap 400x240 in pixels.  On a display that is always assumed to be 1920x1080, that 400x240 tilemap is scaled up by 4.8 x 4.5 in order to fill the screen (with some negligible distortion).</p><p>Problem:</p><p>The above works for a 2D projection, however, I want this arrangement to exist within a 3D projection, such that other tilemaps can be drawn at different levels of depth, in front of the main tile map and/or behind it.</p><p>Most importantly, I’d like to be able to flexibly experiment with the depth of field, (and possibly the positions of the near and far planes), while still having the primary 400x240px tile map set in a fixed position and not have it distort as depth of field is being changed.  Also, being able to “zoom in” to different scales than 4.8 x 4.5 would be a good feature, if I wanted to add focusing effects on certain parts of the action on the tile map.</p><p>As an example, I found this picture online and, as an analogy, you might imagine the z plane is in the position where the dimensions are always fixed at 1920x1080 regardless of the change in depth of field, near and far planes:</p><p><span class="remote-thumbnail"><span class="json">{"name":"613166","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/d\/6df9ab1a817e10d51c3d8f2a49935e4f.jpg","w":405,"h":203,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/d\/6df9ab1a817e10d51c3d8f2a49935e4f"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/6/d/6df9ab1a817e10d51c3d8f2a49935e4f-240.jpg" alt="613166" width="240" height="120" /></span>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Fri, 08 Apr 2022 01:54:57 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Does this help at all?</p><p><a href="https://liballeg.org/a5docs/trunk/transformations.html#al_perspective_transform">https://liballeg.org/a5docs/trunk/transformations.html#al_perspective_transform</a></p><p>Or perhaps you should take a look at a tutorial on using glFrustum.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Fri, 08 Apr 2022 19:49:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmm, not sure if I understand correctly. <br />I think I hacked together something related to have animation effects (rotation around X / Y axes) in lgui tests / demo:</p><p><a href="https://github.com/frank256/lgui/blob/develop/src/tests/lguitest.cpp#L254">https://github.com/frank256/lgui/blob/develop/src/tests/lguitest.cpp#L254</a></p><p>Note sure if I did it the &quot;correct&quot; way, but basically it puts the usual 2D screen on a plane on z=0 within a frustum so that you can draw as you would in 2D, however, different Z coordinates lead to some (slight) perspective effects.</p><p>It&#39;s been a while, would need to wrap my head around it again.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (frank.n)</author>
		<pubDate>Sat, 09 Apr 2022 00:37:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi frank n o/</p><p>Oates - basically you take 1920x1080 and set it as your width and height. you&#39;ll determine the proper depth to render to in a moment.</p><p>First, you need your horizontal field of view and your aspect ratio. Typical is 90^ and 1.33333 for a quarter view on a 4 by 3 screen.</p><p>These determine your depth, which is the desired view &#39;width&#39; divided by the tangent of HFOV/2.0 . This is the desired depth to render to to make everything look like it was normal size on the tilemap.</p><p>So now you need parameters to pass to <span class="source-code">al_perspective_transform</span>. l and r and t and b are just half your width and height to either side of the origin. Eg. -960,960 and -540,540 to center 1920x1080 on the screen. The only other parameters you need are the near and far clipping planes, but they are arbitrary in size depending on the field of view. They can be set to any reasonable near plane for the camera to have space behind whatever it is looking at. The far plane can just be again, another reasonable value say some small multiple of the &#39;screen&#39; depth.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sat, 09 Apr 2022 20:38:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/618642/1052077#target">frank.n</a> said:</div><div class="quote"><p> I think I hacked together something related to have animation effects (rotation around X / Y axes) in lgui tests / demo:</p></div></div><p>Ok, yea this actually works quite seamlessly!</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> Note sure if I did it the &quot;correct&quot; way, but basically it puts the usual 2D screen on a plane on z=0 within a frustum so that you can draw as you would in 2D, however, different Z coordinates lead to some (slight) perspective effects.</p></div></div><p>Yea this is basically exactly what I&#39;m looking for.  I thought I&#39;d have to figure it out myself but your code worked for me out of the box and the comments were very nice.</p><p>I only had to tweak the <span class="source-code">w</span> / <span class="source-code">h</span> variables to 1920x1080, and then I only needed to change the <span class="source-code">Z_DIST_FACTOR</span> to expand/contract the focal length depth effect.  I did have to add the depth rendering flags to get the depth buffer:</p><div class="source-code snippet"><div class="inner"><pre>      <span class="c">// before display creation:</span>
      <a href="http://www.allegro.cc/manual/al_set_new_display_option"><span class="a">al_set_new_display_option</span></a><span class="k2">(</span>ALLEGRO_DEPTH_SIZE, <span class="n">32</span>, ALLEGRO_SUGGEST<span class="k2">)</span><span class="k2">;</span>

      <span class="c">// before renders:</span>
      al_set_render_state<span class="k2">(</span>ALLEGRO_DEPTH_TEST, <span class="k1">true</span><span class="k2">)</span><span class="k2">;</span>
      al_clear_depth_buffer<span class="k2">(</span><span class="n">1000</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

Not only did it work well, it also worked seamlessly with the different camera control strategies that I had in place.  So zooming in/out, changing the camera position to lock to different &quot;rooms&quot;, etc, in the game integrated perfectly.</p><p>Thank you <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Sun, 10 Apr 2022 17:34:49 +0000</pubDate>
	</item>
</rss>
