//==================================================================================== // lineval.cpp : uses PixelFlow style linear-expression evaluator to resolve pixel // coverage, uses paraboloid approximation for depth, uses Qbuffer. //==================================================================================== #include "fbppm.hpp" #include // THE "MOCK" FRAMEBUFFER int WW=256, WH=256; FrameBufferPPM fb(WW,WH); //------------------------------------------------------------------------------------ // Qbuffer : table of precomputed values for each (x,y) pixel location. //------------------------------------------------------------------------------------ int Qbuffer(int x, int y) { return( x*x + y*y ); // FOR NOW, JUST EVALUATE } //------------------------------------------------------------------------------------ // scan-converts sphere given center (a,b,c) in screen space and pixel radius. //------------------------------------------------------------------------------------ void LinEvalSphere(int a, int b, int c, int r) { // FOR EVERY PIXEL (x,y) for (int x=0; x= Qbuffer(x,y) ) PixelIsEnabled=1; // CALCULATE DEPTH USING PARABOLOID APPROXIMATION if (PixelIsEnabled) { float z = (LinEval + c*r - Qbuffer(x,y)) / r; float Color = (z-c)/r; fb.SetForeground(Color,Color,Color); fb.SetPixel(x,y); } } } void main() { int NumSphereTiles=1; float TileWidth = (float)WW/NumSphereTiles; float TileHeight = (float)WH/NumSphereTiles; float Radius = (TileWidth+TileHeight)*0.25; float Cx, Cy; Cy=TileHeight*0.5; for (int i=0; i