My first raycaster found here. When you play it, it looks like you're in a curved room, but the map is a perfectly straight square. Can someone explain to me why? I tried to make the scripts as simple as possible (I don't know how else to do it since I didn't look at a tutorial), so it shouldn't be all that hard to read. Just know that I made 4 scanners and 2 drawers.
Offline
so that you don't need to download, here is the script for sensing the walls
when I receive [sense v] delete (all v) of [distances v] set [drawing v] to [1] set [distance v] to [0] set [scanning remembering thingamajig v] to [48] repeat (24) //because I have 4 sensors set [distance v] to [60] go to [movement v] //the movement sprite point in direction <<[direction v] of [movement v]> + (scanning remembering thingamajig )> repeat until <<touching [wall v]?> or <(distance)=[0]>> move [1] steps change [distance v] by [-1] end add (distance) to [distances v] change [scanning remembering thingamajig v] by [-1] endand here is the script for drawing the walls
when I receive [draw v] go to x:[1] y:[180] //since each drawer takes half the screen set pen size to [5] set pen color to [#0000FF] clear pen up set [help counting v] to [24] //since each distances list is 24 items long repeat (24) set pen shade to <<item (help counting) of [distances v]>*<[1]+<[2]/[3]>>> set y to <<item (help counting) of [distances v]>*[4]> pen down set y to <<<item (help counting) of [distances v]>*[4]>*[-1]> pen up change [help counting v] by [-1] set pen shade to [0] change x by [5] //because the pen size is 5 endEach drawer does that script twice to match up with the 4 lists of distances. I'm trying to figure out how to fix that when it senses, it draws it in a curved room when it's supposed to be straight. Can someone please help me?
Last edited by TorbyFork234 (2012-04-13 16:49:17)
Offline
The reason is because you're using purely distance. If you use purely distance, even if points are on the same line that's perpendicular to your view, they're different distances. This creates the Fisheye effect. In order to correct this, take the distance you get when scanning and multiply by the cosine of the offset of the angle (i.e. if you're drawing the part of the wall right in the middle, the offset is 0 degrees and so the distance will simply be multiplied by 1).
Offline
AtomicBawm3 wrote:
The reason is because you're using purely distance. If you use purely distance, even if points are on the same line that's perpendicular to your view, they're different distances. This creates the Fisheye effect. In order to correct this, take the distance you get when scanning and multiply by the cosine of the offset of the angle (i.e. if you're drawing the part of the wall right in the middle, the offset is 0 degrees and so the distance will simply be multiplied by 1).
How do I find the offset of the angle? I tried turning 1 degree, moving 1 step, and seeing if it's still touching the wall, and if not, take that direction and continue going. but that didn't work.
Offline
Your offset would by your variable "scanning remembering thingamajig." Also, you might be able to reduce your FOV.
Offline
so the new script should be
add <(distance)*<[cos v] of (scanning remembering thingamajig)>> to [distances v]?
Last edited by TorbyFork234 (2012-04-13 17:21:08)
Offline
Yep, looks like it from the way you've got your scripts set up. I hope this helps...what you could do is change you FOV from 96 to something more like 60 as well...that will reduce the effect as well. That would mean at the beginning:
Sensor 1 variable: 30
Sensor 2 variable: 15
Sensor 3 variable: 0
Sensor 4 variable: -15
Offline
AtomicBawm3 wrote:
Yep, looks like it from the way you've got your scripts set up. I hope this helps...what you could do is change you FOV from 96 to something more like 60 as well...that will reduce the effect as well. That would mean at the beginning:
Sensor 1 variable: 30
Sensor 2 variable: 15
Sensor 3 variable: 0
Sensor 4 variable: -15
But that would also reduce the resolution so I won't do it.
Offline
It didn't work, it only made it worse.
Offline
Oh, I know why it's not working...You have your distance counting down as it gets farther away...so your formula for distance would be:
add ((60) - (([cos v] of (variable)) * ((60) - (distance)))) to [distances v]Tell me how that works out.
Last edited by AtomicBawm3 (2012-04-14 12:05:46)
Offline
no, I tried that and everything up close was fine, but everything far away was all wacky. and then I tried
<<[60]-<[cos v] of (variable)>>*<[60]-(distance)>>and that didn't work either.
Offline
Next thing I'll try
<[60]-<<[cos v] of <<[direction v] of [movement v]> - (variable)>>*<[60]-(distance)>>>Would it work?
Offline
Didn't work. Help anyone?
Offline