//==================================================================================== // bruteforce2.cpp : brute force evaluation of sphere pixel coverage (scan-conversion) // and depth-value evaluation using combined method in SCREEN SPACE. //==================================================================================== #include "fbppm.hpp" #include // THE "MOCK" FRAMEBUFFER int WW=256, WH=256; FrameBufferPPM fb(WW,WH); //------------------------------------------------------------------------------------ // Paraboloid function that fits the points: (a+r,b,MaxZ), (a-r,b,MaxZ), (a,b+r,MaxZ), // (a,b-r,MaxZ), and minimum at (a,b,MinZ) extending to infinity in +Z. // Evaluates z for a given (x,y). //------------------------------------------------------------------------------------ float Depth(int x, int y, int a, int b, float r, float MinZ, float MaxZ) { if (r>0) { float xa=x-a, yb=y-b; float fxy = (MaxZ-MinZ)*(xa*xa + yb*yb)/(r*r) + MinZ; return (fxy); } else return(MaxZ+1); // RETURN INVALID VALUE } //------------------------------------------------------------------------------------ // scan-converts sphere given center (a,b) in screen space, pixel radius, // Min and Max depth Z-value (Max is "deeper"). //------------------------------------------------------------------------------------ void BruteForceSphere(int a, int b, float r, float MinZ, float MaxZ) { for (int x=0; x