home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume21
/
sipp
/
part08
< prev
next >
Wrap
Text File
|
1991-07-23
|
37KB
|
1,497 lines
Newsgroups: comp.sources.misc
From: Jonas Yngvesson <jonas-y@isy.liu.se>
Subject: v21i033: sipp - A 3D rendering library v2.1, Part08/08
Message-ID: <1991Jul23.181823.28068@sparky.IMD.Sterling.COM>
X-Md4-Signature: 6aefb07c5af503a76b4069ecfc14c3ae
Date: Tue, 23 Jul 1991 18:18:23 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: Jonas Yngvesson <jonas-y@isy.liu.se>
Posting-number: Volume 21, Issue 33
Archive-name: sipp/part08
Supersedes: sipp2.0: Volume 16, Issue 5-10
Environment: UNIX
#!/bin/sh
# This is part 08 of sipp-2.1
# ============= demo/conetest.c ==============
if test ! -d 'demo'; then
echo 'x - creating directory demo'
mkdir 'demo'
fi
if test -f 'demo/conetest.c' -a X"$1" != X"-c"; then
echo 'x - skipping demo/conetest.c (File already exists)'
else
echo 'x - extracting demo/conetest.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/conetest.c' &&
#include <stdio.h>
#include <math.h>
X
#include <sipp.h>
#include <primitives.h>
X
X
#define RESOLUTION 20
X
extern char *optarg;
X
main(argc, argv)
X int argc;
X char **argv;
{
X FILE *fp ;
X Object *cone;
X Object *trunc_cone;
X Surf_desc surf;
X
X char *imfile_name;
X int mode;
X char c;
X int size;
X
X imfile_name = "cone.ppm";
X mode = PHONG;
X size = 256;
X
X while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
X switch (c) {
X case 'p':
X mode = PHONG;
X imfile_name = "cone.ppm";
X break;
X
X case 'g':
X mode = GOURAUD;
X imfile_name = "cone.ppm";
X break;
X
X case 'f':
X mode = FLAT;
X imfile_name = "cone.ppm";
X break;
X
X case 'l':
X mode = LINE;
X imfile_name = "cone.pbm";
X break;
X
X case 's':
X size = atoi(optarg);
X break;
X }
X }
X
X sipp_init();
X
X lightsource_push(1.0, 1.0, 1.0, 0.9);
X lightsource_push(-1.0, -1.0, 0.5, 0.4);
X
X surf.ambient = 0.5;
X surf.color.red = 1.0000; /* light salmon */
X surf.color.grn = 0.6275;
X surf.color.blu = 0.4784;
X surf.specular = 0.6;
X surf.c3 = 0.2;
X
X /* The ordinary cone */
X cone = sipp_cone(1.0, 0.0, 4.0, RESOLUTION, &surf, basic_shader);
X object_move(cone, -3.0, 0.0, 0.0);
X object_install(cone);
X
X /* The truncated cone */
X trunc_cone = sipp_cone(1.0, 0.4, 5.0, RESOLUTION, &surf, basic_shader);
X object_move(trunc_cone, 3.0, 0.0, 0.0);
X object_install(trunc_cone);
X
X /* The cylinder (a trucated cone with equal top and bottom radii */
X object_install(sipp_cylinder(1.0, 3.0, RESOLUTION, &surf, basic_shader));
X
X viewpoint(5.0, -10.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.4);
X
X printf("Rendering, wait...");
X fflush(stdout);
X
X fp = fopen(imfile_name, "w");
X render_image_file(size, size, fp, mode, 2);
X printf("Done.\n");
X
X exit(0);
}
SHAR_EOF
chmod 0664 demo/conetest.c ||
echo 'restore of demo/conetest.c failed'
Wc_c="`wc -c < 'demo/conetest.c'`"
test 2027 -eq "$Wc_c" ||
echo 'demo/conetest.c: original size 2027, current size' "$Wc_c"
fi
# ============= demo/ellipsoid.c ==============
if test -f 'demo/ellipsoid.c' -a X"$1" != X"-c"; then
echo 'x - skipping demo/ellipsoid.c (File already exists)'
else
echo 'x - extracting demo/ellipsoid.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/ellipsoid.c' &&
#include <stdio.h>
#include <math.h>
X
#include <sipp.h>
#include <primitives.h>
X
X
X
#define RESOLUTION 15
X
extern char *optarg;
X
main(argc, argv)
X int argc;
X char **argv;
{
X FILE *fp ;
X Surf_desc surf;
X
X char *imfile_name;
X int mode;
X char c;
X int size;
X
X imfile_name = "ellipsoid.ppm";
X mode = PHONG;
X size = 256;
X
X while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
X switch (c) {
X case 'p':
X mode = PHONG;
X imfile_name = "ellipsoid.ppm";
X break;
X
X case 'g':
X mode = GOURAUD;
X imfile_name = "ellipsoid.ppm";
X break;
X
X case 'f':
X mode = FLAT;
X imfile_name = "ellipsoid.ppm";
X break;
X
X case 'l':
X mode = LINE;
X imfile_name = "ellipsoid.pbm";
X break;
X
X case 's':
X size = atoi(optarg);
X break;
X }
X }
X
X sipp_init();
X
X lightsource_push(1.0, 1.0, 1.0, 0.9);
X lightsource_push(-1.0, -1.0, 0.5, 0.4);
X
X surf.ambient = 0.5;
X surf.color.red = 0.6;
X surf.color.grn = 0.3;
X surf.color.blu = 0.5;
X surf.specular = 0.6;
X surf.c3 = 0.2;
X
X object_install(sipp_ellipsoid(1.0, 2.0, 3.0, RESOLUTION,
X &surf, basic_shader));
X
X viewpoint(10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.4);
X
X printf("Rendering, wait...");
X fflush(stdout);
X
X fp = fopen(imfile_name, "w");
X render_image_file(size, size, fp, mode, 2);
X printf("Done.\n");
X
X exit(0);
}
SHAR_EOF
chmod 0664 demo/ellipsoid.c ||
echo 'restore of demo/ellipsoid.c failed'
Wc_c="`wc -c < 'demo/ellipsoid.c'`"
test 1595 -eq "$Wc_c" ||
echo 'demo/ellipsoid.c: original size 1595, current size' "$Wc_c"
fi
# ============= demo/isy90.c ==============
if test -f 'demo/isy90.c' -a X"$1" != X"-c"; then
echo 'x - skipping demo/isy90.c (File already exists)'
else
echo 'x - extracting demo/isy90.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/isy90.c' &&
#include <math.h>
#include <stdio.h>
X
#include <sipp.h>
#include <shaders.h>
#include <primitives.h>
X
X
#define BEZ_RES 9
#define CYL_RES 40
#define LID_ROT 1.5
#define BLOCK_SIZE 1.2
#define NCYL 16
#define CYL_LEN 5.0
#define SMALL_CYL_RAD ((BLOCK_SIZE * M_PI) / (NCYL * 2))
#define BIG_CYL_RAD (0.5 * BLOCK_SIZE - 1.1 * SMALL_CYL_RAD)
X
X
Marble_desc teapot_surf = {
X 0.4,
X 0.5,
X 0.05,
X 8.0,
X {0.90, 0.80, 0.65},
X {0.30, 0.08, 0.08}
};
X
Granite_desc column_surf = {
X 0.4,
X 0.1,
X 0.4,
X 20.0,
X {0.647, 0.565, 0.5},
X {0.15, 0.12, 0.10}
};
X
extern char *optarg;
X
main(argc, argv)
X int argc;
X char **argv;
{
X Object *column;
X Object *teapot;
X Object *handle;
X Object *spout;
X Object *body;
X Object *lid;
X Object *tmp;
X FILE *infile;
X FILE *image;
X int i;
X
X char *imfile_name;
X int mode;
X char c;
X int size;
X
X imfile_name = "isy90.ppm";
X mode = PHONG;
X size = 256;
X
X while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
X switch (c) {
X case 'p':
X mode = PHONG;
X imfile_name = "isy90.ppm";
X break;
X
X case 'g':
X mode = GOURAUD;
X imfile_name = "isy90.ppm";
X break;
X
X case 'f':
X mode = FLAT;
X imfile_name = "isy90.ppm";
X break;
X
X case 'l':
X mode = LINE;
X imfile_name = "isy90.pbm";
X break;
X
X case 's':
X size = atoi(optarg);
X break;
X }
X }
X
X sipp_init();
X
X infile = fopen("tpt_handle.bez", "r");
X handle = sipp_bezier(infile, BEZ_RES, &teapot_surf, marble_shader);
X fclose(infile);
X
X infile = fopen("tpt_spout.bez", "r");
X spout = sipp_bezier(infile, BEZ_RES, &teapot_surf, marble_shader);
X fclose(infile);
X
X infile = fopen("tpt_body.bez", "r");
X body = sipp_bezier(infile, BEZ_RES, &teapot_surf, marble_shader);
X fclose(infile);
X
X infile = fopen("tpt_lid.bez", "r");
X lid = sipp_bezier(infile, BEZ_RES, &teapot_surf, marble_shader);
X fclose(infile);
X
X object_rot_y(lid, LID_ROT);
X
X teapot = object_create();
X object_add_subobj(teapot, body);
X object_add_subobj(teapot, lid);
X object_add_subobj(teapot, handle);
X object_add_subobj(teapot, spout);
X
X object_install(teapot);
X
X column = object_create();
X tmp = sipp_block(BLOCK_SIZE, BLOCK_SIZE / 4.0, BLOCK_SIZE,
X &column_surf, granite_shader);
X object_move(tmp, 0.0, -BLOCK_SIZE / 8.0, 0.0);
X object_add_subobj(column, tmp);
X
X for (i = 0; i < NCYL; i++) {
X if (i == 0) {
X tmp = sipp_cylinder(SMALL_CYL_RAD, CYL_LEN, CYL_RES,
X &column_surf, granite_shader);
X } else {
X tmp = object_instance(tmp);
X }
X object_rot_x(tmp, M_PI / 2.0);
X object_move(tmp, BIG_CYL_RAD * cos(i * 2.0 * M_PI / NCYL),
X -0.5 * (CYL_LEN + BLOCK_SIZE / 4.0),
X BIG_CYL_RAD * sin(i * 2.0 * M_PI / NCYL));
X object_add_subobj(column, tmp);
X }
X
X object_install(column);
X
X
X lightsource_push(1.0, 1.0, 0.5, 0.85);
X lightsource_push(-1.0, 0.5, 0.5, 0.25);
X
X view_from(2.0, 1.5, 4.0);
X view_at(0.0, 0.1, 0.0);
X view_up(0.0, 1.0, 0.0);
X view_focal(0.2);
X
X printf("Rendering, wait...");
X fflush(stdout);
X
X image = fopen(imfile_name, "w");
X render_image_file(size, size, image, mode, 2);
X printf("Done.\n");
X
X exit(0);
}
SHAR_EOF
chmod 0664 demo/isy90.c ||
echo 'restore of demo/isy90.c failed'
Wc_c="`wc -c < 'demo/isy90.c'`"
test 3595 -eq "$Wc_c" ||
echo 'demo/isy90.c: original size 3595, current size' "$Wc_c"
fi
# ============= demo/planettest.c ==============
if test -f 'demo/planettest.c' -a X"$1" != X"-c"; then
echo 'x - skipping demo/planettest.c (File already exists)'
else
echo 'x - extracting demo/planettest.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/planettest.c' &&
#include <stdio.h>
#include <math.h>
X
#include <sipp.h>
#include <primitives.h>
#include <shaders.h>
X
X
X
#define SUBDIVS 20
X
extern char *optarg;
X
main(argc, argv)
X int argc;
X char **argv;
{
X Surf_desc planet_surface;
X Object *planet;
X FILE *outfile;
X
X char *imfile_name;
X int mode;
X char c;
X int size;
X
X imfile_name = "planet.ppm";
X mode = PHONG;
X size = 256;
X
X while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
X switch (c) {
X case 'p':
X mode = PHONG;
X imfile_name = "planet.ppm";
X break;
X
X case 'g':
X mode = GOURAUD;
X imfile_name = "planet.ppm";
X break;
X
X case 'f':
X mode = FLAT;
X imfile_name = "planet.ppm";
X break;
X
X case 'l':
X mode = LINE;
X imfile_name = "planet.pbm";
X break;
X
X case 's':
X size = atoi(optarg);
X break;
X }
X }
X
X planet_surface.ambient = 0.4;
X planet_surface.specular = 0.0;
X planet_surface.c3 = 0.5;
X planet_surface.color.red = 1.0;
X planet_surface.color.grn = 0.0;
X planet_surface.color.blu = 0.0;
X
X sipp_init();
X
X lightsource_push(1.0, 1.0, 1.0, 1.0);
X
X object_install(sipp_sphere(1.0, SUBDIVS, &planet_surface, planet_shader));
X
X viewpoint(0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.75);
X
X printf("Rendering, wait...");
X fflush(stdout);
X
X outfile = fopen(imfile_name, "w");
X render_image_file(size, size, outfile, mode, 2);
X printf("Done.\n");
X
X exit(0);
}
SHAR_EOF
chmod 0664 demo/planettest.c ||
echo 'restore of demo/planettest.c failed'
Wc_c="`wc -c < 'demo/planettest.c'`"
test 1633 -eq "$Wc_c" ||
echo 'demo/planettest.c: original size 1633, current size' "$Wc_c"
fi
# ============= demo/prismtest.c ==============
if test -f 'demo/prismtest.c' -a X"$1" != X"-c"; then
echo 'x - skipping demo/prismtest.c (File already exists)'
else
echo 'x - extracting demo/prismtest.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/prismtest.c' &&
#include <stdio.h>
#include <math.h>
X
#include <sipp.h>
#include <primitives.h>
X
X
/* The XY coordinats for a 3-sided prism. */
Vector prism3[3] = {
X { 1.0 -1.0, 0.0},
X {-1.0, 2.0, 0.0},
X {-2.0, -1.0, 0.0}
};
X
/* The XY coordinats for a 5-sided prism. */
Vector prism5[5] = {
X { 0.5 -1.0, 0.0},
X {-1.0, 0.5, 0.0},
X { 1.0, 1.0, 0.0},
X {-1.0, 2.0, 0.0},
X {-2.0, 0.5, 0.0}
};
X
extern char *optarg;
X
main(argc, argv)
X int argc;
X char **argv;
{
X FILE * fp ;
X Object * prism3_obj;
X Object * prism5_obj;
X Surf_desc surf;
X
X char *imfile_name;
X int mode;
X char c;
X int size;
X
X imfile_name = "prism.ppm";
X mode = PHONG;
X size = 256;
X
X while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
X switch (c) {
X case 'p':
X mode = PHONG;
X imfile_name = "prism.ppm";
X break;
X
X case 'g':
X mode = GOURAUD;
X imfile_name = "prism.ppm";
X break;
X
X case 'f':
X mode = FLAT;
X imfile_name = "prism.ppm";
X break;
X
X case 'l':
X mode = LINE;
X imfile_name = "prism.pbm";
X break;
X
X case 's':
X size = atoi(optarg);
X break;
X }
X }
X
X sipp_init();
X
X lightsource_push(1.0, 1.0, 1.0, 0.9);
X lightsource_push(-1.0, -1.0, 0.5, 0.4);
X
X surf.ambient = 0.5;
X surf.color.red = 1.0000; /* light salmon */
X surf.color.grn = 0.6275;
X surf.color.blu = 0.4784;
X surf.specular = 0.6;
X surf.c3 = 0.2;
X
X /* The 3-sided prism */
X prism3_obj = sipp_prism(3, &prism3[0], 4.0, &surf, basic_shader);
X object_move(prism3_obj, -3.0, 0.0, 0.0);
X object_install(prism3_obj);
X
X /* The 5-sided prism */
X prism5_obj = sipp_prism(5, &prism5[0], 5.0, &surf, basic_shader);
X object_move(prism5_obj, 3.0, 0.0, 0.0);
X object_install(prism5_obj);
X
X /* The block (a 4 sided prism) */
X object_install(sipp_block(1.0, 2.0, 3.0, &surf, basic_shader));
X
X viewpoint(5.0, -10.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.4);
X
X printf("Rendering, wait...");
X fflush(stdout);
X
X fp = fopen(imfile_name, "w");
X render_image_file(size, size, fp, mode, 2);
X printf("Done.\n");
X
X exit(0);
}
SHAR_EOF
chmod 0664 demo/prismtest.c ||
echo 'restore of demo/prismtest.c failed'
Wc_c="`wc -c < 'demo/prismtest.c'`"
test 2312 -eq "$Wc_c" ||
echo 'demo/prismtest.c: original size 2312, current size' "$Wc_c"
fi
# ============= demo/strausstest.c ==============
if test -f 'demo/strausstest.c' -a X"$1" != X"-c"; then
echo 'x - skipping demo/strausstest.c (File already exists)'
else
echo 'x - extracting demo/strausstest.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/strausstest.c' &&
/*
X * Demo of the strauss shader. Four spheres are rendered,
X * all with the same base color, but different smoothness
X * and metalness.
X */
X
#include <stdio.h>
#include <math.h>
X
#include <sipp.h>
#include <shaders.h>
#include <primitives.h>
X
X
/*
X * Surface description of the spheres.
X */
Strauss_desc non_metal_dull = {
X 0.4, /* Ambient */
X 0.2, /* Smoothness */
X 0.1, /* Metalness */
X {0.6, 0.33, 0.27} /* Color */
};
X
Strauss_desc non_metal_shiny = {
X 0.4,
X 0.7,
X 0.1,
X {0.6, 0.33, 0.27}
};
X
Strauss_desc metal_dull = {
X 0.4,
X 0.2,
X 0.9,
X {0.6, 0.33, 0.27}
};
X
Strauss_desc metal_shiny = {
X 0.4,
X 0.7,
X 0.9,
X {0.6, 0.33, 0.27}
};
X
X
/*
X * White surface as background.
X */
Surf_desc bg_surf = {
X 0.4,
X 0.0,
X 0.99,
X {0.9804, 0.9216, 0.8431} /* Antique white */
};
X
X
X
#define RESOLUTION 30
X
extern char *optarg;
X
main(argc, argv)
X int argc;
X char **argv;
{
X Object *nmd; /* Non metallic, dull sphere */
X Object *nms; /* Non metallic, shiny sphere */
X Object *md; /* Metallic, dull sphere */
X Object *ms; /* Metallic, shiny sphere */
X Object *bg; /* Background */
X FILE *fp;
X
X char *imfile_name;
X int mode;
X char c;
X int size;
X
X imfile_name = "strauss.ppm";
X mode = PHONG;
X size = 256;
X
X while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
X switch (c) {
X case 'p':
X mode = PHONG;
X imfile_name = "strauss.ppm";
X break;
X
X case 'g':
X mode = GOURAUD;
X imfile_name = "strauss.ppm";
X break;
X
X case 'f':
X mode = FLAT;
X imfile_name = "strauss.ppm";
X break;
X
X case 'l':
X mode = LINE;
X imfile_name = "strauss.pbm";
X break;
X
X case 's':
X size = atoi(optarg);
X break;
X }
X }
X
X sipp_init();
X
X lightsource_push(-1.0, -1.0, 1.0, 1.0);
X lightsource_push(0.0, -1.0, 2.0, 0.6);
X
X /*
X * Non metal, dull. Upper left.
X */
X nmd = sipp_sphere(1.0, RESOLUTION, &non_metal_dull, strauss_shader);
X object_move(nmd, -1.1, 0.0, 1.1);
X object_install(nmd);
X
X /*
X * Non metal, shiny. Upper right.
X */
X nms = sipp_sphere(1.0, RESOLUTION, &non_metal_shiny, strauss_shader);
X object_move(nms, 1.1, 0.0, 1.1);
X object_install(nms);
X
X /*
X * Metal, dull. Lower left.
X */
X md = sipp_sphere(1.0, RESOLUTION, &metal_dull, strauss_shader);
X object_move(md, -1.1, 0.0, -1.1);
X object_install(md);
X
X /*
X * Metal, shiny. Lower right.
X */
X ms = sipp_sphere(1.0, RESOLUTION, &metal_shiny, strauss_shader);
X object_move(ms, 1.1, 0.0, -1.1);
X object_install(ms);
X
X /*
X * Background.
X */
X bg = sipp_block(10.0, 0.5, 10.0, bg_surf, basic_shader);
X object_move(bg, 0.0, 1.5, 0.0);
X object_install(bg);
X
X viewpoint(0.0, -10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.25);
X
X printf("Rendering, wait...");
X fflush(stdout);
X
X fp = fopen(imfile_name, "w");
X render_image_file(size, size, fp, mode, 2);
X printf("Done.\n");
X
X exit(0);
}
SHAR_EOF
chmod 0644 demo/strausstest.c ||
echo 'restore of demo/strausstest.c failed'
Wc_c="`wc -c < 'demo/strausstest.c'`"
test 3272 -eq "$Wc_c" ||
echo 'demo/strausstest.c: original size 3272, current size' "$Wc_c"
fi
# ============= demo/structure.c ==============
if test -f 'demo/structure.c' -a X"$1" != X"-c"; then
echo 'x - skipping demo/structure.c (File already exists)'
else
echo 'x - extracting demo/structure.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/structure.c' &&
#include <stdio.h>
#include <math.h>
X
#include <sipp.h>
#include <primitives.h>
#include <shaders.h>
X
X
#define SPHERERES 40
#define CYLRES 40
X
#define SIGNBIT(bit, i) (((i >> bit) & 1) ? -1.0 : 1.0)
X
Surf_desc surf = {
X 0.4,
X 0.7,
X 0.1,
X {0.8, 0.6, 0.3}
X };
X
Bumpy_desc bumpy_surf = {
X basic_shader,
X &surf,
X 14.0,
X FALSE,
X TRUE
};
X
extern char *optarg;
X
main(argc, argv)
X int argc;
X char **argv;
{
X Object *sphere;
X Object *cyl;
X Object *structure;
X FILE *fp ;
X Surf_desc cyl_surf;
X int i;
X
X char *imfile_name;
X int mode;
X char c;
X int size;
X
X imfile_name = "structure.ppm";
X mode = PHONG;
X size = 256;
X
X while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
X switch (c) {
X case 'p':
X mode = PHONG;
X imfile_name = "structure.ppm";
X break;
X
X case 'g':
X mode = GOURAUD;
X imfile_name = "structure.ppm";
X break;
X
X case 'f':
X mode = FLAT;
X imfile_name = "structure.ppm";
X break;
X
X case 'l':
X mode = LINE;
X imfile_name = "structure.pbm";
X break;
X
X case 's':
X size = atoi(optarg);
X break;
X }
X }
X
X sipp_init();
X
X lightsource_push(1.0, 1.0, 1.0, 0.9);
X lightsource_push(-1.0, -1.0, 0.5, 0.4);
X
X cyl_surf.ambient = 0.5;
X cyl_surf.color.red = 0.5;
X cyl_surf.color.grn = 0.6;
X cyl_surf.color.blu = 0.8;
X cyl_surf.specular = 0.4;
X cyl_surf.c3 = 0.3;
X
X structure = object_create();
X
X sphere = sipp_sphere(1.0, SPHERERES, &bumpy_surf, bumpy_shader);
X for (i = 0; i < 8; i++) {
X if (i) {
X sphere = object_instance(sphere);
X }
X object_move(sphere, 2.0 * SIGNBIT(2, i), 2.0 * SIGNBIT(1, i),
X 2.0 * SIGNBIT(0, i));
X object_add_subobj(structure, sphere);
X }
X
X cyl = sipp_cylinder(0.25, 4.0, CYLRES, &cyl_surf, basic_shader);
X for (i = 0; i < 4; i++) {
X if (i) {
X cyl = object_instance(cyl);
X }
X object_move(cyl, 2.0 * SIGNBIT(1, i), 2.0 * SIGNBIT(0, i), 0.0);
X object_add_subobj(structure, cyl);
X }
X for (i = 0; i < 4; i++) {
X cyl = object_instance(cyl);
X object_rot_x(cyl, M_PI / 2.0);
X object_move(cyl, 2.0 * SIGNBIT(1, i), 0.0, 2.0 * SIGNBIT(0, i));
X object_add_subobj(structure, cyl);
X }
X for (i = 0; i < 4; i++) {
X cyl = object_instance(cyl);
X object_rot_y(cyl, M_PI / 2.0);
X object_move(cyl, 0.0, 2.0 * SIGNBIT(1, i), 2.0 * SIGNBIT(0, i));
X object_add_subobj(structure, cyl);
X }
X
X object_install(structure);
X
X view_from(10.0, -5.0, 15.0);
X view_at(0.0, 0.0, 0.0);
X view_up(0.0, 0.0, 1.0);
X view_focal(0.25);
X
X printf("Rendering, wait...");
X fflush(stdout);
X
X fp = fopen(imfile_name, "w");
X render_image_file(size, size, fp, mode, 2);
X printf("Done.\n");
X
X exit(0);
}
SHAR_EOF
chmod 0664 demo/structure.c ||
echo 'restore of demo/structure.c failed'
Wc_c="`wc -c < 'demo/structure.c'`"
test 3047 -eq "$Wc_c" ||
echo 'demo/structure.c: original size 3047, current size' "$Wc_c"
fi
# ============= demo/teapot.c ==============
if test -f 'demo/teapot.c' -a X"$1" != X"-c"; then
echo 'x - skipping demo/teapot.c (File already exists)'
else
echo 'x - extracting demo/teapot.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/teapot.c' &&
#include <stdio.h>
X
#include <sipp.h>
#include <primitives.h>
X
X
#define RESOLUTION 9
X
Surf_desc teapot_surf = {
X 0.4,
X 0.5,
X 0.1,
X {0.9, 0.6, 0.6}
};
X
extern char *optarg;
X
main(argc, argv)
X int argc;
X char **argv;
{
X Object *teapot;
X Object *handle;
X Object *spout;
X Object *body;
X Object *lid;
X FILE *infile;
X FILE *image;
X
X char *imfile_name;
X int mode;
X char c;
X int size;
X
X imfile_name = "teapot.ppm";
X mode = PHONG;
X size = 256;
X
X while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
X switch (c) {
X case 'p':
X mode = PHONG;
X imfile_name = "teapot.ppm";
X break;
X
X case 'g':
X mode = GOURAUD;
X imfile_name = "teapot.ppm";
X break;
X
X case 'f':
X mode = FLAT;
X imfile_name = "teapot.ppm";
X break;
X
X case 'l':
X mode = LINE;
X imfile_name = "teapot.pbm";
X break;
X
X case 's':
X size = atoi(optarg);
X break;
X }
X }
X
X sipp_init();
X
X infile = fopen("tpt_handle.bez", "r");
X handle = sipp_bezier(infile, RESOLUTION, &teapot_surf, basic_shader);
X fclose(infile);
X
X infile = fopen("tpt_spout.bez", "r");
X spout = sipp_bezier(infile, RESOLUTION, &teapot_surf, basic_shader);
X fclose(infile);
X
X infile = fopen("tpt_body.bez", "r");
X body = sipp_bezier(infile, RESOLUTION, &teapot_surf, basic_shader);
X fclose(infile);
X
X infile = fopen("tpt_lid.bez", "r");
X lid = sipp_bezier(infile, RESOLUTION, &teapot_surf, basic_shader);
X fclose(infile);
X
X teapot = object_create();
X object_add_subobj(teapot, body);
X object_add_subobj(teapot, lid);
X object_add_subobj(teapot, handle);
X object_add_subobj(teapot, spout);
X
X object_install(teapot);
X
X lightsource_push(1.0, 1.0, 1.0, 1.0);
X lightsource_push(-1.0, 1.0, -1.0, 0.4);
X
X view_from(0.75, 1.5, 3.5);
X view_at(0.0, 0.4, 0.0);
X view_up(0.0, 1.0, 0.0);
X view_focal(0.25);
X
X printf("Rendering, wait...");
X fflush(stdout);
X
X image = fopen(imfile_name, "w");
X render_image_file(size, size, image, mode, 2);
X printf("Done.\n");
X
X exit(0);
}
SHAR_EOF
chmod 0664 demo/teapot.c ||
echo 'restore of demo/teapot.c failed'
Wc_c="`wc -c < 'demo/teapot.c'`"
test 2263 -eq "$Wc_c" ||
echo 'demo/teapot.c: original size 2263, current size' "$Wc_c"
fi
# ============= demo/torustest.c ==============
if test -f 'demo/torustest.c' -a X"$1" != X"-c"; then
echo 'x - skipping demo/torustest.c (File already exists)'
else
echo 'x - extracting demo/torustest.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/torustest.c' &&
#include <stdio.h>
#include <math.h>
X
#include <sipp.h>
#include <primitives.h>
X
X
X
#define SMALLRES 15
#define BIGRES 40
X
extern char *optarg;
X
main(argc, argv)
X int argc;
X char **argv;
{
X FILE *fp ;
X Surf_desc surf;
X
X char *imfile_name;
X int mode;
X char c;
X int size;
X
X imfile_name = "torus.ppm";
X mode = PHONG;
X size = 256;
X
X while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
X switch (c) {
X case 'p':
X mode = PHONG;
X imfile_name = "torus.ppm";
X break;
X
X case 'g':
X mode = GOURAUD;
X imfile_name = "torus.ppm";
X break;
X
X case 'f':
X mode = FLAT;
X imfile_name = "torus.ppm";
X break;
X
X case 'l':
X mode = LINE;
X imfile_name = "torus.pbm";
X break;
X
X case 's':
X size = atoi(optarg);
X break;
X }
X }
X
X sipp_init();
X
X lightsource_push(1.0, 1.0, 1.0, 0.9);
X lightsource_push(-1.0, -1.0, 0.5, 0.4);
X
X surf.ambient = 0.5;
X surf.color.red = 0.6;
X surf.color.grn = 0.3;
X surf.color.blu = 0.5;
X surf.specular = 0.6;
X surf.c3 = 0.2;
X
X object_install(sipp_torus(1.0, 0.4, BIGRES, SMALLRES, &surf,
X basic_shader));
X
X viewpoint(2.0, 0.0, 7.0, 0.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.4);
X
X printf("Rendering, wait...");
X fflush(stdout);
X
X fp = fopen(imfile_name, "w");
X render_image_file(size, size, fp, mode, 2);
X printf("Done.\n");
X
X exit(0);
}
SHAR_EOF
chmod 0664 demo/torustest.c ||
echo 'restore of demo/torustest.c failed'
Wc_c="`wc -c < 'demo/torustest.c'`"
test 1585 -eq "$Wc_c" ||
echo 'demo/torustest.c: original size 1585, current size' "$Wc_c"
fi
# ============= demo/tpt_body.bez ==============
if test -f 'demo/tpt_body.bez' -a X"$1" != X"-c"; then
echo 'x - skipping demo/tpt_body.bez (File already exists)'
else
echo 'x - extracting demo/tpt_body.bez (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/tpt_body.bez' &&
# Bezier curves (rotational body) for teapot body.
X
bezier_curves:
X
vertices: 10
vertex_list:
X 3.500000E-01 5.625000E-01 0.000000E+00
X 3.343750E-01 5.953125E-01 0.000000E+00
X 3.593750E-01 5.953125E-01 0.000000E+00
X 3.750000E-01 5.625000E-01 0.000000E+00
X 4.375000E-01 4.312500E-01 0.000000E+00
X 5.000000E-01 3.000000E-01 0.000000E+00
X 5.000000E-01 1.875000E-01 0.000000E+00
X 5.000000E-01 7.500000E-02 0.000000E+00
X 3.750000E-01 1.875000E-02 0.000000E+00
X 3.750000E-01 0.000000E+00 0.000000E+00
X
curves: 3
curve_list:
X
X 1 2 3 4
X
X 4 5 6 7
X
X 7 8 9 10
SHAR_EOF
chmod 0664 demo/tpt_body.bez ||
echo 'restore of demo/tpt_body.bez failed'
Wc_c="`wc -c < 'demo/tpt_body.bez'`"
test 644 -eq "$Wc_c" ||
echo 'demo/tpt_body.bez: original size 644, current size' "$Wc_c"
fi
# ============= demo/tpt_handle.bez ==============
if test -f 'demo/tpt_handle.bez' -a X"$1" != X"-c"; then
echo 'x - skipping demo/tpt_handle.bez (File already exists)'
else
echo 'x - extracting demo/tpt_handle.bez (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/tpt_handle.bez' &&
# Bezier patches defining the teapot handle.
X
bezier_patches:
X
X
vertices: 42
vertex_list:
X
X -3.750000E-01 5.250000E-01 0.000000E+00
X -6.250000E-01 5.250000E-01 0.000000E+00
X -7.500000E-01 5.250000E-01 0.000000E+00
X -7.500000E-01 4.125000E-01 0.000000E+00
X -7.500000E-01 3.000000E-01 0.000000E+00
X -6.625000E-01 1.968750E-01 0.000000E+00
X -4.750000E-01 1.125000E-01 0.000000E+00
X -3.750000E-01 5.250000E-01 -7.500000E-02
X -6.250000E-01 5.250000E-01 -7.500000E-02
X -7.500000E-01 5.250000E-01 -7.500000E-02
X -7.500000E-01 4.125000E-01 -7.500000E-02
X -7.500000E-01 3.000000E-01 -7.500000E-02
X -6.625000E-01 1.968750E-01 -7.500000E-02
X -4.750000E-01 1.125000E-01 -7.500000E-02
X -4.000000E-01 4.687500E-01 -7.500000E-02
X -5.750000E-01 4.687500E-01 -7.500000E-02
X -6.750000E-01 4.687500E-01 -7.500000E-02
X -6.750000E-01 4.125000E-01 -7.500000E-02
X -6.750000E-01 3.562500E-01 -7.500000E-02
X -6.250000E-01 2.437500E-01 -7.500000E-02
X -5.000000E-01 1.875000E-01 -7.500000E-02
X -4.000000E-01 4.687500E-01 0.000000E+00
X -5.750000E-01 4.687500E-01 0.000000E+00
X -6.750000E-01 4.687500E-01 0.000000E+00
X -6.750000E-01 4.125000E-01 0.000000E+00
X -6.750000E-01 3.562500E-01 0.000000E+00
X -6.250000E-01 2.437500E-01 0.000000E+00
X -5.000000E-01 1.875000E-01 0.000000E+00
X -4.000000E-01 4.687500E-01 7.500000E-02
X -5.750000E-01 4.687500E-01 7.500000E-02
X -6.750000E-01 4.687500E-01 7.500000E-02
X -6.750000E-01 4.125000E-01 7.500000E-02
X -6.750000E-01 3.562500E-01 7.500000E-02
X -6.250000E-01 2.437500E-01 7.500000E-02
X -5.000000E-01 1.875000E-01 7.500000E-02
X -3.750000E-01 5.250000E-01 7.500000E-02
X -6.250000E-01 5.250000E-01 7.500000E-02
X -7.500000E-01 5.250000E-01 7.500000E-02
X -7.500000E-01 4.125000E-01 7.500000E-02
X -7.500000E-01 3.000000E-01 7.500000E-02
X -6.625000E-01 1.968750E-01 7.500000E-02
X -4.750000E-01 1.125000E-01 7.500000E-02
X
patches: 4
patch_list:
X
X 1 2 3 4
36 37 38 39
29 30 31 32
22 23 24 25
X
22 23 24 25
15 16 17 18
X 8 9 10 11
X 1 2 3 4
X
X 4 5 6 7
39 40 41 42
32 33 34 35
25 26 27 28
X
X 7 6 5 4
14 13 12 11
21 20 19 18
28 27 26 25
SHAR_EOF
chmod 0664 demo/tpt_handle.bez ||
echo 'restore of demo/tpt_handle.bez failed'
Wc_c="`wc -c < 'demo/tpt_handle.bez'`"
test 2371 -eq "$Wc_c" ||
echo 'demo/tpt_handle.bez: original size 2371, current size' "$Wc_c"
fi
# ============= demo/tpt_lid.bez ==============
if test -f 'demo/tpt_lid.bez' -a X"$1" != X"-c"; then
echo 'x - skipping demo/tpt_lid.bez (File already exists)'
else
echo 'x - extracting demo/tpt_lid.bez (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/tpt_lid.bez' &&
# Bezier curves (rotational body) for teapot lid.
X
bezier_curves:
X
vertices: 7
vertex_list:
X
X 0.000000e+00 7.500000e-01 0.000000e+00
X 2.000000E-01 7.500000E-01 0.000000E+00
X 0.000000E+00 6.750000E-01 0.000000E+00
X 5.000000E-02 6.375000E-01 0.000000E+00
X 1.000000E-01 6.000000E-01 0.000000E+00
X 3.250000E-01 6.000000E-01 0.000000E+00
X 3.500000E-01 5.625000E-01 0.000000E+00
X
X
curves: 2
curve_list:
X
X 1 2 3 4
X
X 4 5 6 7
SHAR_EOF
chmod 0664 demo/tpt_lid.bez ||
echo 'restore of demo/tpt_lid.bez failed'
Wc_c="`wc -c < 'demo/tpt_lid.bez'`"
test 482 -eq "$Wc_c" ||
echo 'demo/tpt_lid.bez: original size 482, current size' "$Wc_c"
fi
# ============= demo/tpt_spout.bez ==============
if test -f 'demo/tpt_spout.bez' -a X"$1" != X"-c"; then
echo 'x - skipping demo/tpt_spout.bez (File already exists)'
else
echo 'x - extracting demo/tpt_spout.bez (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/tpt_spout.bez' &&
# Bezier patches for teapot spout
X
bezier_patches:
X
vertices: 42
vertex_list:
X 4.250000E-01 3.187500E-01 0.000000E+00
X 6.500000E-01 3.187500E-01 0.000000E+00
X 5.750000E-01 4.875000E-01 0.000000E+00
X 6.750000E-01 5.625000E-01 0.000000E+00
X 7.000000E-01 5.812500E-01 0.000000E+00
X 7.250000E-01 5.812500E-01 0.000000E+00
X 7.000000E-01 5.625000E-01 0.000000E+00
X 4.250000E-01 3.187500E-01 1.650000E-01
X 6.500000E-01 3.187500E-01 1.650000E-01
X 5.750000E-01 4.875000E-01 6.250000E-02
X 6.750000E-01 5.625000E-01 6.250000E-02
X 7.000000E-01 5.812500E-01 6.250000E-02
X 7.250000E-01 5.812500E-01 3.750000E-02
X 7.000000E-01 5.625000E-01 3.750000E-02
X 4.250000E-01 1.125000E-01 1.650000E-01
X 7.750000E-01 1.687500E-01 1.650000E-01
X 6.000000E-01 4.687500E-01 6.250000E-02
X 8.250000E-01 5.625000E-01 6.250000E-02
X 8.812500E-01 5.859375E-01 6.250000E-02
X 8.625000E-01 5.906250E-01 3.750000E-02
X 8.000000E-01 5.625000E-01 3.750000E-02
X 4.250000E-01 1.125000E-01 0.000000E+00
X 7.750000E-01 1.687500E-01 0.000000E+00
X 6.000000E-01 4.687500E-01 0.000000E+00
X 8.250000E-01 5.625000E-01 0.000000E+00
X 8.812500E-01 5.859375E-01 0.000000E+00
X 8.625000E-01 5.906250E-01 0.000000E+00
X 8.000000E-01 5.625000E-01 0.000000E+00
X 4.250000E-01 1.125000E-01 -1.650000E-01
X 7.750000E-01 1.687500E-01 -1.650000E-01
X 6.000000E-01 4.687500E-01 -6.250000E-02
X 8.250000E-01 5.625000E-01 -6.250000E-02
X 8.812500E-01 5.859375E-01 -6.250000E-02
X 8.625000E-01 5.906250E-01 -3.750000E-02
X 8.000000E-01 5.625000E-01 -3.750000E-02
X 4.250000E-01 3.187500E-01 -1.650000E-01
X 6.500000E-01 3.187500E-01 -1.650000E-01
X 5.750000E-01 4.875000E-01 -6.250000E-02
X 6.750000E-01 5.625000E-01 -6.250000E-02
X 7.000000E-01 5.812500E-01 -6.250000E-02
X 7.250000E-01 5.812500E-01 -3.750000E-02
X 7.000000E-01 5.625000E-01 -3.750000E-02
X
patches: 4
patch_list:
X
22 23 24 25
15 16 17 18
X 8 9 10 11
X 1 2 3 4
X
X 1 2 3 4
36 37 38 39
29 30 31 32
22 23 24 25
X
25 26 27 28
18 19 20 21
11 12 13 14
X 4 5 6 7
X
X 4 5 6 7
39 40 41 42
32 33 34 35
25 26 27 28
SHAR_EOF
chmod 0664 demo/tpt_spout.bez ||
echo 'restore of demo/tpt_spout.bez failed'
Wc_c="`wc -c < 'demo/tpt_spout.bez'`"
test 2358 -eq "$Wc_c" ||
echo 'demo/tpt_spout.bez: original size 2358, current size' "$Wc_c"
fi
# ============= demo/woodtest.c ==============
if test -f 'demo/woodtest.c' -a X"$1" != X"-c"; then
echo 'x - skipping demo/woodtest.c (File already exists)'
else
echo 'x - extracting demo/woodtest.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'demo/woodtest.c' &&
#include <stdio.h>
#include <math.h>
X
#include <sipp.h>
#include <shaders.h>
#include <primitives.h>
X
X
Wood_desc wood_surf = {
X 0.5,
X 0.0,
X 0.99,
X 10.0,
X {0.770, 0.568, 0.405},
X {0.468, 0.296, 0.156},
};
X
X
extern char *optarg;
X
main(argc, argv)
X int argc;
X char **argv;
{
X FILE *fp ;
X
X char *imfile_name;
X int mode;
X char c;
X int size;
X
X imfile_name = "wood.ppm";
X mode = PHONG;
X size = 256;
X
X while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
X switch (c) {
X case 'p':
X mode = PHONG;
X imfile_name = "wood.ppm";
X break;
X
X case 'g':
X mode = GOURAUD;
X imfile_name = "wood.ppm";
X break;
X
X case 'f':
X mode = FLAT;
X imfile_name = "wood.ppm";
X break;
X
X case 'l':
X mode = LINE;
X imfile_name = "wood.pbm";
X break;
X
X case 's':
X size = atoi(optarg);
X break;
X }
X }
X
X sipp_init();
X
X lightsource_push(1.0, 1.0, 1.0, 0.9);
X
X object_install(sipp_block(4.0, 3.0, 3.0, &wood_surf, wood_shader));
X
X viewpoint(10.0, 10.0, 20.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.125);
X
X printf("Rendering, wait...");
X fflush(stdout);
X
X fp = fopen(imfile_name, "w");
X render_image_file(size, size, fp, mode, 2);
X printf("Done.\n");
X
X exit(0);
}
SHAR_EOF
chmod 0644 demo/woodtest.c ||
echo 'restore of demo/woodtest.c failed'
Wc_c="`wc -c < 'demo/woodtest.c'`"
test 1441 -eq "$Wc_c" ||
echo 'demo/woodtest.c: original size 1441, current size' "$Wc_c"
fi
exit 0
--
------------------------------------------------------------------------------
J o n a s Y n g v e s s o n
Dept. of Electrical Engineering jonas-y@isy.liu.se
University of Linkoping, Sweden ...!uunet!isy.liu.se!jonas-y
exit 0 # Just in case...