Beispiel #1
0
void ShowRotation(Basis_3& xyz_basis,void drawfunc(void),int swappages){
 Basis_3  rot(1,0,0,
              0,1,0,
              0,0,1);
 float alf;
 int page=0,ind,cont=0;
 char h;
 if(swappages){
  setactivepage(page);
  setvisualpage(page);
 }
 cleardevice();
 drawfunc();

 do{
  while(kbhit())h=getch();
  switch(h){
   case 'x':
    ind=1;
    break;
   case 'X':
    ind=-1;
    break;
   case 'y':
    ind=2;
    break;
   case 'Y':
    ind=-2;
    break;
   case 'z':
    ind=3;
    break;
   case 'Z':
    ind=-3;
    break;
   case ' ':
    cont=1-cont;
    h=0;
    break;
   default:
    ind=0;
  }
  if(ind){
   if(ind<0){
    ind=-ind;
    ind--;
    alf=-0.1; //-rot[ind].angle;
   }
   else { alf=0.1;--ind;} //rot[--ind].angle;
   xyz_basis=RotateBasis(xyz_basis,rot.vec[ind],alf);
   if(swappages)setactivepage(page=1-page);
   cleardevice();
   drawfunc();
   if(swappages)setvisualpage(page);
   ind=0;
   if(!cont)h=0;
  }
 }while(h!=27);
}
Beispiel #2
0
void redraw(void (*drawfunc)(Screencell*,unsigned int,unsigned int),bool copyover,bool forceredraw){
	unsigned int scrwidth,scrheight;
	tie(scrwidth,scrheight)=IO::screensize();
	const bool validprev=prevscreen&&scrwidth==prevwidth&&scrheight==prevheight;
	Screencell *newscreen=new Screencell[scrwidth*scrheight];
	//cerr<<"redraw: validprev="<<validprev<<" copyover="<<copyover<<" prevscreen?="<<!!prevscreen<<endl;
	if(copyover&&validprev)
		memcpy(newscreen,prevscreen,scrwidth*scrheight*sizeof(Screencell));
	drawfunc(newscreen,scrwidth,scrheight);
	if(!validprev||forceredraw){
		copytoscreen(newscreen,scrwidth,0,0,scrwidth,scrheight);
		if(prevscreen)delete[] prevscreen;
		prevwidth=scrwidth;
		prevheight=scrheight;
		prevscreen=new Screencell[scrwidth*scrheight];
		assert(prevscreen);
		memcpy(prevscreen,newscreen,scrwidth*scrheight*sizeof(Screencell));
	} else {
		unsigned int x,y;
		for(y=0;y<scrheight;y++){
			for(x=0;x<scrwidth;x++){
				if(prevscreen[scrwidth*y+x]!=newscreen[scrwidth*y+x])break;
			}
			if(x<scrwidth){
				//cerr<<"refreshing line "<<y<<" (diff at x="<<x<<')'<<endl;
				copylinetoscreen(newscreen,scrwidth,0,y,scrwidth);
			}
		}
		memcpy(prevscreen,newscreen,scrwidth*scrheight*sizeof(Screencell));
	}
	gotoFrontBufferCursor();
	cout.flush();
}
void PolyTriangleDrawer::draw_shaded_triangle(const TriVertex *vert, bool ccw, TriDrawTriangleArgs *args, WorkerThreadData *thread, void(*drawfunc)(const TriDrawTriangleArgs *, WorkerThreadData *))
{
	// Cull, clip and generate additional vertices as needed
	TriVertex clippedvert[max_additional_vertices];
	int numclipvert;
	clipedge(vert, clippedvert, numclipvert);

	// Map to 2D viewport:
	for (int j = 0; j < numclipvert; j++)
	{
		auto &v = clippedvert[j];

		// Calculate normalized device coordinates:
		v.w = 1.0f / v.w;
		v.x *= v.w;
		v.y *= v.w;
		v.z *= v.w;

		// Apply viewport scale to get screen coordinates:
		v.x = viewport_x + viewport_width * (1.0f + v.x) * 0.5f;
		v.y = viewport_y + viewport_height * (1.0f - v.y) * 0.5f;
	}

	// Draw screen triangles
	if (ccw)
	{
		for (int i = numclipvert; i > 1; i--)
		{
			args->v1 = &clippedvert[numclipvert - 1];
			args->v2 = &clippedvert[i - 1];
			args->v3 = &clippedvert[i - 2];
			drawfunc(args, thread);
		}
	}
	else
	{
		for (int i = 2; i < numclipvert; i++)
		{
			args->v1 = &clippedvert[0];
			args->v2 = &clippedvert[i - 1];
			args->v3 = &clippedvert[i];
			drawfunc(args, thread);
		}
	}
}
Beispiel #4
0
static void _skycolumn (void (*drawfunc)(void), int x)
{
	dc_yl = _skypl->top[x];
	dc_yh = _skypl->bottom[x];

	if (dc_yl != -1 && dc_yl <= dc_yh)
	{
		int angle = ((((viewangle + xtoviewangle[x])^skyflip)>>sky1shift) + frontpos)>>16;

		dc_texturefrac = dc_texturemid + (dc_yl - centery + 1) * dc_iscale;
		dc_source = R_GetColumnData(skytex, angle);
		drawfunc ();
	}