|
Calculating ceiling and floor textures in a raycaster |
StevenVI
Member #562
July 2000
|
Well, I decided to start working on my raycaster idea again. I remember a little while after I started working on mine there was some sort of craze around here with them, so I figure by now everyone's written their own Duke3D clone and I'm way behind the times... But anyways, I was wondering if anyone would share the math involved for texturing the floor and ceiling. I can't seem to figure out the math on this one. I have some triangles written down on paper with two similar triangles ... but I'm not sure if they're related or what and I'm babbling now. So if anyone could explain the formulas (or just tell them to me ) I'd appreciate it. Thanks! __________________________________________________ |
23yrold3yrold
Member #1,134
March 2001
|
I never actually implemented it in mine, but the tutorial we were all referencing during the craze (this one) shows how to do it. Most of what I learnt about the raycasting implementation I got from there ... -- |
StevenVI
Member #562
July 2000
|
233yrold3yrold: Thanks, I do have that tutorial in my reference list. I looked over the pages on texturing the floors, and it was pretty vague and I couldn't quite understand it. I have an "almost-working" implementation at the moment. It moves left and right with the camera properly, but not forward or backwards (the product of a couple guesses in math and stealing code from another program which I wasn't up to disecting in it's entirety.) This is what I have (the decimal function returns the decimal portion of a floating point number): for(row=bot+1; row<SCREEN_H; row++) { // get ratio of viewer height to pixel height float ratio = player_height/(row-(SCREEN_H/2)); // get distance to visible pixel float distance = ratio*VIEWPLANE_DISTANCE/my_cos(i*ANGLE_BETWEEN_RAYS-FOV2); // rotate distance to ray angle float x = decimal((-distance * my_sin(ray<i>.angle))+player_x)*floor_texture->w; float y = decimal((distance * my_cos(ray<i>.angle))+player_y)*floor_texture->h; putpixel(buffer,i,row,getpixel(floor_texture,(int)x,(int)y)); } (And please no kiddies commenting on the fact that it's not optimised. That's for once it works properly.) The x/sin and y/cos is from the other program I looked at. I tried a bunch of combinations on the x= and y= lines and none of them worked (and understanding the math would most definitely make this baby work for me, maybe if I just sat here and thought for another few minutes...) __________________________________________________ |
Roman Tech.
Member #600
August 2000
|
This is how I do my floor casting:
|
Krzysztof Kluczek
Member #4,191
January 2004
|
I'm rendering floors the same way as in code posted above, but still this is really bad approach to rendering floors. Most FPPs (Doom, Duke3d) were rendering floors in horizontal lines. This will spare you per-pixel division since it's essentially the same as rendering vertical walls then. Anyway, mixing column and row rendering doesn't seem to be easy. ________ |
Kitty Cat
Member #2,815
October 2002
|
You should actually draw all your floors first (far to near), then walls (near to far with some kind of per-ray z-buffer, or far to near without). -- |
|