コード例 #1
0
int GzPutTriangle(GzRender	*render, int numParts, GzToken *nameList, 
				  GzPointer	*valueList)
/* numParts : how many names and values */
{
/*  
- pass in a triangle description with tokens and values corresponding to 
      GZ_POSITION:3 vert positions in model space 
- Xform positions of verts  
- Clip - just discard any triangle with verts behind view plane 
       - test for triangles with all three verts off-screen 
- invoke triangle rasterizer  
*/ 

	GzCoord *transfVert, *NormVert;
	if(render==NULL)
		return GZ_FAILURE;
	for(int i=0; i<numParts;i++ )
	{
		GzCoord *coord=(GzCoord *)(valueList[i]);	
	  if(nameList[i]==GZ_POSITION)
		{
		transfVert=(GzCoord *)malloc(3*sizeof(GzCoord));
			
		
			for(int i=0;i<3;i++)
			transformation(render->Ximage[render->matlevel],coord[i],transfVert[i] );
				
			//
			//Rasterization( render,transfVert);
		}
	  else if (nameList[i]==GZ_NORMAL)
                {
            NormVert=(GzCoord *)malloc(3*sizeof(GzCoord));
		//	GzCoord *coord=(GzCoord *)(valueList[i]);	
		
			for(int i=0;i<3;i++)
			transformation(render->Xnorm[render->matlevel],coord[i],NormVert[i] );
				
			//Rasterization( render,transfVert);   
                }
	   else if (nameList[i]==GZ_NULL_TOKEN)
		{
			
		}
	}
	
	Rasterization( render,transfVert,NormVert);
	return GZ_SUCCESS;
}
コード例 #2
0
ファイル: Renderer.cpp プロジェクト: unoyx/soft-renderer
void Renderer::DrawPrimitive(Primitive *primitive)
{
    rend_primitive_ = RendPrimitive(primitive->size, primitive->material);

    for (int i = 0; i < rend_primitive_.size; ++i)
    {
        rend_primitive_.position[i].SetVector3(primitive->position[i]);
        rend_primitive_.position[i].w = 1.0f;
        rend_primitive_.normals[i].SetVector3(primitive->normals[i]);
        rend_primitive_.normals[i].w = 0.0f;
        rend_primitive_.colors[i] = primitive->colors[i];
    }

    ModelViewTransform();
    // Lighting();
    Projection();
    Clipping(Vector3(-1, -1, 0), Vector3(1, 1, 1.0f));
    Rasterization();
}