Archived

This topic is now archived and is closed to further replies.

robertgamble

Raycasting:- Possible to only cast the corners of boxes?

Recommended Posts

Would it be possible to write a raycasting engine that only finds the corners/edges of boxes? Say it''s a wolfenstien style engine with 64*64 boxes: the engine casts out one set of rays, until it finds a wall. draws a plain black line (wall slice) and remembers the coordinates of the top and bottom of this line. calculates where abouts in the box the ray hit (same math as working out which slice of a texture to draw), and then calculates the angle change needed for the next set of rays to hit the next set of corners.. A ray is cast at this new angle, and a line/wall slice is drawn, then 2 lines are drawn between the 2 wall slices.. I know I haven''t explained it very well, but I hope someone can understand what I''m babbling on about. What I''m aiming for is a sort of wireframe raycasting engine, but because it''s a raycaster hidden walls wont be drawn so it''ll look nice and tidy. Oh and this isn''t for DHTML!

Share this post


Link to post
Share on other sites
i would suggest image postprocessing. raycast and store the face-index per pixel. then go through all the pixels, compare if the index on the pixel right of yours is different, if so, make it black, if not, let it be white. same for the pixel downunder yours..

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
Yeah, I guess that would work.. But if I only had to cast the corners of walls it would be alot faster. I''d like to try and do this on the virtual boy, or standard game boy.

Share this post


Link to post
Share on other sites
I''m sure there''s a way to do what you want, but I don''t think traditional raycasting will be it. I''ll improvise a solution here:

First, let''s define some terms to avoid confusion: Your map is a grid of cells. A cell may either be a block or empty.

Next, understand that a frustrum in this 2d world is itself 2d, and needs to be represented only by two lines.

Now, assume you have a routine that will return the closest block in a given frustrum* (the asterisk means more on this later). Use this function with the main frustrum, and get the block. When projected on the screen, two sides of the block will be vertical. Determine which two edges of the block form those vertical edges when projected on the screen (This can be done with a few ifs and elses). These edges are just two corners of a cell. Each corner is a point. Define a line through one corner point and the camera point. Do the same for the other one. Now you have a left line and a right line. Define one new frustrum with the left line and the left side of the current frustrum, and the other with the right line and the right side of the current frustrum. Draw the current block**, and recurse with each of these two frustra.

Now, this last paragraph assumed two corners of the closest block would always fall in a frustrum. But if only one corner falls in, then you only need to recurse with one new frustrum. And if neither of the two extreme corners fall in, then you don''t need to recurse at all.

* Finding the closest block in a given frustrum:

Method 1: Treat each of the two lines (edges of the frustrum) parametrically. They''re functions. We''ll call the two lines p and q. p(t) is a point. So is q(t). Two points define another line; I''ll call it r. Step along line r between p and q, testing to see if a cell is a block. The first block you come across this way should be the closest one (or close enough to it).

Method 2: At load time, build a simple quadtree/mipmap structure representing your map. At coarser levels, if any cell within a "pixel" is a block, that "pixel" is marked as "block." Just walk down the tree.


**Drawing the curent block:

Each block is drawn as only seven lines at most. Clip the lines to the current frustrum (remember that you can clip many lines simultaneously very easily since you''re clipping against vertical lines in screen space). Then draw those lines.


So, im summary: This algorithm draws blocks in front to back order with zero overdraw, and it draws those blocks as line segments. It''s not a raycaster, but I think it does what you want.

Share this post


Link to post
Share on other sites