示例#1
0
/** Draw an axis-aligned cube, defined by the the minimum and maximum
 * coordinates of the corners.
 */
void drawCube(Vec3 min, Vec3 max)
{
	RtInt nverts[] = {4, 4, 4, 4, 4, 4};
	RtInt verts[] = {
		0, 1, 2, 3, 
		4, 7, 6, 5, 
		0, 4, 5, 1,
		3, 2, 6, 7, 
		1, 5, 6, 2, 
		0, 3, 7, 4
	};
	RtFloat P[] = {
		min.x, min.y, min.z,
		max.x, min.y, min.z,
		max.x, min.y, max.z,
		min.x, min.y, max.z,
		min.x, max.y, min.z,
		max.x, max.y, min.z,
		max.x, max.y, max.z,
		min.x, max.y, max.z
	};

	RiPointsPolygons(6, nverts, verts, "P", P, RI_NULL);
}
示例#2
0
void show_object(wave_object_t *obj) {
    RtPoint *verts = malloc(sizeof(RtPoint)*(obj->largest_face));
    RtInt *nverts = malloc(sizeof(RtInt)*(obj->num_faces));
    
    int hasNorms = 1;
    size_t vn;
    size_t nn;
    size_t total_pts = 0;
    size_t i,j;
    face_t f;
    RtInt *polys;
    size_t cur_off;
    
    for (i = 0; i< obj->num_faces; ++i) {
        f = obj->faces[i];
        nverts[i] = f.size;
        total_pts += f.size;
    }
    polys = malloc(sizeof(RtInt)*total_pts);
    cur_off = 0;
    
    for (i = 0; i< obj->num_faces; ++i) {
        f = obj->faces[i];
        for (j = 0; j< f.size; ++j) {
            polys[cur_off++] = f.verts[j];
        }
    }
    printf("cur_off = %zu, obj->num_faces = %zu, total_pts = %zu\n", cur_off, obj->num_faces, total_pts);
    RiPointsPolygons(obj->num_faces,
                     nverts,
                     polys,
                     "P", obj->verts, RI_NULL);
    free(polys);
    free(nverts);
    free(verts);
}
示例#3
0
void doFrame(int fNum, scene_info_t *scene) {

    RiFrameBegin(fNum);

    char buffer[256];
    sprintf(buffer, "images/%s%05d.tif", scene->fprefix, fNum);
    RiDisplay(buffer,(char*)"file",(char*)"rgba",RI_NULL);
  
    RiFormat(800, 600,  1.25);
    RiLightSource((char*)"distantlight",RI_NULL);
    RiProjection((char*)"perspective",RI_NULL);
  
    /* RiTranslate(scene->x_trans, scene->y_trans, scene->z_trans); */
    /* RiRotate( scene->x_rotation, 1.0, 0.0, 0.0); */
    /* RiRotate( scene->y_rotation, 0.0, 1.0, 0.0); */
    /* RiRotate( scene->z_rotation, 0.0, 0.0, 1.0); */

    PlaceCamera(&scene->cam);
    RiWorldBegin();
  
    RiSurface((char*)"matte", RI_NULL);

    const size_t NUM_I = 256;
    const size_t NUM_J = 256;

    RtPoint *pts = malloc(sizeof(RtPoint)*NUM_I*NUM_J);
    RtColor *colors = malloc(sizeof(RtPoint)*NUM_I*NUM_J);
    
    double umin  = -4*PI;
    double umax = 4*PI;
    double vmin = -4*PI;
    double vmax = 4*PI;
    double du = (umax - umin)/(NUM_J-1);
    double dv = (vmax - vmin)/(NUM_I-1);

    double u = umin;
    for (size_t i=0; i< NUM_I; ++i) {
        double v = vmin;
        for (size_t j=0; j < NUM_J; ++j) {
            pts[i*NUM_J + j][0] = x(u,v);
            pts[i*NUM_J + j][1] = z(u,v);
            pts[i*NUM_J + j][2] = y(u,v);

            colors[i*NUM_J + j][0] = r(u,v);
            colors[i*NUM_J + j][1] = g(u,v);
            colors[i*NUM_J + j][2] = b(u,v);

            /* RiTransformBegin(); */
            /* RiTranslate(x(u,v), y(u,v), z(u,v)); */
            /* RiSphere(du, -du, du, 360.0, RI_NULL); */
            /* RiTransformEnd(); */
            v += dv;
        }
        u += du;
    }

    
    RtInt npolys = 2*(NUM_J+1)*(NUM_I+1);
    RtInt *nvertices = malloc(sizeof(RtInt) * npolys);
    for (size_t i=0; i<npolys; ++i) {
        nvertices[i] = 3;
    }
    RtInt *vertices = malloc(sizeof(RtInt)*3*npolys);

    size_t curIdx = 0;
    for (size_t i = 0; i<(NUM_I-1); ++i) {
        for (size_t j=0; j<(NUM_J-1); ++j) {
            vertices[curIdx] = j*NUM_I + i;
            vertices[curIdx+1] = (j+1)*NUM_I + i;
            vertices[curIdx+2] = j*NUM_I + i+1;
            vertices[curIdx+3] = (j+1)*NUM_I + i;
            vertices[curIdx+4] = (j+1)*NUM_I + (i+1);
            vertices[curIdx+5] = j*NUM_I + (i+1);
            curIdx += 6;
        }
    }
    
    RiPointsPolygons(curIdx/3, nvertices, vertices, "P", pts, "Cs", colors, RI_NULL);
    /* RiSphere(10.0, -10.0, 10.0, 360.0); */

    free(vertices);
    free(nvertices);
    free(colors);
    free(pts);
                    
    RiWorldEnd();
    RiFrameEnd();
}
示例#4
0
/**
 * Various polygon geometry interface calls
 */
void testPoly10()
{
	RtFloat p[] = {
		// outer
		-.5, -.5, 1, //  1
		-.5,  .5, 1, //  2
		.5,  .5, 1, //  3
		.5, -.5, 1, //  4
		0
	};
	RtInt nloops[] = {
		1
	};
	RtInt nverts[] = {
		4
	};
	RtInt verts[] = {
		0, 1, 2, 3
	};

	// Disable warnings (variable not used)
	opacity_25[0] = opacity_25[0]+0;
	opacity_50[0] = opacity_50[0]+0;
	opacity_75[0] = opacity_75[0]+0;

	RiAttributeBegin(); {
		RiTranslate(0, 0, 1.5);
		RiAttributeBegin(); {
			RiRotate(15.0, 0, 0, 1);
			RiOpacity(opacity_50);
			RiColor(greenish);

			// RiGeneralPolygon(nloops[0], nverts, RI_P, &p, RI_NULL);
			RiPolygon(4, RI_P, &p, RI_NULL);
			// RiPointsPolygons(1, nverts, verts, RI_P, &p, RI_NULL);
			// RiPointsGeneralPolygons(1, nloops, nverts, verts, RI_P, &p, RI_NULL);
	
#			if defined ( _TRACE )
			{
				RtInt i;
				RiTransformPoints(RI_CURRENT, RI_RASTER, sizeof(p)/sizeof(RtPoint), (RtPoint *)p);
				for ( i = 0; i < 4; ++i ) {
					printf("x %f, y %f, z %f\n", p[i*3+0], p[i*3+1], p[i*3+2]);
				}
				printf("Inverse\n");
				RiTransformPoints(RI_RASTER, RI_CURRENT, sizeof(p)/sizeof(RtPoint), (RtPoint *)p);
				for ( i = 0; i < 4; ++i ) {
					printf("x %f, y %f, z %f\n", p[i*3+0], p[i*3+1], p[i*3+2]);
				}
			}
#			endif
		} RiAttributeEnd();
	
		RiAttributeBegin(); {
			RiTranslate(0, 0, 0.2F);
			// RiOpacity(opacity_50);
			RiColor(redish);

			// RiGeneralPolygon(nloops[0], nverts, RI_P, &p, RI_NULL);
			// RiPolygon(4, RI_P, &p, RI_NULL);
			RiPointsPolygons(1, nverts, verts, RI_P, &p, RI_NULL);
			// RiPointsGeneralPolygons(1, nloops, nverts, verts, RI_P, &p, RI_NULL);
			
		} RiAttributeEnd();

		RiAttributeBegin(); {
			RiRotate(-15.0F, 0, 0, 1);
			RiTranslate(0, 0, 0.3F);
			RiOpacity(opacity_75);
			RiColor(blueish);

			// RiGeneralPolygon(nloops[0], nverts, RI_P, &p, RI_NULL);
			// RiPolygon(4, RI_P, &p, RI_NULL);
			// RiPointsPolygons(1, nverts, verts, RI_P, &p, RI_NULL);
			RiPointsGeneralPolygons(1, nloops, nverts, verts, RI_P, &p, RI_NULL);
			
		} RiAttributeEnd();

	} RiAttributeEnd();
}