[go: up one dir, main page]

File: xchain.c

package info (click to toggle)
sipp 3.1-11
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,268 kB
  • ctags: 744
  • sloc: ansic: 8,534; makefile: 304; lex: 65; sh: 14
file content (118 lines) | stat: -rw-r--r-- 2,817 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * Example of how to use the xrender function.
 */

#include <stdio.h>
#include <math.h>

#include <sipp.h>
#include <primitives.h>



#define SMALLRES 15
#define BIGRES   39

extern char *optarg;

main(argc, argv)
    int    argc;
    char **argv;
{
    Object  *torus;
    Object  *torus_pair;
    Object  *chain;
    FILE    *fp ;
    Surf_desc surf;

    char    *imfile_name;
    int      mode;
    int      c;
    int      size;

    imfile_name = "chain.ppm";
    mode = PHONG;
    size = 256;

    while ((c = getopt(argc, argv, "pgfls:")) != EOF) {
        switch (c) {
          case 'p':
            mode = PHONG;
            imfile_name = "chain.ppm";
            break;

          case 'g':
            mode = GOURAUD;
            imfile_name = "chain.ppm";
            break;

          case 'f':
            mode = FLAT;
            imfile_name = "chain.ppm";
            break;

          case 'l':
            mode = LINE;
            imfile_name = "chain.pbm";
            break;

          case 's':
            size = atoi(optarg);
            break;
        }
    }

    sipp_init();

    lightsource_create(1.0, 1.0, 1.0, 0.9, 0.9, 0.9, LIGHT_DIRECTION);
    lightsource_create(-1.0, -1.0, 0.5, 0.4, 0.4, 0.4, LIGHT_DIRECTION);

    surf.ambient = 0.5;
    surf.specular = 0.6;
    surf.c3 = 0.2;
    surf.color.red = 0.8;
    surf.color.grn = 0.6;
    surf.color.blu = 0.3;
    surf.opacity.red = 1.0;
    surf.opacity.grn = 1.0;
    surf.opacity.blu = 1.0;
    
    torus = sipp_torus(1.0, 0.23, BIGRES, SMALLRES, &surf, basic_shader, 
                       WORLD);
    torus_pair = object_create();
    object_add_subobj(torus_pair, torus);
    torus = object_instance(torus);
    object_move(torus, 0.0, -1.375, 0.0);
    object_rot_y(torus, M_PI / 2.0);
    object_add_subobj(torus_pair, torus);
    
    chain = object_create();
    object_move(torus_pair, -1.375, 1.375, 0.0);
    object_add_subobj(chain, torus_pair);
    torus_pair = object_instance(torus_pair);
    object_rot_z(torus_pair, M_PI / 2.0);
    object_move(torus_pair, -1.375, -1.375, 0.0);
    object_add_subobj(chain, torus_pair);
    torus_pair = object_instance(torus_pair);
    object_rot_z(torus_pair, M_PI);
    object_move(torus_pair, 1.375, -1.375, 0.0);
    object_add_subobj(chain, torus_pair);
    torus_pair = object_instance(torus_pair);
    object_rot_z(torus_pair, 3.0 * M_PI / 2.0);
    object_move(torus_pair, 1.375, 1.375, 0.0);
    object_add_subobj(chain, torus_pair);
    
    object_add_subobj(sipp_world, chain);

    camera_params(sipp_camera, 5.0, -2.0, 15.0,  0.5, 0.0, 0.0, 
                  0.0, 0.0, 1.0,  0.25);

    /*
     * Change parameters in this call to try out
     * the various features.
     */
    render_ximage(size, size, mode, 2, 1, 0, 0);

    sleep(20);
    exit(0);
}