### Author Topic: Floor Casting  (Read 5944 times)

0 Members and 1 Guest are viewing this topic.

#### Jim

• Founder Member
• Posts: 5301
• Karma: 402
##### Re: Floor Casting
« Reply #20 on: August 05, 2010 »
very pretty!
Jim
Challenge Trophies Won:

#### Dr.Death

• Senior Member
• Amiga 1200
• Posts: 433
• Karma: 8
##### Re: Floor Casting
« Reply #21 on: August 05, 2010 »
Great job mate
Proud member of DAWN

#### rain_storm

• Here comes the Rain
• Posts: 3088
• Karma: 182
• Rain never hurt nobody
##### Re: Floor Casting
« Reply #22 on: October 05, 2010 »
http://www.dbfinteractive.com/forum/index.php/topic,2816.msg38767/topicseen.html#msg38767

Code: [Select]
`    w  = -yres / y`This w variable is a scalar. It is used to set up the scale of each horizontal line (rows). w is proportional to the distance y relative to a fixed point along the y axis I used -yres or half the screen width above the first pixel. The effect of this is that rows which are closer to this point are scaled by a smaller size. The scale is then applied to all pixels contained in that row (a horizontal line).

Code: [Select]
`      u = u + w`Here you can see that u is a UV co-ordinate and on each iteration of the inner loop we increment the u co-ordinate by the depth scalar w. By this mechanism the scalar w is applied to each pixel in the row. as the value of y grows larger the increment becomes smaller. to phrase that another way the further away from the fixed point your current row happens to be, the longer it will take for w to increment u such that u is incremented by an integer 1.0

By the time y reaches the bottom of the screen, w is minimal and it takes a long time for it to increment u co-ordinates to the next higher integer.

Code: [Select]
`    v =  resX*w - camY    u = -xres*w + camX`
This part of the code is used to add some dynamics to the scene we are simply setting up the initial values for the u and v co-ordinates. we can move the camera up or down by changing v or we can move the camera left and right by changing u. Once these variables have been set up however there is no room to play with them. u must be incremented by w and v must remain unchanged. I think you already gathered this

Code: [Select]
`      c = (u xor v) and 255      buffer(b+x) = rgb(c,c,c)`Here in my code we convert the uv co-ordinates into a checkerboard pattern. This is done by simply taking their integer parts, xoring them, then taking the low 8 bit value to define the color. this part probably needs no further explaination, except that we are only interested in the integer parts of u and v.

so from this info we can see that to do this for just a few arbitrary points what you need to do is...

Code: [Select]
`for p = 0 to points    w  = -yres / pointY(p)    v = resX*w - camY    u = (-xres*w + camX) + w*pointX(p)    pixel u, vnext p`
Points can be plotted at will and appear to move uniformly in paralax. Points drawn later will be drawn on top of existing points overwriting them in the process.
pointY can even be replaced by pointZ and you are then free to choose where to plot the pixel on the y axis
« Last Edit: October 05, 2010 by rain_storm »

Challenge Trophies Won: