[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Raycaster Demo



On 6 Dec 2006 at 11:01, Kris Schnee wrote:

> On a whim, since we're talking about graphics engines and I hear someone 
> else is doing one, I put together a super-simple raycasting engine 
> during class this morning. I call it "Tachikoma," having just rented 
> "Ghost In the Shell: Stand-Alone Complex." For your amusement:
> 
> http://kschnee.xepher.net/code/raycaster.py.txt
> 
> It works in that you can view some "walls" in a 3D perspective in the 
> style of "Wolfenstein 3D," but there's some weird fisheye distortion I 
> haven't figured out how to correct for.
> 
> (To use: Just run it, and use the arrow keys to move and Esc to quit. 
> Requires just Python and Pygame, no graphics files.)
> 
Interesting. The distortion is because apparent size is inversely 
proportional to distance; the program simply subtracts the distance. 
Here are some code changes that give better perspective. Inserted 
code is marked with #**:

    def DrawWorld(self):
        fov_size = (100,100)
        half_wall_height = 20 #**
        ...
        leftmost_line_x = 100

        # Calculate distance at which top of wall  #**
        # touches top of image.  #**
        # viewing angle: 100 degrees  #**
        vertical_limit_distance = (
            half_wall_height /
            math.tan(math.radians(50))  #**
        ...
        for n in range(len(angles_to_scan)):
            ...
            for dist in range(0,max_draw_distance):
                ...
                if whats_here[0] == 255:
##                    print "Angle "+str(angle)+": Wall @ distance 
"+str(dist)
                    half_apparent_wall_height = (
                        half_wall_height *
                        vertical_limit_distance) / dist  #**

                    ## Correct for fisheye distortion.


For comparison I rendered your model with POV-Ray (see attachment) 
using a perspetive camera with 1:1 aspect ratio and 100 degree 
viewing angle. Lighting is fully ambient and the wall height is 20.

Lenard Lindstrom
<len-l@xxxxxxxxx>


The following section of this message contains a file attachment
prepared for transmission using the Internet MIME message format.
If you are using Pegasus Mail, or any other MIME-compliant system,
you should be able to save it or view it from within your mailer.
If you cannot, please ask your system administrator for assistance.

   ---- File information -----------
     File:  perspective.png
     Date:  6 Dec 2006, 12:21
     Size:  645 bytes.
     Type:  Binary

Attachment: perspective.png
Description: Binary data