<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Sprites in Raycasting</title>
		<link>http://www.allegro.cc/forums/view/283342</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sat, 19 Jul 2003 04:38:16 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I need to know the techniques behind rendering sprites in a raycaster(ie. badies). I&#39;m going to look at some source code soon, but I&#39;m posting here to see if I can get an accual explaination instead of blindly following some source code, heh.</p><p>BTW I want a technique that is flexible, speed is nice, but flexibility it cool <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Billybob)</author>
		<pubDate>Thu, 17 Jul 2003 06:31:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
We need a Raycasting forum ...</p><p>Well, I would just draw back to front. Make sure you keep track of the distance from the player to the &quot;baddy&quot; though; that way you can make sure you don&#39;t draw the enemy over a wall (you&#39;re probably already keeping track of distance to wall for every pixel column, so this is easy). Use the same system you use for walls when drawing; draw a slice at a time and make all the slices the same size so the enemy doesn&#39;t become distorted.</p><p>Should be easy enough <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Thu, 17 Jul 2003 06:46:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok, so I just translate the center of all visible baddies and draw them, eh? But how do I know how wide to draw them, same translation? Also, will a baddie have any slant to the top/bottem of it cause it is always facing you(billboard) or does it slant. If it doesn&#39;t slant then I don&#39;t have to draw it slice by slice, just a simple blit &gt;8)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Billybob)</author>
		<pubDate>Thu, 17 Jul 2003 06:56:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Edit, um... I guess I accidently posted to the wrong post, sorry...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Carrus85)</author>
		<pubDate>Thu, 17 Jul 2003 06:56:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yea, I already know that translation equation like the back of my hand, heh. Good ole similar triangles</p><p>EDIT Response to your edit....Oh... EDIT
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Billybob)</author>
		<pubDate>Thu, 17 Jul 2003 06:59:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I'm dumb!... that post was intended for the drawing a guiding arrow post...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Carrus85)</author>
		<pubDate>Thu, 17 Jul 2003 07:03:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>We need a Raycasting forum </p></div></div><p>

I&#39;ve been wondering something about the prevelance of this &quot;raycasting&quot; technique (I really hate that name, as it sounds too much like a real rendering technique, raytracing) around here lately.</p><p>Why?</p><p>In terms of presenting a 3D world, a scan converter is, not only much better at it, but (when hardware-accelerated) faster as well. It is also more artistically free. You aren&#39;t stuck with Doom-like creations; you can make much more interesting, dynamic environments.</p><p>So, if you&#39;re interested in doing something vaguely 3-dimensional, why not go all the way?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Korval)</author>
		<pubDate>Thu, 17 Jul 2003 10:33:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> In terms of presenting a 3D world, a scan converter is, not only much better at it, but (when hardware-accelerated) faster as well.</p></div></div><p>Is that the thing TH made?</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Why?</p></div></div><p>Easy and fun? <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Thu, 17 Jul 2003 11:09:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> In terms of presenting a 3D world, a scan converter is, not only much better at it, but (when hardware-accelerated) faster as well.</p></div></div><p>
As I&#39;m sure you know already:</p><p>But a raycaster is a scan converter - it just so happens that the walls are converted to vertical rather than horizontal scanlines, which means that, per pixel, you can use affine scaling and still get correct perspective, and by thinking slightly more in trig than in linear algebra you can save several more calculations.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Is that the thing TH made?</p></div></div><p>It was, I guess, but it was using trig. Nevertheless, everything is changing now that I&#39;ve moved on to the platform I actually want to target - low end mobile phones. I&#39;ve switched to a style much more like ray casting (but still with portals) which has the advantage of being very good at guessing which wall a particular ray will hit first time, and very good at guessing which wall it must have hit if not.</p><p><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/7/d/7d312c3e9ae0b1010393f09793eea9b9.jpg" alt="mbcaster.jpg" width="214" height="537" /></p><p>That version is not yet fully optimised.</p><p>To the original poster: is your raycaster simple Wolfenstein style, same height walls? If so what you effectively do is keep a 1d z-buffer. Keep a record of the heights of every sliver, convert your sprite to screen co-ordinates and draw (as a first implementation) sliver by sliver only where the sprite slivers are larger than the wall slivers.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Harte)</author>
		<pubDate>Thu, 17 Jul 2003 15:39:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>William: In wolfenstein, doom, and just about every other raycaster, the objects aren&#39;t drawn at an angle to the viewer, you always only get the same picture! The same goes for the enemies, except they have pre-made 4 sides.</p><p>I&#39;m at the objects step in my raycaster, too. I belive that the only thing I need to do is get the angle from the object to the player:
</p><div class="source-code snippet"><div class="inner"><pre>............................ Line from P-O is the
............................ distance from Player
........_................... to object
.........<span class="k3">-</span>_....O............ Line coming out from
...........<span class="k3">-</span>_.b.\........... player <span class="k2">(</span>made of 
.............<span class="k3">-</span>_..\.......... hyphens <span class="k3">&amp;</span> underscores
...............<span class="k3">-</span>_.\......... <span class="k2">)</span> is the players 
.................<span class="k3">-</span>P......... angle.
............................
</pre></div></div><p>
I need to find angle &#39;b&#39; in that picture (the angle between the object and the player. I have, the angle of the player, and the distance to the object. I must have to use the inverse of one of the trig functions...?<br />Otherwise, I&#39;ve got scaling done! Then, when I go to draw the objects, I&#39;ll draw each vertical strip of them, then check the values in my view[320] array and only draw if there isn&#39;t a distance in that line closer to the player. That&#39;s the easy part. I just gotta get that angle!</p><div class="quote_container"><div class="title">Korval said:</div><div class="quote"><p>
(I really hate that name, as it sounds too much like a real rendering technique, raytracing) </p></div></div><p>
Heeey, man...don&#39;t bash it! Come over to the dark side...the raycasted side. Leave all your &quot;real rendering techniques&quot; behind...::)</p><div class="quote_container"><div class="title">23, in response to raycasting critisism said:</div><div class="quote"><p>Easy and fun? <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /></p></div></div><p>
<b>Yeah!</b> Plus, if you like old games like DOOM and Wolfenstein 3D (I do!8-)), it&#39;s real cool to make one that looks like that! Also, it&#39;s good for a guy who&#39;s only been through geometry in school (also me!).;)::):-/;D</p><p>Thomas: That&#39;s cool!8-)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (aybabtu)</author>
		<pubDate>Thu, 17 Jul 2003 18:01:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> I need to find angle &#39;b&#39; in that picture (the angle between the object and the player. I have, the angle of the player, and the distance to the object. I must have to use the inverse of one of the trig functions...?</p></div></div><p>
You could, if you wanted to do it the trig way, use atan2 and then subtract the angle your viewer is actually rotated at.</p><p>Alternatively, and probably more speedily, you could use some linear algebra. Use the dot product to project the vector from the viewer to the enemy into screen space, adjust that for your FOV (multiply x by z multiplied by some scalar) then do a standard issue perspective transformation.
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Thomas: That&#39;s cool!</p></div></div><p>You can get a full Doom port for the Nokia series 60 line with bilinear filtering... but we don&#39;t all want one of those ugly things.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Harte)</author>
		<pubDate>Thu, 17 Jul 2003 20:32:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m making some headway (very little) over on my other thread:P (Getting an angle...sorry...)...I&#39;ve got the angle, (I think!), and now I need to draw the sprite!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (aybabtu)</author>
		<pubDate>Thu, 17 Jul 2003 20:34:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>True, 3d hardware has come a long way in increasing the speed at which you can draw 3d objects, but it also came for a price: complexity.  No offense, but open-gl really bugs me because you have to enter like 35 lines of code to make one stupid triangle popup on the screen.  Not only that, raycasters are more hardware independant, because they don&#39;t depend on a platform that has opengl accel.</p><p>True, they could always implement an opengl accelerated renderer that the user could choose from, I guess...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Carrus85)</author>
		<pubDate>Thu, 17 Jul 2003 20:36:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I tried following the &quot;NeHe tutorials&quot; on OpenGL, but I didn&#39;t want to type in all that code! It was like 10 billion (okay, maybe I&#39;m exagerrating a little) pages of code! Just for the first program! I&#39;m totally with you there, Carrus!:D
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (aybabtu)</author>
		<pubDate>Thu, 17 Jul 2003 20:40:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Um... how much of them 35 lines are for setting up the hardware for your program (like the install_* functions in Allegro)?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (MiquelFire)</author>
		<pubDate>Thu, 17 Jul 2003 20:43:45 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There isn&#39;t any...it&#39;s all OpenGL and windows crap.:P::)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (aybabtu)</author>
		<pubDate>Thu, 17 Jul 2003 20:45:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">FF8 fan said:</div><div class="quote"><p>it&#39;s all OpenGL and <b>windows crap</b></p></div></div><p>

The windows crap is the same as the install_* functions in Allegro (and the set_gfx_mode() as well) <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (MiquelFire)</author>
		<pubDate>Thu, 17 Jul 2003 20:47:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Okay...but there&#39;s like 15 lines of it...hardly any of which (to teh WinAPI n00b) is understandable. Nyah.:P
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (aybabtu)</author>
		<pubDate>Thu, 17 Jul 2003 20:52:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
The Windows crap is overhead that you should be keeping on hand for whatever purpose so you don&#39;t have to retype it. NeHe hands out that base code for a reason, y&#39;know <img src="http://www.allegro.cc/forums/smileys/rolleyes.gif" alt="::)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Thu, 17 Jul 2003 20:52:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b>What</b>...ever...<br />This is too OT.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (aybabtu)</author>
		<pubDate>Thu, 17 Jul 2003 20:55:36 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>No offense, but open-gl really bugs me because you have to enter like 35 lines of code to make one stupid triangle popup on the screen.</p></div></div><p>

And how many lines does it take to write a ray-caster that is decently well-optimized? I&#39;m pretty sure it&#39;s more than 35.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Okay...but there&#39;s like 15 lines of it...hardly any of which (to teh WinAPI n00b) is understandable. Nyah.</p></div></div><p>

You aren&#39;t supposed to understand it. Just recognize that it is required to produce a window. You copy and paste it as needed. You can use Allegro just fine without fully understand what all the initialization functions are.</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>I need to know the techniques behind rendering sprites in a raycaster(ie. badies). </p></div></div><p>

Stretch-blit. That&#39;s the long and short of it. You stretch-blit the sprite such that it appears to be on the ground and remains, perspective-wise, at a particular height.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Korval)</author>
		<pubDate>Fri, 18 Jul 2003 00:44:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>open-gl really bugs me because you have to enter like 35 lines of code to make one stupid triangle popup on the screen.</p></div></div><p>

Ever tried D3D? <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /><br />You won&#39;t get away with 35 lines - try 350. <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Fri, 18 Jul 2003 00:50:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes! Going along witht the original post, visit the &quot;Getting an angle&quot; thread, go all the way to the last post where I have done it!! With lots of help from 23yrold3yrold! I attached a screenshot.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (aybabtu)</author>
		<pubDate>Fri, 18 Jul 2003 00:53:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">23 said:</div><div class="quote"><p>
We need a raycasting forum
</p></div></div><p>
I agree, if this keeps up...<br />But I think a better idea is to write a &quot;monthly&quot; article on the subject in pixelate.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trezker)</author>
		<pubDate>Fri, 18 Jul 2003 02:27:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Me=8-)<br /><b>aybabtu eyes his sig</b><br /><img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>Oooh! I have a teensy problem...it seems that my object drawing method fails for I think 180 degrees! Objects disappear! Look:<br /><span class="remote-thumbnail"><span class="json">{"name":"wolf.gif","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/6\/567fd195c6b6f49ac04e82d333248f2c.gif","w":320,"h":320,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/6\/567fd195c6b6f49ac04e82d333248f2c"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/6/567fd195c6b6f49ac04e82d333248f2c-240.jpg" alt="wolf.gif" width="240" height="240" /></span><br />There&#39;s supposed to be 3 barrels there. The one on the far left <i>does</i> appear, but you have to turn a bit to the left! It <i>should</i> be visible in this shot, if I move about 5 degrees to the left, it shows up... WTF? <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>I know it&#39;s not the right forum:-X, but here&#39;s my code:
</p><div class="source-code snippet"><div class="inner"><pre><span class="c">/*</span>
<span class="c"> int odistance=distancefrom player to object</span>
<span class="c"> float oangle is angle between player and object</span>
<span class="c"> int odisplayx=where to draw on screen</span>
<span class="c"> int obj_x,objy=object's coordinates</span>
<span class="c"> */</span>
odistance<span class="k3">=</span><span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>DIV_VIEW<span class="k3">/</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_738.html" target="_blank">sqrt</a><span class="k2">(</span><span class="k2">(</span>obj_x<span class="k3">&lt;</span>i&gt;-px<span class="k2">)</span><span class="k3">*</span><span class="k2">(</span>obj_x<span class="k3">&lt;</span>i&gt;-px<span class="k2">)</span><span class="k3">+</span><span class="k2">(</span>obj_y<span class="k3">&lt;</span>i&gt;-py<span class="k2">)</span><span class="k3">*</span><span class="k2">(</span>obj_y<span class="k3">&lt;</span>i&gt;-py<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
   oangle<span class="k3">=</span>RAD_TO_DEG<span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_50.html" target="_blank">atan2</a><span class="k2">(</span>obj_y<span class="k3">&lt;</span>i&gt;-py,obj_x<span class="k3">&lt;</span>i&gt;-px<span class="k2">)</span><span class="k2">)</span><span class="k3">-</span>pa<span class="k2">;</span>
   <span class="k1">if</span><span class="k2">(</span>oangle<span class="k3">&lt;</span><span class="n">0</span><span class="k2">)</span> oangle<span class="k3">+</span><span class="k3">=</span><span class="n">359</span><span class="k2">;</span>
   <span class="k1">if</span><span class="k2">(</span>oangle&gt;359<span class="k2">)</span> oangle-<span class="k3">=</span><span class="n">359</span><span class="k2">;</span>
   odisplayx<span class="k3">=</span><span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>oangle<span class="k3">/</span><span class="n">0</span>.<span class="n">1875</span><span class="k2">)</span><span class="k3">+</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a><span class="k3">/</span><span class="n">2</span><span class="k2">)</span><span class="k2">;</span>
   <a href="http://www.allegro.cc/manual/stretch_sprite" target="_blank"><span class="a">stretch_sprite</span></a><span class="k2">(</span>front,object<span class="k2">[</span><span class="n">0</span><span class="k2">]</span>,odisplayx-odistance<span class="k3">/</span><span class="n">2</span>,<span class="n">100</span><span class="k3">-</span>odistance<span class="k3">/</span><span class="n">2</span>,odistance,odistance<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (aybabtu)</author>
		<pubDate>Fri, 18 Jul 2003 03:10:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What in the world has my thread become! I'm dumb!. Uhhh, stop dis-ing OpenGL, cause that is what I&#39;m using for my next &quot;3D&quot; project &gt;8)</p><p>First off, thanks for all the help, I think what I thought was correct and what you are telling me is making me think that what I thought about being correct in thinking what I thought was good. Get that? Got that? Good.</p><p>My engine is not like Doom or Wolfenstien, it is an Advanced Raycaster much like the rex3D engine, but still a raycaster, just slightly different.</p><p>I guess I&#39;m off to go work up some code for rendering sprites <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> Thanks for the help.</p><p><s>-------------NEW POST</s>-------------------------</p><p>Let me run this math by ya and make sure its good.</p><p>X is the offset of the sprite&#39;s center from the center of the screen.<br />P is distance to projection plane.<br />a is Angle between camera and sprite relative to the camera&#39;s viewing angle.</p><p>X = P * tan a</p><p>and of course I can get the height scale of the sprite via my translation function used on the walls and I can use the ratio of the translated height and the real height to figure out how wide to draw the sprite.</p><p>All that sound OK? It better be. <img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Billybob)</author>
		<pubDate>Fri, 18 Jul 2003 03:20:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Quoted code:</p><div class="source-code snippet"><div class="inner"><pre>odistance<span class="k3">=</span><span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>DIV_VIEW<span class="k3">/</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_738.html" target="_blank">sqrt</a><span class="k2">(</span><span class="k2">(</span>obj_x<span class="k3">&lt;</span>i&gt;-px<span class="k2">)</span><span class="k3">*</span><span class="k2">(</span>obj_x<span class="k3">&lt;</span>i&gt;-px<span class="k2">)</span><span class="k3">+</span><span class="k2">(</span>obj_y<span class="k3">&lt;</span>i&gt;-py<span class="k2">)</span><span class="k3">*</span><span class="k2">(</span>obj_y<span class="k3">&lt;</span>i&gt;-py<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
oangle<span class="k3">=</span>RAD_TO_DEG<span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_50.html" target="_blank">atan2</a><span class="k2">(</span>obj_y<span class="k3">&lt;</span>i&gt;-py,obj_x<span class="k3">&lt;</span>i&gt;-px<span class="k2">)</span><span class="k2">)</span><span class="k3">-</span>pa<span class="k2">;</span>
<span class="k1">if</span><span class="k2">(</span>oangle<span class="k3">&lt;</span><span class="n">0</span><span class="k2">)</span> oangle<span class="k3">+</span><span class="k3">=</span><span class="n">359</span><span class="k2">;</span>
<span class="k1">if</span><span class="k2">(</span>oangle&gt;359<span class="k2">)</span> oangle-<span class="k3">=</span><span class="n">359</span><span class="k2">;</span>
odisplayx<span class="k3">=</span><span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>oangle<span class="k3">/</span><span class="n">0</span>.<span class="n">1875</span><span class="k2">)</span><span class="k3">+</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a><span class="k3">/</span><span class="n">2</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/stretch_sprite" target="_blank"><span class="a">stretch_sprite</span></a><span class="k2">(</span>front,object<span class="k2">[</span><span class="n">0</span><span class="k2">]</span>,odisplayx-odistance<span class="k3">/</span><span class="n">2</span>,<span class="n">100</span><span class="k3">-</span>odistance<span class="k3">/</span><span class="n">2</span>,odistance,odistance<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
I have various observations. First of all, I think you actually want this:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">if</span><span class="k2">(</span>oangle<span class="k3">&lt;</span><span class="n">0</span><span class="k2">)</span> oangle<span class="k3">+</span><span class="k3">=</span><span class="n">360</span><span class="k2">;</span>
<span class="k1">if</span><span class="k2">(</span>oangle&gt;359<span class="k2">)</span> oangle-<span class="k3">=</span><span class="n">360</span><span class="k2">;</span>
</pre></div></div><p>
e.g. the angle &#39;360&#39; is not the same as the angle &#39;1&#39;.</p><div class="source-code snippet"><div class="inner"><pre>odistance<span class="k3">=</span><span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>DIV_VIEW<span class="k3">/</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_738.html" target="_blank">sqrt</a><span class="k2">(</span><span class="k2">(</span>obj_x<span class="k3">&lt;</span>i&gt;-px<span class="k2">)</span><span class="k3">*</span><span class="k2">(</span>obj_x<span class="k3">&lt;</span>i&gt;-px<span class="k2">)</span><span class="k3">+</span><span class="k2">(</span>obj_y<span class="k3">&lt;</span>i&gt;-py<span class="k2">)</span><span class="k3">*</span><span class="k2">(</span>obj_y<span class="k3">&lt;</span>i&gt;-py<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
oangle<span class="k3">=</span>RAD_TO_DEG<span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_50.html" target="_blank">atan2</a><span class="k2">(</span>obj_y<span class="k3">&lt;</span>i&gt;-py,obj_x<span class="k3">&lt;</span>i&gt;-px<span class="k2">)</span><span class="k2">)</span><span class="k3">-</span>pa<span class="k2">;</span>
<span class="k1">if</span><span class="k2">(</span>oangle<span class="k3">&lt;</span><span class="n">0</span><span class="k2">)</span> oangle<span class="k3">+</span><span class="k3">=</span><span class="n">360</span><span class="k2">;</span>
<span class="k1">if</span><span class="k2">(</span>oangle&gt;359<span class="k2">)</span> oangle-<span class="k3">=</span><span class="n">360</span><span class="k2">;</span>
</pre></div></div><p>
So, odistance is the perspective projected size of a square tile in pixels, oangle is the angle between the centre of the view and the object.</p><div class="source-code snippet"><div class="inner"><pre>odisplayx<span class="k3">=</span><span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>oangle<span class="k3">/</span><span class="n">0</span>.<span class="n">1875</span><span class="k2">)</span><span class="k3">+</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a><span class="k3">/</span><span class="n">2</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
You&#39;ve picked oangle to be always positive, so your objects are always on the right hand side of the screen here. It strikes me that you might instead want the following:</p><div class="source-code snippet"><div class="inner"><pre>odistance<span class="k3">=</span><span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>DIV_VIEW<span class="k3">/</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_738.html" target="_blank">sqrt</a><span class="k2">(</span><span class="k2">(</span>obj_x<span class="k3">&lt;</span>i&gt;-px<span class="k2">)</span><span class="k3">*</span><span class="k2">(</span>obj_x<span class="k3">&lt;</span>i&gt;-px<span class="k2">)</span><span class="k3">+</span><span class="k2">(</span>obj_y<span class="k3">&lt;</span>i&gt;-py<span class="k2">)</span><span class="k3">*</span><span class="k2">(</span>obj_y<span class="k3">&lt;</span>i&gt;-py<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
oangle<span class="k3">=</span>RAD_TO_DEG<span class="k2">(</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_50.html" target="_blank">atan2</a><span class="k2">(</span>obj_y<span class="k3">&lt;</span>i&gt;-py,obj_x<span class="k3">&lt;</span>i&gt;-px<span class="k2">)</span><span class="k2">)</span><span class="k3">-</span>pa<span class="k2">;</span>
<span class="k1">while</span><span class="k2">(</span>oangle<span class="k3">&lt;</span><span class="k3">-</span><span class="n">180</span><span class="k2">)</span> oangle<span class="k3">+</span><span class="k3">=</span><span class="n">360</span><span class="k2">;</span>
<span class="k1">while</span><span class="k2">(</span>oangle&gt;<span class="k3">=</span><span class="n">180</span><span class="k2">)</span> oangle-<span class="k3">=</span><span class="n">360</span><span class="k2">;</span>
odisplayx<span class="k3">=</span><span class="k2">(</span><span class="k1">int</span><span class="k2">)</span><span class="k2">(</span>oangle<span class="k3">/</span><span class="n">0</span>.<span class="n">1875</span><span class="k2">)</span><span class="k3">+</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a><span class="k3">/</span><span class="n">2</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/stretch_sprite" target="_blank"><span class="a">stretch_sprite</span></a><span class="k2">(</span>front,object<span class="k2">[</span><span class="n">0</span><span class="k2">]</span>,odisplayx-odistance<span class="k3">/</span><span class="n">2</span>,<span class="n">100</span><span class="k3">-</span>odistance<span class="k3">/</span><span class="n">2</span>,odistance,odistance<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
i.e. you restrict your angle to the range [-180,179] rather than [0, 359]. You might be able to use &#39;if&#39; rather than &#39;while&#39;, I&#39;ll let you think about that one!
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Let me run this math by ya and make sure its good.</p><p>X is the offset of the sprite&#39;s center from the center of the screen.<br />P is distance to projection plane.<br />a is Angle between camera and sprite relative to the camera&#39;s viewing angle.</p><p>X = P * tan a</p></div></div><p>I&#39;m confused by P. If you&#39;ve calculated distance from viewer to object and called this P then in your right angled triangle, you have one angle, and the hypotenuse and want to get the side opposite the angle, so you &#39;sin angle = opposite / hypotenuse&#39;. Conversely if you want the side adjoining you use cos.</p><p>If you have the adjoining side, which I guess you mean is P, then yeah:</p><p>tan A = X / P<br />=&gt; P * tan A = X</p><p>Although I reiterate my claim from earlier in this thread that adding objects in a trigonometric manner is silly and processor expensive.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Harte)</author>
		<pubDate>Fri, 18 Jul 2003 15:04:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yay!;D I attached a screenshot...<br />Thank&#39;s Thomas!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (aybabtu)</author>
		<pubDate>Fri, 18 Jul 2003 21:42:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Do you have to keep attaching .pcx files? You can&#39;t view them inline. It&#39;s annoying. At least make them .bmp ... <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Fri, 18 Jul 2003 21:43:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
BMP is too big. PNG/GIF is teh win!!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Fri, 18 Jul 2003 21:47:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Use png&#39;s <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /> much better on the bandwidth.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Fri, 18 Jul 2003 21:49:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
I said <i>at least</i>, since he&#39;s likely generating these screenshots via Allegro, which can&#39;t save gif/png without extra libs.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Fri, 18 Jul 2003 21:49:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Yeah, but everyone should have a program for converting BMP&#39;s to a multitude of file formats ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Fri, 18 Jul 2003 21:53:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
In case he doesn&#39;t, I just want to express that even .bmp is better than .pcx, since .bmp can be viewed inline.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Fri, 18 Jul 2003 21:56:26 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I do have a program, but it&#39;s &#39;new&#39; and takes over a minute to load up...it&#39;s so much easier for me (:P) to do it this way...but, from now on...I&#39;ll convert them to GIFs.:)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (aybabtu)</author>
		<pubDate>Fri, 18 Jul 2003 22:06:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>ewwww, CODE, I'm dumb!. Theories for me. I eat theories for breakfast, and sometimes for lunch. Well, I&#39;m going to make my entity engine, and then I&#39;ll work on the sprite rendering code. If I run into problems with my theories then I&#39;ll check out code, heh.</p><p>EDIT<br />BTW, here is my theory. Use the variables as described in past post.</p><p>http://www.cljy.com/~billy/Sprite Theory.JPG
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Billybob)</author>
		<pubDate>Sat, 19 Jul 2003 04:38:16 +0000</pubDate>
	</item>
</rss>
