Beispiel #1
0
void buildPoly(int i){
  
  double xx[20], yy[20], zz[20] ;
  double xpoly[20], ypoly[20];
  int j,k,n;
  
  n = shapes[polyDistance[i].objNum][polyDistance[i].polyNum][0];
  
  for(j=1;j<=n;j++){
    xx[j-1] = xp[polyDistance[i].objNum][shapes[polyDistance[i].objNum][polyDistance[i].polyNum][j]] ;
    yy[j-1] = yp[polyDistance[i].objNum][shapes[polyDistance[i].objNum][polyDistance[i].polyNum][j]] ;
    zz[j-1] = zp[polyDistance[i].objNum][shapes[polyDistance[i].objNum][polyDistance[i].polyNum][j]] ;
  }
  
  for(j=0;j<n;j++){
    xpoly[j] = (300/H)*xx[j]/zz[j] + 300 ;
    ypoly[j] = (300/H)*yy[j]/zz[j] + 300 ;
  }
  
  if(thisObj == polyDistance[i].objNum){
    calcColor(xx, yy, zz, 1, .4, .4);
  }else{
    calcColor(xx, yy, zz, .1,.3,.6);
  }
  
  G_fill_polygon(xpoly, ypoly, n);
  //G_rgb(0,0,0);
  //G_polygon(xpoly, ypoly, n);
  
  
} 
Beispiel #2
0
int calcPass(int u, int v, int cur){
	if(calcColor(u, cur) == calcColor(v, cur))
		return cur;
	int a = cur, b = cur;
	for(int i = 0;i < 3; ++i){
		a = calcAlter(u, a);
		b = calcAlter(v, b);
		if(a != b)
			return a < b ? a : b;
	}
	return Inf;
}
Beispiel #3
0
void Star::draw(){
	glBegin(GL_POINT);
	Vector4<double> color = calcColor();
	glColor4d(color.getX(),color.getY(),color.getZ(),color.getA());
	glVertex2d(pos.getX(),pos.getY());
	glEnd();
}
Beispiel #4
0
/**
 * Performs a raytrace on the given pixel on the current scene.
 * The pixel is relative to the bottom-left corner of the image.
 * @param scene The scene to trace.
 * @param x The x-coordinate of the pixel to trace.
 * @param y The y-coordinate of the pixel to trace.
 * @param width The width of the screen in pixels.
 * @param height The height of the screen in pixels.
 * @return The color of that pixel in the final image.
 */
static Color3 trace_pixel( const Scene* scene, size_t x, size_t y, size_t width, size_t height )
{
    ray_t tRay;
    real_t time;
    real_t bestTime = 100000;
    ray_t bestRay;
    int bestGeom;

    assert( 0 <= x && x < width );
    assert( 0 <= y && y < height );

    ray_t curRay = getRay(scene, x, y, width, height);

    Geometry* const* geometries = scene->get_geometries();
    Material* const* materials = scene->get_materials();

    for ( size_t i = 0; i < scene->num_geometries(); i++ ) {
        Geometry& geom = *geometries[i];
        tRay = transform(curRay, geom);
        time = geom.intersect(tRay);
        real_t lastTime = time;
        time = time / lastLength;
        if( (time > 0) && (time < bestTime) ) {
            bestTime = time;
            bestGeom = i;
        }
    }

    if(bestTime < 100000)
        return calcColor(bestTime, curRay, bestGeom, scene, MAX_DEPTH);
    else
        return scene->background_color;
}
Beispiel #5
0
Color3 traceSpecularColor(ray_t reflectedRay, const Scene* scene, int depth, int thisGeom) {

    ray_t tRay;
    real_t time;
    real_t bestTime = 100;
    int bestGeom;

    Geometry* const* geometries = scene->get_geometries();
    Material* const* materials = scene->get_materials();

    for ( size_t i = 0; i < scene->num_geometries(); i++ ) {
        Geometry& geom = *geometries[i];
        tRay = transform(reflectedRay, geom);
        time = geom.intersect(tRay);
        if( (time > SLOP_FACTOR) && (time < bestTime) && (i != thisGeom) ) {
            bestTime = time;
            bestGeom = i;
        }
    }

    if(bestTime < 100)
        return calcColor(bestTime, reflectedRay, bestGeom, scene, depth);
    //	return (*geometries[bestGeom]).getAmbientColor();
    else
        return scene->background_color;

}
Beispiel #6
0
Sphere::Sphere(QPoint coord1, QPoint size1)
{
    coord = coord1;
    step  = calcStep();
    size = size1;
    color = calcColor();
    brush = 2;
}
Beispiel #7
0
static int  alldiagrams(FILE * fd,  int nsub)
{  
   marktp     bh;
   varptr     totnum, totdenum, rnum;
   long       pos_c1,pos_c2; int deg1,deg2,tmpn1,tmpn2, nC;
   catrec     cr;
   deninforec dendescript;

   mark_(&bh); tmpNameMax=0; initinfo(); initdegnames();

   writeF("{\n");
   writeF("REAL N,D,R; COMPLEX Prop;\n");
   pos_c1= ftell(outFile); writeF("%70s\n","");   
   writeF("if(CalcConst) C%d(C);\n",nsub);

   while(FREAD1(dendescript,fd) == 1)
   {
      fseek(catalog,dendescript.cr_pos,SEEK_SET);
      FREAD1(cr,catalog); ++(diagrcount);
      if(!noPict)writpict(cr.ndiagr_ + inftmp->firstdiagpos - 1);
      whichArchive(cr.nFile,'r');
      fseek(archiv,cr.factpos,SEEK_SET);

      readvardef(archiv);
      readpolynom(&totnum);
      readpolynom(&totdenum);
      clearvardef();
   
      fseek(archiv,cr.rnumpos,SEEK_SET);

      readvardef(archiv);
      readpolynom(&rnum);
      clearvardef();
   
      fortwriter("N",totnum);
      fortwriter("D",totdenum);

      fortwriter("R",rnum);

      writeF("R*=(N/D);\n");
      if(nin+nout>3)
      {  writeF("Prop=1");
         writeDenominators(&dendescript);
         writeF("R*=creal(Prop);\n");
         writeF(" if(R>Fmax) Fmax=R; else if(R<-Fmax) Fmax=-R;\n");
      } else  writeF(";\n");
      if(!noCChain)calcColor(cr.ndiagr_+inftmp->firstdiagpos);
      writeF("ans+=R;\n");
   }   
   whichArchive(0,0);
   writeF("\n}\nreturn ans;\n}\n");

   deg1=cleardegnames();
   tmpn1=tmpNameMax;
   tmpNameMax=0;
   initdegnames();

   writeF("\nstatic void C%d(REAL*C)\n{\n",nsub); 
   writeF("  REAL* V=va_ext;\n");
   pos_c2= ftell(outFile); writeF("%70s\n","");   

   nC=write_const(); 
   if(nC==0) nC=1; 
   writeF("}\n");

   fseek(outFile,pos_c1,SEEK_SET); 
   writeF("static REAL C[%d];",nC); 
   if(deg1) writeF("REAL S[%d];",deg1);
   if(tmpn1) writeF("REAL tmp[%d];",tmpn1); 

 
   fseek(outFile,pos_c2,SEEK_SET);
   deg2=cleardegnames();
   tmpn2=tmpNameMax;
   if(deg2) writeF("REAL S[%d];",deg2) ;
   if(tmpn2) writeF("REAL tmp[%d];",tmpn2 );
   fseek(outFile,0,SEEK_END);

   release_(&bh);
   if( escpressed()) return 1; else return 0;
}
Beispiel #8
0
static void  onediagram(deninforec* dendescript)
{  catrec      cr;
   marktp      bh;
   varptr      totnum, totdenum, rnum;
   long pos_c;
   int deg1,nConst;

   mark_(&bh);
   tmpNameMax=0;
   initinfo();
   initdegnames();
   
   fseek(catalog,dendescript->cr_pos,SEEK_SET);
   FREAD1(cr,catalog);
   ++(diagrcount);
   whichArchive(cr.nFile,'r');

   fseek(archiv,cr.factpos,SEEK_SET);
    
   readvardef(archiv);
   readpolynom(&totnum);
   readpolynom(&totdenum);
   clearvardef();
   
   fseek(archiv,cr.rnumpos,SEEK_SET);

   readvardef(archiv);
   readpolynom(&rnum);
   clearvardef();

   {  outFileOpen("%sresults%cf%d.c",pathtouser,f_slash,diagrcount);
      labl();
      writeF("#include\"num_out.h\"\n");
      writeF("#include\"num_in.h\"\n");   
   }
   writeF("extern FNN F%d_ext;\n",diagrcount);
   writeF("static void C%d(REAL * C)\n{\n",diagrcount);
   writeF("REAL* V=va_ext;\n");
   pos_c= ftell(outFile); writeF("%80s\n",""); 
   nConst=write_const();
   deg1=cleardegnames();       
   writeF("}\n"); 

   fseek(outFile,pos_c,SEEK_SET);
   if(deg1) writeF("REAL S[%d];",deg1);
   if(tmpNameMax) writeF("REAL tmp[%d];",tmpNameMax );                                

   fseek(outFile,0,SEEK_END);
   tmpNameMax=0;
   initdegnames();

   writeF("REAL F%d_ext(double GG,REAL*DP,REAL*Q0,COMPLEX*Q1,REAL*Q2)\n{\n",diagrcount);

   if(!noPict) writpict(cr.ndiagr_ + inftmp->firstdiagpos - 1);

   writeF("REAL N,D,R; COMPLEX Prop;\n");
   writeF("REAL * V=va_ext;\n");
   pos_c= ftell(outFile); writeF("%80s\n","");
  
   writeF("if(CalcConst) C%d(C);\n",diagrcount);
   
   fortwriter("N",totnum);
   fortwriter("D",totdenum);
   fortwriter("R",rnum);
   
   writeF("R*=(N/D);\n");
   writeF("Prop=1");
   writeDenominators(dendescript);
   writeF("R*=creal(Prop);\n");
   if(!noCChain)calcColor(cr.ndiagr_+inftmp->firstdiagpos);

   writeF(" return R;\n");  
   writeF("}\n");

   deg1=cleardegnames();
   if(nConst==0) nConst=1;
   fseek(outFile,pos_c,SEEK_SET);
   writeF("static REAL C[%d];",nConst);
   if(deg1) writeF("REAL S[%d];",deg1);
   if(tmpNameMax) writeF("REAL tmp[%d];",tmpNameMax );
   fseek(outFile,0,SEEK_END);
   outFileClose();
   release_(&bh);
}
Beispiel #9
0
uint8_t sendLine(uint32_t fxyze[], uint32_t abs_dxyze[], uint8_t dir_xyze[])
{
	uint32_t f = 0;
	uint32_t i, n = 0;

	for (i = 0; i < 3; i++)
	{
		if (fxyze[i] > f)
		{
			f = fxyze[i];
			n = i;
		}
	}
	// if(abs_dxyze[n] > 20) {
	//  for(i = 0; i < 4; i++) fxyze[i] = (uint32_t)((uint64_t)f * (uint64_t)abs_dxyze[i]/abs_dxyze[n]);
	if (abs_dxyze[n] > 10)
	{
		for (i = 0; i < 4; i++)
			if (i != n)
			{
				fxyze[i] = (uint32_t)(((uint64_t)f * (uint64_t)abs_dxyze[i]) / abs_dxyze[n]) + 1; //+1 for debug
			}
	}
	if ((curGCodeMode & GFILE_MODE_MASK_EXEC) == 0)
	{
		int i;
		for (i = 0; i < 4; i++)
			if (fxyze[i] != 0)
			{
				commonTimeReal += abs_dxyze[i] * 1000L * K_FRQ / fxyze[i];
				break;
			}

		if ((curGCodeMode & GFILE_MODE_MASK_SHOW) != 0)
		{
			if (dir_xyze[0])	linesBuffer.stepsX += abs_dxyze[0];
			else				linesBuffer.stepsX -= abs_dxyze[0];

			if (dir_xyze[1])	linesBuffer.stepsY += abs_dxyze[1];
			else				linesBuffer.stepsY -= abs_dxyze[1];

			if (dir_xyze[2])	linesBuffer.stepsZ += abs_dxyze[2];
			else				linesBuffer.stepsZ -= abs_dxyze[2];

#if (USE_LCD != 0)
			double x, y;
			short scrX, scrY;

			x = (double)linesBuffer.stepsX / SM_X_STEPS_PER_MM;
			y = (double)linesBuffer.stepsY / SM_Y_STEPS_PER_MM;

			scrX = crdXtoScr(TABLE_CENTER_X + x);
			scrY = crdYtoScr(TABLE_CENTER_Y + y);

			if (scrX != prev_scrX || prev_scrY != scrY)
				scr_Line(prev_scrX, prev_scrY, scrX, scrY, calcColor((uint8_t)(linesBuffer.stepsZ * 5 / SM_X_STEPS_PER_MM) & 0x1F));
			prev_scrX = scrX;
			prev_scrY = scrY;
#endif
		}
		return true;
	}
#ifdef DEBUG_MODE
	DBG("\n\tsendLine dx:%c%d(%d)\tdy:%c%d(%d)\tdz:%c%d(%d) tz:%d ty:%d tz:%d",
		dir_xyze[0] ? '+' : '-', abs_dxyze[0], fxyze[0],
		dir_xyze[1] ? '+' : '-', abs_dxyze[1], fxyze[1],
		dir_xyze[2] ? '+' : '-', abs_dxyze[2], fxyze[2],
		fxyze[0] == 0 ? 0 : abs_dxyze[0] * 1000L * K_FRQ / fxyze[0],
		fxyze[1] == 0 ? 0 : abs_dxyze[1] * 1000L * K_FRQ / fxyze[1],
		fxyze[2] == 0 ? 0 : abs_dxyze[2] * 1000L * K_FRQ / fxyze[2]);
	{
		static uint32_t prevF[3] = { 0, 0, 0 };
		static uint8_t prevDir[3] = { 0, 0, 0 };
		int i;

		for (i = 0; i < 3; i++)
		{
			double p;
			if ((p = labs(prevF[i] - fxyze[i]) / (double)_smParam.smoothStartF_from0[i]) > 1.5)
			{
				p *= 100;
				DBG(" !!!!!! <%d:%d/%d\t%f> %s", i, labs(prevF[i] - fxyze[i]), _smParam.smoothStartF_from0[i], p, p > 250 ? "$$$" : "");
			}
			if (prevDir[i] != dir_xyze[i] && (p = fxyze[i] / (double)_smParam.smoothStartF_from0[i]) > 1.5)
			{
				p *= 100;
				DBG(" !!!!!! ## <%d:%d/%d\t%f> %s", i, labs(prevF[i] - fxyze[i]), _smParam.smoothStartF_from0[i], p, p > 250 ? "$$$" : "");
			}
			if (fxyze[i] > _smParam.maxFeedRate[i])
			{
				DBG(" !!!!!! <%d:%d/%d too hight feedrate!> ", i, fxyze[i], _smParam.maxFeedRate[i]);
			}
			if (fxyze[i] < (50 * SM_X_STEPS_PER_MM / 60) && abs_dxyze[i] > 120)
			{
				DBG(" !!!!!! <%d:%d too slow feedrate!> ", i, fxyze[i]);
			}
		}
		for (i = 0; i < 3; i++)
		{
			prevF[i] = fxyze[i];
			prevDir[i] = dir_xyze[i];
		}
	}
#endif

	if (!cnc_waitSMotorReady())
		return false;

	if (isPause)
	{
#if (USE_KEYBOARD != 0)
	#if (USE_KEYBOARD == 2)
		const TPKey_p * tp_save;
		tp_save = SetTouchKeys(kbdPause);
	#endif
	#if (USE_KEYBOARD == 1)
		scr_fontColor(Black, White);
		scr_gotoxy(1, 13);
		scr_puts(" PAUSE..'B'-continue 'C'-cancel");
		scr_clrEndl();
	#endif
		while (stepm_inProc()) { }
		stepm_EmergeStop();

		while (isPause)
		{
			switch (kbd_getKey())
			{
			case KEY_C:
				isPause = false;
	#if (USE_KEYBOARD == 2)
				SetTouchKeys(tp_save);
	#endif
				return false;
			case KEY_B:
				isPause = false;
			}
		}

	#if (USE_KEYBOARD == 1)
		scr_fontColor(White, Black);
		scr_gotoxy(1, 13);
		scr_clrEndl();
	#endif
	#if (USE_KEYBOARD == 2)
		SetTouchKeys(tp_save);
	#endif
#endif
	}
	stepm_addMove(abs_dxyze, fxyze, dir_xyze);
	return true;
}
Beispiel #10
0
void calcColor(unsigned char* toFill,Autonoma* c, Ray ray, unsigned int depth){
   double curTime;
   Shape* curShape = NULL;
   ShapeNode* t = c->listStart;
   unsigned int data1;
   double data2, data3;
   unsigned int tdata1;
   double tdata2, tdata3;
   while(t!=NULL){
      double time = t->data->getIntersection(ray, &tdata1, &tdata2, &tdata3);
      if(time !=inf && (curShape==NULL || curTime > time)){
         curTime = time;
         curShape = t->data;
         data1 = tdata1; data2 = tdata2; data3 = tdata3;
         //printf("II\n");
         //printf("I: \t%u\n", data1);
      }
      t = t->next;
   }
   if(curShape==NULL){
      double opacity, reflection, ambient;
      if(c->skybox->constant())
         c->skybox->getColor(toFill, &ambient, &opacity, &reflection, 0., 0.);
      else{
         Vector temp = ray.vector.normalize();
         const double x = temp.x;
         const double z = temp.z;
         const double me = (temp.y<0)?-temp.y:temp.y;
         const double angle = atan2(z, x);
         c->skybox->getColor(toFill, &ambient, &opacity, &reflection, fix(angle/M_TWO_PI),fix(me));
      }
   }
   else{
      Vector intersect = curTime*ray.vector+ray.point;
      double opacity, reflection, ambient;
      if(curShape->texture->constant())
         curShape->texture->getColor(toFill, &ambient, &opacity, &reflection, 0., 0.);
      else
         curShape->getColor(toFill, &ambient, &opacity, &reflection, c, Ray(intersect, ray.vector), depth, &data1, &data2, &data3);
      
      double lightData[3];
      getLight(lightData, c, intersect, curShape->getNormal(intersect, &data1, &data2, &data3), curShape->reversible(&data1, &data2, &data3));
      toFill[0] = (unsigned char)(toFill[0]*(ambient+lightData[0]*(1-ambient)));
      toFill[1] = (unsigned char)(toFill[1]*(ambient+lightData[1]*(1-ambient)));
      toFill[2] = (unsigned char)(toFill[2]*(ambient+lightData[2]*(1-ambient)));
      if(depth<c->depth && (opacity<1-1e-6 || reflection>1e-6)){
         unsigned char col[4];
         if(opacity<1-1e-6){
            Ray nextRay = Ray(intersect+ray.vector*1E-4, ray.vector);
            calcColor(col, c, nextRay, depth+1);
            toFill[0]= (unsigned char)(toFill[0]*opacity+col[0]*(1-opacity));
            toFill[1]= (unsigned char)(toFill[1]*opacity+col[1]*(1-opacity));
            toFill[2]= (unsigned char)(toFill[2]*opacity+col[2]*(1-opacity));
        
         // if(toFill[0]==255 && toFill[1]==255 && toFill[2]==255) printf("WTF\n");
          //  printf("%d %d %d ||%d %d %d %f %f %f\n", toFill[0], toFill[1], toFill[2], col[0], col[1], col[2], nextRay.point.x, nextRay.point.y, nextRay.point.z);
         }
         if(reflection>1e-6){
            Vector norm = curShape->getNormal(intersect, &data1, &data2, &data3).normalize();
            Vector vec = ray.vector-2*norm*(norm.dot(ray.vector));
            Ray nextRay = Ray(intersect+vec*1E-4, vec);
            calcColor(col, c, nextRay, depth+1);
         
            toFill[0]= (unsigned char)(toFill[0]*(1-reflection)+col[0]*(reflection));
            toFill[1]= (unsigned char)(toFill[1]*(1-reflection)+col[1]*(reflection));
            toFill[2]= (unsigned char)(toFill[2]*(1-reflection)+col[2]*(reflection));
         }
      }
      
   }
}