Exemple #1
0
// 		public bool Render(GBuffer gbDest, IRect rectDest) {
// 			bool bGood=true;
// 			IRect rectShrinking=gbDest.ToRect();
// 			//int iBlobSizeNow=8;
// 			int iBlobSizeNow=1;
// 			int iShrinkBy=gbDest.Height/8;
// 			while (iBlobSizeNow>0) {
// 				if (!Render(gbDest,rectDest,rectShrinking,iBlobSizeNow)) bGood=false;
// 				if (iBlobSizeNow==1) iBlobSizeNow=0;
// 				else {
// 					iBlobSizeNow/=2;
// 					//rectShrinking.Shrink(iShrinkBy);//commented for debug only
// 				}
// 			}
// 			return bGood;
// 		}
		public bool Render(GBuffer gbDest, IRect rectDest) {//, DPoint pPixelOrigin, double rPixelsPerUnit, double rSeed) {
			bool bGood=true;
			try {
				ResetPasses();//fixes iDetailRadius etc
				//int xDest=rectDest.Left;
				//int yDest=rectDest.Top;
				int xEnder=rectDest.X+rectDest.Width;
				int yEnder=rectDest.Y+rectDest.Height;
				
				//double rInverseScale=1.0/rPixelsPerUnit;
				FRACTALREAL rUnitsPerPixel=fr1/rPixelsPerUnit;
				xSrcStart=-((FRACTALREAL)xCenterAtPixel*rUnitsPerPixel);//rInverseScale
				ySrc=-((FRACTALREAL)yCenterAtPixel*rUnitsPerPixel);//rInverseScale
				int iHalfW=gbFractal.Width/2;
				int iHalfH=gbFractal.Height/2;
				//int iBlobIncrement=gbFractal.Height/8;
				//if (iBlobIncrement<1) iBlobIncrement=1;
				FRACTALREAL rFractalness=fr0;
// 			int xBlobPrev=-1;
// 			int yBlobPrev=-1;
// 			int xBlob;
// 			int yBlob;
// 			bool bBlobStartX=false;
// 			bool bBlobStartY=false;
				xDest=rectDest.X;
				yDest=rectDest.Y;
				//int zone_Right=rectCropFractal.Right;
				//int zone_Bottom=rectCropFractal.Bottom;
				//int iBlobSize=(int)RMath.Dist((double)iHalfW,(double)iHalfH,(double)xDest,(double)yDest)/iBlobIncrement;
				//int iBlobSize=(int)(  (1.0-(RMath.Dist((double)iHalfW,(double)iHalfH,(double)xDest,(double)yDest)/(double)iHalfW)) * (double)iBlobIncrement  );
				//iBlobSize=8;//debug only
				for (yDest=rectDest.Y; yDest<yEnder; yDest++) {
					xSrc=xSrcStart;
					//yBlob=yDest/iBlobSize;
					//bBlobStartY=yBlobPrev!=yBlob;
					//yBlobPrev=yBlob;
					for (xDest=rectDest.X; xDest<xEnder; xDest++) {
						///NOTE: Hsv is NOT H<360 it is H<1.0
						//iBlobSize=(int)(  (1.0-(RMath.Dist((double)iHalfW,(double)iHalfH,(double)xDest,(double)yDest)/(double)iHalfW)) * (double)iBlobIncrement  );
						//iBlobSize=8;//debug only
						//if (iBlobSize<1) iBlobSize=1;
						//xBlob=xDest/iBlobSize;
						//bBlobStartX=xBlobPrev!=xBlob;//&&yBlobPrev!=yBlob;
						//xBlobPrev=xBlob;
						//this.SetPixelHsva(xDest,yDest,RMath.SafeAngle360(RMath.THETAOFXY_RAD(xSrc,ySrc))/360.0f,1.0,1.0,1.0);
						//double rFractalness=RMath.SafeAngle360(
						//	(double)FractalResultMandelbrot(xSrc,ySrc,rSeed) 
						//	);
						//int iFractalResult=FractalResultMandelbrot((float)xSrc,(float)ySrc);//TODO: use rSeed
						//byte byFractalResult=(byte)(iFractalResult%255);
						//double rFractalness=(double)byFractalResult/255.0;
						//float rFractalness=(float)(Fractal.FractalResultMandelbrot((float)xSrc,(float)ySrc)%255)/255.0f;
						//double rFractalness=(double)(FractalResultMandelbrot((double)xSrc,(double)ySrc)%255)/255.0;
						//if (iBlobSize==1||(bBlobStartX||bBlobStartY))
						//if (bBlobStartX||bBlobStartY)
						//rFractalness=fr_1;
						//if (xDest>rectCropFractal.X&&xDest<zone_Right&&yDest<zone_Bottom&&yDest>=rectCropFractal.Y) {
							//if (xDest%iBlobSize==0&&yDest%iBlobSize==0)
							//double rFractalness=(double)(ResultMandelbrot(xSrc,ySrc,(double)rSeed)%256)/255.0;
							rFractalness=(FRACTALREAL)(ResultMandelbrot((FRACTALREAL)xSrc,(FRACTALREAL)ySrc,rSeed)%256)/fr255;
						//}
						//if (rFractalness!=fr_1) {//bBlobStartX||bBlobStartY) {
							//if (iBlobSize>1) {
							//	try {
							//		if (xDest>=0&&yDest>=0&&xDest+iBlobSize<=gbFractal.Width&&yDest+iBlobSize<=gbFractal.Height) {
							//			GBuffer.SetBrushHsva(rFractalness,1.0,rFractalness,1.0);
							//			if (!gbFractal.DrawRectFilledSafe(xDest,yDest,iBlobSize,iBlobSize)) {
							//				RReporting.Warning("Skipped fractal blob.","{location:"+IPoint.Description(xDest,yDest)+"; size:"+IPoint.Description(iBlobSize,iBlobSize)+"}");
							//			}
							//		}
							//	}
							//	catch {RReporting.Warning("Failed to render fractal blob.","{location:"+IPoint.Description(xDest,yDest)+"}");}
							//}
							//else {
								gbFractal.SetPixelHsva(xDest,yDest,rFractalness,1.0,rFractalness,1.0);
							//}
						//}
						xSrc+=rUnitsPerPixel;
					}
					ySrc+=rUnitsPerPixel;
				}
				//GBuffer.SetBrushRgb(255,0,0);
				//gbFractal.DrawRectFilledSafe(0,0,64,64);
				//gbFractal.DrawRectFilledSafe(gbFractal.Width-64,gbFractal.Height-64,64,64);
				//if (!gbDest.DrawSmallerWithoutCropElseCancel(rectDest.X,rectDest.Y,gbFractal)) bGood=false;
				if (!gbDest.Draw(rectDest,gbFractal,rectSrcDefault)) bGood=false;
				//if (!GBuffer.Render(gbDest,rectDest,gbFractal,rectCropFractal,GBuffer.DrawModeCopyAlpha)) bGood=false;
				if (bGood) iFramesRendered++;
			}
			catch (Exception exn) {	
				RReporting.ShowExn(exn,"Fractal Render");
			}
			return bGood;
		}//end Render
Exemple #2
0
		public bool RenderIncrement(GBuffer gbDest, IRect rectDest) {
			bool bGood=true;
			try {
				gbFractal.SetPixelArgb(400,300, 255,255,0,0);//debug only
				if (!FinishedRenderingAll()) {
					iTickStartPrev=iTickStart;
					iTickStart=PlatformNow.TickCount;
					if (iTickStartPrev!=-1) {//&&iTickStart!=-1) {
						iTicksPerFrame=iTickStart-iTickStartPrev;
						//if (iTicksPerFrame>iMaxUsableTicksPerFrame_ElseIgnoreFrameRate) {
							//TODO: fix this: //FRACTALREAL rPerformanceScaler=(FRACTALREAL)iMaxUsableTicksPerFrame_ElseIgnoreFrameRate/(FRACTALREAL)iTicksPerFrame;
							//TODO: fix this: iMaxPPF=(int)((FRACTALREAL)iMaxPPF*rPerformanceScaler);
							if (iMaxPPF<1) iMaxPPF=1;
						//}
					}
					int iPixelRel=0;
					while (iPixelRel<iMaxPPF&&iPixelsRendered<gbFractal.iPixelsTotal) {
						//xSrc+=rPassUnitsPerChunk;
						if (xDest>=gbFractal.Width) {
							xDest=0;
							yDest+=iPassPixelsPerChunk;
							xSrc=xSrcStart;
							//ySrc+=rPassUnitsPerChunk;
						}
						xSrc=XPixelToUnitLocation(xDest);
						ySrc=YPixelToUnitLocation(yDest);
						
						if (yDest<gbFractal.Height) {
							//gbFractal.SetPixelRgb(xDest,yDest, 255,0,0);//debug only
	
							//float rFractalness=(float)(ResultMandelbrot((float)xSrc,(float)ySrc)%255)/255.0f;
							//TODO: finish this--use rSeed
							//double rFractalness=(double)(ResultMandelbrot((double)xSrc,(double)ySrc)%255)/255.0;
							
							//if (RMath.Dist(RMath.IRound(gbFractal.Width/2),RMath.IRound(gbFractal.Height/2),xDest,yDest)<iDetailRadius) {
							if (iPass==1||RMath.Dist((double)(gbFractal.Width/2.0),(double)(gbFractal.Height/2.0),(double)xDest,(double)yDest)<(double)iDetailRadius) {
								FRACTALREAL rFractalness=(FRACTALREAL)(ResultMandelbrot((FRACTALREAL)xSrc,(FRACTALREAL)ySrc)%255)/fr255;
								if (iPassPixelsPerChunk>1) {
									GBuffer.SetBrushHsva(rFractalness,1.0,rFractalness,1.0);
									gbFractal.DrawRectCroppedFilled(xDest,yDest,iPassPixelsPerChunk,iPassPixelsPerChunk);
								}
								else gbFractal.SetPixelHsva(xDest,yDest,rFractalness,1.0,rFractalness,1.0);
								//xSrc+=rPassUnitsPerChunk;
							}
							
							iPixelsRendered++;
							iPixelRel++;
						}//end if yDest<gbFractal.Height
						else break;//finished rendering frame
						xDest+=iPassPixelsPerChunk;
					}//end while iPixelRel<iMaxPPF
					
					//TODO: finish this
					if (FinishedRenderingFrame()) {
						iPass++;//must be incremented BEFORE ResetLocations (before OnSetPass)
						ResetLocations();//DOES OnStartPass
						iFramesRendered++;
					}
				}//end if !FinishedRenderingAll
				//gbFractal.SetPixelArgb(400,300, 255,0,255,0);//debug only
				if (!gbDest.Draw(rectDest,gbFractal)) {
					bGood=false;
					RReporting.Warning("Couldn't draw Fractal buffer to destination.","{gbFractal:"+GBuffer.VariableMessage(gbFractal)+"; gbDest:"+GBuffer.VariableMessage(gbDest)+"; rectDest:"+rectDest.Description()+"}");
				}
			}
			catch (Exception exn) {
				bGood=false;
				RReporting.ShowExn(exn,"Fractal RenderIncrement","rendering fractal increment");
			}
			return bGood;
		}//end RenderIncrement