示例#1
0
void render_rect(WILLUSBITMAP *bmp,double x1,double y1,
                                double x2,double y2,
                                RENDER_COLOR *fgc,RENDER_COLOR *bgc,
                                int render_type)

    {
    TRIANGLE2D t;
/*
    RENDER_COLOR fg,bg;

    bg.rgb[0]=bg.rgb[1]=bg.rgb[2]=1.0;
    fg.rgb[0]=r/255.;
    fg.rgb[1]=g/255.;
    fg.rgb[2]=b/255.;
*/
    t.p[0]=p2d_point(x1,y1);
    t.p[1]=p2d_point(x1,y2);
    t.p[2]=p2d_point(x2,y2);
// printf("(%g,%g) - (%g,%g)\n",x1*bmp->width,y1*bmp->height,x2*bmp->width,y2*bmp->height);
    render_triangle(bmp,&t,fgc,bgc,render_type);
    t.p[0]=p2d_point(x1,y1);
    t.p[1]=p2d_point(x2,y1);
    t.p[2]=p2d_point(x2,y2);
    render_triangle(bmp,&t,fgc,bgc,render_type);
    }
示例#2
0
/*
** render_circle() is AS FRACTION OF BITMAP, NOT POINTS
*/
void render_circle(WILLUSBITMAP *bmp,double xc,double yc,double xradius,
                   int nsteps,RENDER_COLOR *rcolor,RENDER_COLOR *bgcolor,
                   int render_type)

    {
    int i;
    double ar;

    if (nsteps<0)
        {
        nsteps=xradius*bmp->width*1.33; // Makes a pretty good circle
        if (nsteps<8)
            nsteps=8;
        }
    ar=(double)bmp->width/bmp->height;
    for (i=0;i<nsteps;i++)
        {
        double th1,th2;
        TRIANGLE2D tri;

        th1=i*2.*PI/nsteps;
        th2=(i==nsteps-1)?0.:(i+1)*2.*PI/nsteps;
        tri.p[0].x = xc;
        tri.p[0].y = yc;
        tri.p[1].x = xc+xradius*cos(th1);
        tri.p[1].y = yc+xradius*ar*sin(th1);
        tri.p[2].x = xc+xradius*cos(th2);
        tri.p[2].y = yc+xradius*ar*sin(th2);
        render_triangle(bmp,&tri,rcolor,bgcolor,render_type);
        }
    }
示例#3
0
void render_tri_pts(double x1,double y1,double x2,double y2,
                    double x3,double y3)

    {
    TRIANGLE2D tri;

    tri.p[0]=p2d_point(x1/width_pts,y1/height_pts);
    tri.p[1]=p2d_point(x2/width_pts,y2/height_pts);
    tri.p[2]=p2d_point(x3/width_pts,y3/height_pts);
    render_triangle(lbmp,&tri,&lfgc,&lbgc,lrtype);
    }
示例#4
0
render_object *render_object_triangles() {
	render_object *o = render_object_create("background");
	render_object_triangles_data *d = calloc(1, sizeof(render_object_triangles_data));
	o->data = d;
	o->render = render_object_triangles_render;
	o->free = render_object_triangles_free;

	d->triangle = glGenLists(1);
	glNewList(d->triangle, GL_COMPILE);
	render_triangle();
	glEndList();
	return o;
}
示例#5
0
static void
frame_callback(void *data, struct wl_callback *callback, uint32_t time)
{
  //  printf ("client: frame_callback start\n");
  struct nested_client *client = data;

  if (callback)
    wl_callback_destroy(callback);

  callback = wl_surface_frame(client->surface);
  wl_callback_add_listener(callback, &frame_listener, client);

  render_triangle(client, time);

  eglSwapBuffers(client->egl_display, client->egl_surface);
  //  printf ("client: frame_callback end\n");
}
示例#6
0
void render_frame() {
    /* Clear the color and depth buffers */
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    /* Draw the triangle on the left side*/
    glPushMatrix();
    glTranslatef(-2, 0, 0);  
    render_triangle();
    glPopMatrix();

    /* Draw the cube with some rotation on the right side */
    glPushMatrix();

    /* EDIT: Timing control for the animation! */
    static unsigned previous_time = 0;
    unsigned current_time = SDL_GetTicks();
    unsigned elapsed_time = current_time - previous_time;
    previous_time = current_time;
	
    /* Make the cube rotate around a little */
    static float angle1 = 0.0f;
    static float angle2 = 0.0f;
    angle1 += 0.1f * elapsed_time;
    angle2 += 0.05f * elapsed_time; 

    glTranslatef(2, 0, 0);
    glRotatef(angle1, 0, 1, 0);
    glRotatef(angle2, 1, 0, 0);
    render_cube();
    glPopMatrix();

    /* Present the frame buffer */
    SDL_GL_SwapBuffers();
}
示例#7
0
文件: L3View.c 项目: deeice/ldglite
int Draw1PartPtr(struct L3LineS *LinePtr, int Color)
{
	float          m1[4][4];
	int CurColor = ldraw_commandline_opts.C;
	int SaveColor;

	int            i;
	float          r[4];
	vector3d       v3d[4];

	if (!LinePtr)
	  return 0;

	InitViewMatrix();
	include_stack_ptr = 1; // Start nesting level pointer at 1.

	SaveColor = LinePtr->Color;
	if (Color < 0) 
	    Color = LinePtr->Color;
	else
	    LinePtr->Color = Color;
	switch (Color)
	{
	case 16:
	    Color = CurColor;
	    break;
	case 24:
#ifdef SIXTEEN_EDGE_COLORS
	    if (0 <= CurColor  &&  CurColor <= 15)
		Color = edge_color(CurColor);
	    else
		Color = 0;
#else
	    Color = edge_color(CurColor);
#endif
	    break;
	default:
	    break;
	}
	
	switch (LinePtr->LineType)
	{
	case 0:
	    break;
	case 1:
	    M4M4Mul(m1,m_m,LinePtr->v);
	    if ((ldraw_commandline_opts.F & TYPE_F_XOR_MODE) && (LinePtr->PartPtr->FromP))
	    {
		// This is a primitive and may render invisibly in TYPE_F_XOR_MODE
		// if it contains no edges.
		ldraw_commandline_opts.F |= TYPE_F_XOR_PRIMITIVE;
		DrawPart(0,LinePtr->PartPtr,Color,m1);
		ldraw_commandline_opts.F &= ~(TYPE_F_XOR_PRIMITIVE);
		break;
	    }
	    DrawPart(0,LinePtr->PartPtr,Color,m1);
	    break;
	case 2:
	    for (i=0; i<LinePtr->LineType; i++)
	    {
		M4V3Mul(r,m_m,LinePtr->v[i]);
		v3d[i].x=r[0];
		v3d[i].y=r[1];
		v3d[i].z=r[2];
	    }
	    render_line(&v3d[0],&v3d[1],Color);
	    break;
	case 3:
	    for (i=0; i<LinePtr->LineType; i++)
	    {
		M4V3Mul(r,m_m,LinePtr->v[i]);
		v3d[i].x=r[0];
		v3d[i].y=r[1];
		v3d[i].z=r[2];
	    }
	    //if (zWire)
	    if ((ldraw_commandline_opts.F & TYPE_F_NO_POLYGONS) ||
		(ldraw_commandline_opts.F & TYPE_F_XOR_MODE))
	    {
		// This would render invisibly in TYPE_F_XOR_MODE 
		// since it contains no edges.
		render_line(&v3d[0],&v3d[1],Color);
		render_line(&v3d[1],&v3d[2],Color);
		render_line(&v3d[2],&v3d[0],Color);
		break;
	    }
	    render_triangle(&v3d[0],&v3d[1],&v3d[2],Color);
	    break;
	case 4:
	    for (i=0; i<LinePtr->LineType; i++)
	    {
		M4V3Mul(r,m_m,LinePtr->v[i]);
		v3d[i].x=r[0];
		v3d[i].y=r[1];
		v3d[i].z=r[2];
	    }
	    //if (zWire)
	    if ((ldraw_commandline_opts.F & TYPE_F_NO_POLYGONS) ||
		(ldraw_commandline_opts.F & TYPE_F_XOR_MODE))
	    {
		// This would render invisibly in TYPE_F_XOR_MODE
		// since it contains no edges.
		render_line(&v3d[0],&v3d[1],Color);
		render_line(&v3d[1],&v3d[2],Color);
		render_line(&v3d[2],&v3d[3],Color);
		render_line(&v3d[3],&v3d[0],Color);
		break;
	    }
	    render_quad(&v3d[0],&v3d[1],&v3d[2],&v3d[3],Color);
	    break;
	case 5:
	    for (i=0; i<4; i++)
	    {
		M4V3Mul(r,m_m,LinePtr->v[i]);
		v3d[i].x=r[0];
		v3d[i].y=r[1];
		v3d[i].z=r[2];
	    }
	    if (ldraw_commandline_opts.F & TYPE_F_XOR_MODE)
	    {
		render_line(&v3d[0],&v3d[1],Color);
		render_line(&v3d[0],&v3d[2],Color);
		render_line(&v3d[1],&v3d[3],Color);
		break;
	    }
	    render_five(&v3d[0],&v3d[1],&v3d[2],&v3d[3],Color);
	    break;
	default:
	    break;
	}
	
	LinePtr->Color = SaveColor;
	return 1;
}
示例#8
0
文件: L3View.c 项目: deeice/ldglite
static void DrawPart(int IsModel, struct L3PartS *PartPtr, int CurColor, float m[4][4])
{
	float          r[4], m1[4][4];
	int            i, Color;
	struct L3LineS *LinePtr;
	vector3d       v3d[4];

#ifdef USE_OPENGL
	float mm[4][4];
	float det = 0;

	if ((ldraw_commandline_opts.F & TYPE_F_STUDLINE_MODE) != 0)
	  if (PartPtr->IsStud)
	  {
	    DrawPartLine(PartPtr, CurColor, m);
	    //DrawPartBox(PartPtr, CurColor, m, 1);
	    return;
	  }

	// Draw only bounding boxes of top level parts if in fast spin mode.
	if (ldraw_commandline_opts.F & TYPE_F_BBOX_MODE) 
	  if (PartPtr->FromPARTS) // (!IsModel)
	  {
	    if (ldraw_commandline_opts.F & TYPE_F_NO_POLYGONS) 
	      DrawPartBox(PartPtr, CurColor, m, 1);
	    else
	      DrawPartBox(PartPtr, CurColor, m, 0);
	    return;
	  }	

	  if (PartPtr->IsStud)
	    det = M3Det(m); // Check the determinant of m to fix mirrored studs.
#endif

	for (LinePtr = PartPtr->FirstLine; LinePtr; LinePtr = LinePtr->NextLine)
	{
#ifdef USE_OPENGL
                char *s;

	        if (Skip1Line(IsModel,LinePtr))
		  continue;
#endif
		hardcolor = 0; // Assume color 16 or 24.
		switch (LinePtr->Color)
		{
		case 16:
			Color = CurColor;
			break;
		case 24:
#ifdef SIXTEEN_EDGE_COLORS
			if (0 <= CurColor  &&  CurColor <= 15)
				Color = edge_color(CurColor);
			else
				Color = 0;
#else
			Color = edge_color(CurColor);
#endif
			break;
		default:
			Color = LinePtr->Color;
#if 0
			if ((LinePtr->LineType == 3) || 
			    (LinePtr->LineType == 4))
			  // Hardcoded color = printed.  Blend me!
			  hardcolor = 1; 
#else
			if (LinePtr->LineType != 1)
			  // Hardcoded color = printed.  Blend me!
			  hardcolor = 1; 
#endif
			break;
		}
		switch (LinePtr->LineType)
		{
		case 0:
#ifdef USE_OPENGL
		        // Skip whitespace
		        for (s = LinePtr->Comment; *s != 0; s++)
		        {
			  if ((*s != ' ') && (*s != '\t'))
			    break;
			}
			if (strnicmp(s,"STEP",4) == 0)
			{
			  // if (include_stack_ptr <= ldraw_commandline_opts.output_depth )
			  {
			    zStep(stepcount,1);
			    stepcount++;
			  }
			}
			else if (strncmp(s,"CLEAR",5) == 0)
			{
			  // if (include_stack_ptr <= ldraw_commandline_opts.output_depth )
			  {
			    zClear();
			  }
			}
			// Experiment with MLCAD extensions
			// Based on info provided on lugnet.
			else if (strncmp(s,"BUFEXCHG A STORE",16) == 0)
			{
			  int k;

			  if (IsModel)
			  {
			    k = BufA1Store(IsModel,LinePtr);
			    printf("BUFEXCHG A STORE %d\n", k);
			  }
			}
			else if (strncmp(s,"BUFEXCHG A RETRIEVE",19) == 0)
			{
			  int j,n, opts, dcp, cp;
			  extern int curpiece;
			  extern int DrawToCurPiece;
			  void DrawModel(void);
			   
			  if (IsModel)
			  {
			    n = BufA1Retrieve(IsModel,LinePtr);
			    printf("BUFEXCHG A RETRIEVE %d\n", n);
			    // clear and redraw model up to saved point.
#if 0		    
			    opts = ldraw_commandline_opts.M;
			    ldraw_commandline_opts.M = 'C';
			    dcp = DrawToCurPiece;
			    DrawToCurPiece = 1;
			    cp = curpiece;
			    zClear();
			    curpiece = n;
			    Init1LineCounter();
			    BufA1Store(IsModel,LinePtr);
			    DrawModel();
			    //for(j = 0; j < n; j++)
			    //  Draw1Part(j, -1);
			    DrawToCurPiece = dcp;
			    curpiece = cp;
			    ldraw_commandline_opts.M = opts;
#endif
			  }
			}
			else if (strncmp(s,"GHOST",5) == 0)
			{
			  if (IsModel)
			  {
			    // Parse the rest of the line as a .DAT line.
			  }
			}
			if (ldraw_commandline_opts.M != 'C')
			{
			  // Non-continuous output stop after each step.
			}

			// Parse global color change meta-commands
			// Should?? be done by ReadMetaLine() in L3Input.cpp			
			// Should SAVE old colors, restore after the for loop.
			// To save space, build a linked list of saved colors.
			// Do NOT resave a color if its already saved.
			if ((strncmp(s,"COLOR",5) == 0) ||
			    (strncmp(s,"COLOUR",6) == 0))
			{
			  if (ldraw_commandline_opts.debug_level == 1)
			    printf("%s\n", s);
			  //0 COLOR 4 red 0 196 0 38 255 196 0 38 255
			  char colorstr[256];
			  char name[256];
			  int n, inverse_index;

			  n = sscanf(s, "%s %d %s %d %f %f %f %f %f %f %f %f",
				     colorstr, &i, name, &inverse_index,
				     &m1[0][0], &m1[0][1], &m1[0][2], &m1[0][3],
				     &m1[1][0], &m1[1][1], &m1[1][2], &m1[1][3]);
			  if (n != 12)
			  {
			    if (ldraw_commandline_opts.debug_level == 1)
			      printf("Illegal COLOR syntax %d\n",n);
			    break;
			  }
			  zcolor_modify(i,name,inverse_index,
					(int)m1[0][0], (int)m1[0][1], (int)m1[0][2], (int)m1[0][3],
					(int)m1[1][0], (int)m1[1][1], (int)m1[1][2], (int)m1[1][3]);
			}

			// Intercept the ldconfig.ldr !COLOUR meta command.
			if (ldlite_parse_colour_meta(s))
			  break;
#else
			if (strncmp(LinePtr->Comment,"STEP",4) == 0)
			{
				// STEP encountered, you may set some flags to enable/disable e.g. drawing
				// (Note that I have not tested this, but this is the way it is supposed to work :-)
			}
#endif
			break;
		case 1:
#ifdef USE_OPENGL
    // NOTE:  I could achieve L3Lab speeds if I delay rendering studs till last
    // then do occlusion tests on the bounding boxes before rendering.
    // Unfortunately GL_OCCLUSION_TEST_HP is an extension (SUN, HP, ???)
    // 
    // Other ideas include substituting GLU cylinder primitives for studs.  
		        if (LinePtr->PartPtr->IsStud)
			{
                          if ((ldraw_commandline_opts.F & TYPE_F_STUDLESS_MODE) != 0)
                            break;
#ifdef USE_OPENGL_OCCLUSION
                          if ((ldraw_commandline_opts.F & TYPE_F_STUDONLY_MODE) != 0)
			  {
			    M4M4Mul(m1,m,LinePtr->v);
			    if (Occluded(LinePtr->PartPtr, Color, m1))
			      break;
			  }
#endif
			}	    
#endif
			M4M4Mul(m1,m,LinePtr->v);
#ifdef USE_OPENGL
			// Negative determinant means its a mirrored stud.
			if (det < 0)
			{
			  // For now, we only support Paul Easters logo.dat texture.
			  // For display speed, we really should precalculate an IsLogo flag
			  // and use that here rather than IsStud.
			  if  (LinePtr->PartPtr && LinePtr->PartPtr->DatName &&
			       !stricmp(LinePtr->PartPtr->DatName, "logo.dat"))
			  {
			    float mirror[4][4] = {
			      {1.0,0.0,0.0,0.0},
			      {0.0,1.0,0.0,0.0},
			      {0.0,0.0,-1.0,0.0},
			      {0.0,0.0,0.0,1.0}
			    };
			    M4M4Mul(mm,m1,mirror);
			    memcpy(m1,mm,sizeof(m1));
			  }
			}
			  
			// implement nesting level counter.
			include_stack_ptr++;
			DrawPart(0,LinePtr->PartPtr,Color,m1);
			include_stack_ptr--;	
			// Do zStep() after the model, not toplevel parts.
#else
			DrawPart(0,LinePtr->PartPtr,Color,m1);
			if (IsModel) zStep(0,0);
#endif
			break;
		case 2:
#ifdef USE_OPENGL_OCCLUSION
		        if ((ldraw_commandline_opts.F & TYPE_F_STUDONLY_MODE) &&
			    !(PartPtr->IsStud))
                            break;
#endif
			for (i=0; i<LinePtr->LineType; i++)
			{
				M4V3Mul(r,m,LinePtr->v[i]);
				v3d[i].x=r[0];
				v3d[i].y=r[1];
				v3d[i].z=r[2];
			}
			render_line(&v3d[0],&v3d[1],Color);
			break;
		case 3:
#ifdef USE_OPENGL_OCCLUSION
		        if ((ldraw_commandline_opts.F & TYPE_F_STUDONLY_MODE) &&
			    !(PartPtr->IsStud))
                            break;
#endif
			for (i=0; i<LinePtr->LineType; i++)
			{
				M4V3Mul(r,m,LinePtr->v[i]);
				v3d[i].x=r[0];
				v3d[i].y=r[1];
				v3d[i].z=r[2];
			}
#ifdef USE_OPENGL
			// Try to render solid Primitives visibly when in XOR wire mode.
			if (ldraw_commandline_opts.F & TYPE_F_XOR_PRIMITIVE)
			{
			    render_line(&v3d[0],&v3d[1],Color);
			    render_line(&v3d[1],&v3d[2],Color);
			    render_line(&v3d[2],&v3d[0],Color);
			    break;
			}
#endif
			render_triangle(&v3d[0],&v3d[1],&v3d[2],Color);
			break;
		case 4:
#ifdef USE_OPENGL_OCCLUSION
		        if ((ldraw_commandline_opts.F & TYPE_F_STUDONLY_MODE) &&
			    !(PartPtr->IsStud))
                            break;
#endif
			for (i=0; i<LinePtr->LineType; i++)
			{
				M4V3Mul(r,m,LinePtr->v[i]);
				v3d[i].x=r[0];
				v3d[i].y=r[1];
				v3d[i].z=r[2];
			}
#ifdef USE_OPENGL
			// Try to render solid Primitives visibly when in XOR wire mode.
			if (ldraw_commandline_opts.F & TYPE_F_XOR_PRIMITIVE)
			{
			    render_line(&v3d[0],&v3d[1],Color);
			    render_line(&v3d[1],&v3d[2],Color);
			    render_line(&v3d[2],&v3d[3],Color);
			    render_line(&v3d[3],&v3d[0],Color);
			    break;
			}
#endif
			render_quad(&v3d[0],&v3d[1],&v3d[2],&v3d[3],Color);
			break;
		case 5:
#ifdef USE_OPENGL_OCCLUSION
		        if ((ldraw_commandline_opts.F & TYPE_F_STUDONLY_MODE) &&
			    !(PartPtr->IsStud))
                            break;
#endif
			for (i=0; i<4; i++)
			{
				M4V3Mul(r,m,LinePtr->v[i]);
				v3d[i].x=r[0];
				v3d[i].y=r[1];
				v3d[i].z=r[2];
			}
			render_five(&v3d[0],&v3d[1],&v3d[2],&v3d[3],Color);
			break;
		}
	}
	if (((zDetailLevel == TYPE_PART) && (PartPtr->FromPARTS)) ||
	    ((zDetailLevel == TYPE_P) && (PartPtr->FromP)))
	  zStep(-1, 0);
}
示例#9
0
文件: rollext.cpp 项目: MASHinfo/mame
void rollext_renderer::process_display_list(uint32_t* disp_ram)
{
	const rectangle& visarea = screen().visible_area();

	render_delegate rd = render_delegate(&rollext_renderer::render_texture_scan, this);

	int num = disp_ram[0xffffc/4];

	for (int i=0; i < num; i++)
	{
		int ii = i * 0x60;

		vertex_t vert[4];

		//int x[4];
		//int y[4];

		// Poly data:
		// Word 0:   xxxxxxxx -------- -------- --------   Command? 0xFC for quads
		//           -------- -------- xxxxxxxx --------   Palette?
		//           -------- -------- -------- xxxxxxxx   Number of verts? (4 for quads)

		// Word 1:   xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Vertex 1 X

		// Word 2:   xxxxxxxx xxxxx--- -------- --------   Texture Origin Bottom
		//           -------- -----xxx xxxxxxxx --------   Texture Origin Left

		// Word 3:   xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Vertex 1 Y

		// Word 4:   -------- -------- xxxxxxxx xxxxxxxx   ?

		// Word 5:   xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Vertex 2 X

		// Word 6:   xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Unknown float

		// Word 7:   xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Vertex 2 Y

		// Word 8:   -------- -------- -------- --------   ?

		// Word 9:   xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Vertex 3 X

		// Word 10:  -------- -------- -------- --------   ?

		// Word 11:  xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Vertex 3 Y

		// Word 12:  -------- -------- -------- --------   ?

		// Word 13:  xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Vertex 4 X

		// Word 14:  -------- -------- -------- --------   ?

		// Word 15:  xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Vertex 4 Y

		// Word 16:  xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Unknown float

		// Word 17:  -------- -------- -------- --------   ?

		// Word 18:  xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Unknown float

		// Word 19:  -------- -------- -------- --------   ?

		// Word 20:  xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Unknown float

		// Word 21:  -------- -------- -------- --------   ?

		// Word 22:  xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx   Unknown float

		// Word 23:  -------- -------- -------- --------   ?

		for (int j=0; j < 4; j++)
		{
			uint32_t ix = disp_ram[(ii + (j*0x10) + 0x4) / 4];
			uint32_t iy = disp_ram[(ii + (j*0x10) + 0xc) / 4];

			vert[j].x = (int)((u2f(ix) / 2.0f) + 256.0f);
			vert[j].y = (int)((u2f(iy) / 2.0f) + 192.0f);
		}

		vert[0].p[0] = 0.0f;        vert[0].p[1] = 1.0f;
		vert[1].p[0] = 0.0f;        vert[1].p[1] = 0.0f;
		vert[2].p[0] = 1.0f;        vert[2].p[1] = 0.0f;
		vert[3].p[0] = 1.0f;        vert[3].p[1] = 1.0f;

		rollext_polydata &extra = object_data_alloc();

		extra.tex_bottom = (disp_ram[(ii + 8) / 4] >> 19) & 0x1fff;
		extra.tex_left = (disp_ram[(ii + 8) / 4] >> 8) & 0x7ff;
		extra.pal = (disp_ram[(ii + 0) / 4] >> 8) & 0x1f;

#if 0
		printf("P%d\n", i);
		for (int j=0; j < 6; j++)
		{
			printf("   %08X %08X %08X %08X", disp_ram[(ii + (j*0x10) + 0) / 4], disp_ram[(ii + (j*0x10) + 4) / 4], disp_ram[(ii + (j*0x10) + 8) / 4], disp_ram[(ii + (j*0x10) + 12) / 4]);
			printf("   %f %f %f %f\n", u2f(disp_ram[(ii + (j*0x10) + 0) / 4]), u2f(disp_ram[(ii + (j*0x10) + 4) / 4]), u2f(disp_ram[(ii + (j*0x10) + 8) / 4]), u2f(disp_ram[(ii + (j*0x10) + 12) / 4]));
		}
#endif

		render_triangle(visarea, rd, 4, vert[0], vert[1], vert[2]);
		render_triangle(visarea, rd, 4, vert[0], vert[2], vert[3]);

	}

	wait();
}
示例#10
0
void render_polyhedron (struct msscene *ms, struct surface *phn, double fine_pixel, long interpolate)
{
	int j, k, check, comp, hue, f, atm;
	int orn0, orn1, orn2;
	long t;
	long n_back, n_clipped, n_rendered;
	int vclipped[3], vback;
	double tcen[3];
	double trad;
	double tvertices[3][3];
	double tnormals[4][3];
	double tvalues[3];
	char message[MAXLINE];
	struct phnedg *edg0, *edg1, *edg2;
	struct phntri *tri;
	struct phnvtx *vtx, *vtxs[3];
    struct cept *ex;

	n_back = 0;
	n_clipped = 0;
	n_rendered = 0;
	f = (phn -> function[0]);
	if (phn -> phntri_handles == NULL) return;
	for (t = 0; t < phn -> n_phntri; t++) {
		tri = num2phntri (phn, t+1);
		if (tri == NULL) {
			ex = new_cept (POINTER_ERROR,  NULL_POINTER,  FATAL_SEVERITY);
			add_object (ex, PHNTRI, "tri");
			add_function (ex, "render_polyhedron");
			add_source (ex, "msrender.c");
			return;
		}
		for (k = 0; k < 3; k++)
			tcen[k] = tri -> center[k];
		trad = tri -> radius;
		edg0 = tri -> edg[0];
		edg1 = tri -> edg[1];
		edg2 = tri -> edg[2];
		orn0 = tri -> orn[0];
		orn1 = tri -> orn[1];
		orn2 = tri -> orn[2];
		vtxs[0] = edg0 -> pvt[orn0];
		vtxs[1] = edg1 -> pvt[orn1];
		vtxs[2] = edg2 -> pvt[orn2];
		for (k = 0; k < 3; k++)
			tnormals[3][k] = tri -> axis[k];
		for (j = 0; j < 3; j++) {
			vtx = vtxs[j];
			if      (f == 'x') tvalues[j] = vtx -> center[0];
			else if (f == 'y') tvalues[j] = vtx -> center[1];
			else if (f == 'z') tvalues[j] = vtx -> center[2];
			else if (f == 'u') tvalues[j] = vtx -> values[0];
			else if (f == 'v') tvalues[j] = vtx -> values[1];
			else if (f == 'w') tvalues[j] = vtx -> values[2];
			else tvalues[j] = vtx -> center[2]; /* default */
			for (k = 0; k < 3; k++) {
				tvertices[j][k] = vtx -> center[k];
				tnormals[j][k] = vtx -> outward[k];
			}
			/* check back-facing for triangle vertex normal */
			/* check clipping for triangle vertex */
			vclipped[j] =  ms -> clipping && phn -> clipping && clipped (ms, tvertices[j]);
		}
		vback =  (tnormals[3][2] < 0.0);
		if (ms -> clipping && phn -> clipping) {
			/* if all three vertices are clipped, triangle is clipped */
			check = (vclipped[0] || vclipped[1] || vclipped[2]);
			if (vclipped[0] && vclipped[1] && vclipped[2]) {
				n_clipped++;
				continue;
			}
		}
		else {
			check = 0;	/* no need to check triangle for being partially clipped */
			/* if back-facing, skip triangle */
			if (vback) {
				n_back++;
				continue;
			}
		}
		comp = tri -> comp;
		atm = tri -> atm;
		if (atm <= 0) {
			ex = new_cept (LOGIC_ERROR,  BOUNDS,  FATAL_SEVERITY);
			add_function (ex, "render_polyhedron");
			add_source (ex, "msrender.c");
			add_long (ex, "atm", (long) atm);
			add_message(ex, "invalid atom number for triangle");
			return;
		}
		hue = tri -> hue;
		render_triangle (ms, phn, fine_pixel, interpolate, 
			tcen, trad, tvertices, tnormals, tvalues, check, comp, hue, atm);
		if (error()) return;
		n_rendered++;
	}
	if (ms -> clipping && phn -> clipping)
		sprintf (message,"%8ld triangles rendered, %6ld clipped",
			n_rendered, n_clipped);
	else
		sprintf (message,"%8ld triangles rendered, %6ld back-facing",
			n_rendered, n_back);
	inform(message);
}