   Raycasting flat terrain
  Hi,I'm trying to build a game wherein I have an infinite plane that the user is looking down on at an angle.  I have a bunch of polygons defined by bezier curves that indicate areas on the plane I wish to colour in a different fashion.  The user must be able to freely move in this world that only has a single plane coloured in different ways.From the reading I have done, it would appear that raycasting is the way to go about drawing this game I'm describing.  However everything I have read regarding "floor-casting" as it were is written with respect to a "maze" world with walls.  I'm finding that the actual information about drawing the ground is written with the wall positions in mind.If anyone can give some advice or a link to a tutorial that describes how to draw the plane I'm describing in correct perspective, that would be excellent.All the data is stored in "real-world" coordinates such as meters.Thanks,Karma   
  Just do the same thing as this (there's a second page), but ignore the whole thing about walls.  The main idea will be the same.  Once you know which part of the floor you're drawing, you can just grab a pixel that represents that place from however you have your map stored.   ;  From what I can tell, this method goes through every single pixel below a wall.  This is way WAY too slow for what I'm doing.  Any other suggestions?Karma   ;  You could easily do this using raytracing principles.For every pixel on screen, calculate the camera ray.Now you need to find the intersection point between the plane and the ray.Normally you you calculate the intersection time like this:t = (Plane.Normal dot CameraOrigin + Plane.D) / -(Plane.Normal dot CameraRay).But since we assume that the normal is (0, 1, 0) we can simplyfy things.t = -(CameraOrigin.Y + Plane.D) / CameraRay.YThe first term is constant for every pixel during the "frame", so this could be stored, giving (C = -(CameraOrigin.Y + Plane.D)):t = C / CameraRay.Y   If t < 0 the ray doesn't intersect the plane, so paint with whatever color you like (background color).If CameraRay.Y is close to zero you'd also like to paint with the background color.Once you have the t parameter you get the world space position using:WorldPos = CameraRay * t + CameraOriginSo just use your X and Z coordinate as your "texel" coordinate (maybe applying some scaling and offsetting).A final optimization is to limit the camera so there's no pitch (roll) involved.Doing this ensures that the CameraDir.Y is constant during a scanline.This means that the expensive divide could be left out, so to osummarize in pseudo code:Every frame:float c = -(CameraOrigin.Y + Plane.D);Every scanline:if (fabsf(CameraDir.Y) < 0.000001f)  goto skipPixel; float t = c / CameraDir.Y;Every pixel:float x = CameraDir.X * t + CameraOrigin.X;float z = CameraDir.Z * t + CameraOrigin.Z;Use x and z to look up in your "texture"Disclaimer: All the above is written from my tired memory, so there might be some errors in it.[Edited by - eq on November 15, 2005 3:29:27 PM];  Going pixel by pixel is, unfortunately, too slow for this processor.  I've switched it around so that I'm casting into the number of points of the polygon, and then determining the screen coordinates from those world space points.Then I'll just do a 2d polygon fill to get the colour correct.  Really, there aren't even textures, so it's not like I'm stretching any texture out.  I just want to paint the various flat polygons in the world coordinates different colours.Karma;Quote:Going pixel by pixel is, unfortunately, too slow for this processor. I've switched it around so that I'm casting into the number of points of the polygon, and then determining the screen coordinates from those world space points.Wow! You've just reivented a software 3d pipeline ;)Quote:Then I'll just do a 2d polygon fill to get the colour correct. Really, there aren't even textures, so it's not like I'm stretching any texture out. I just want to paint the various flat polygons in the world coordinates different colours.One issue that might be a problem is clipping, you might need to clip your polygons to near plane (ans possible the edges of the screen).;  This might provide some insight into the floorcasting issue - have a look at the techniques behind Mode7 style graphics (used for MarioKart & F-Zero on the SNES & GBA (probably) & many other similar games on other platforms)I think this would be fairly straightforward to adapt to use textures instead of large images containing the entire map data (i.e. a complete track circuit or something).. in fact that's given me an idea.   