-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnurbtst.c
131 lines (108 loc) · 3.67 KB
/
nurbtst.c
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
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
* nurbtst.c - Simple file to create a single NURB patch
*
* Author: Alexander Enzmann
*
* Modified: 1 December 2012 - correct sensible size factor (relevant to
* output naming). Fix yellow/magenta mix up. Make image size match
* other dbs (512x512)
* Sam [sbt] Thompson
*
* size_factor is ignored.
*
*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h> /* atoi */
#include "def.h"
#include "drv.h" /* display_close() */
#include "lib.h"
/* These may be read from the command line */
static int size_factor = 0;
static int raytracer_format = OUTPUT_RT_DEFAULT;
static int output_format = OUTPUT_CURVES;
#ifdef OUTPUT_TO_FILE
static FILE * stdout_file = NULL;
#else
#define stdout_file stdout
#endif /* OUTPUT_TO_FILE */
/* Some standard colors */
static COORD3 White = { 1.0, 1.0, 1.0 };
static COORD3 Red = { 1.0, 0.0, 0.0 };
static COORD3 Green = { 0.0, 1.0, 0.0 };
static COORD3 Blue = { 0.0, 0.0, 1.0 };
static COORD3 Cyan = { 0.0, 1.0, 1.0 };
static COORD3 Magenta = { 1.0, 0.0, 1.0 };
static COORD3 Yellow = { 1.0, 1.0, 0.0 };
static COORD3 Black = { 0.0, 0.0, 0.0 };
float nknots[] = {0, 0, 0, 0, 1.5, 1.5, 3, 3, 3, 3}; /* Non-uniform knot vector */
float mknots[] = {0, 0, 0, 0, 1, 2, 2, 2, 2}; /* Uniform open knot vector */
COORD4 ctlpts0[] = {{ 0, 0, 0, 1}, { 1, 0, 3, 1}, { 2, 0,-3, 1},
{ 3, 0, 3, 1}, { 4, 0, 0, 1}};
COORD4 ctlpts1[] = {{ 0, 1, 0, 1}, { 1, 1, 0, 1}, { 2, 1, 0, 1},
{ 3, 1, 0, 1}, { 4, 1, 0, 1}};
COORD4 ctlpts2[] = {{ 0, 2, 0, 1}, { 1, 2, 0, 2}, { 2, 2, 5, 0.5},
{ 3, 2, 0, 1}, { 4, 2, 0, 1}};
COORD4 ctlpts3[] = {{ 0, 3, 0, 1}, { 1, 3, 0, 2}, { 2, 3, 5, 0.5},
{ 3, 3, 0, 1}, { 4, 3, 0, 1}};
COORD4 ctlpts4[] = {{ 0, 4, 0, 1}, { 1, 4, 0, 1}, { 2, 4, 0, 20},
{ 3, 4, 0, 1}, { 4, 4, 0, 1}};
COORD4 ctlpts5[] = {{ 0, 5, 0, 1}, { 1, 5,-3, 1}, { 2, 5, 3, 1},
{ 3, 5,-3, 1}, { 4, 5, 0, 1}};
/* Build a single NURB patch and dump it */
static void
create_a_nurb(curve_format)
int curve_format ;
{
COORD4 *ctlpts[6];
COORD3 vec;
lib_output_color(NULL, Red, 0.1, 0.7, 0.0, 0.7, 10.0, 0.0, 1.0);
ctlpts[0] = ctlpts0;
ctlpts[1] = ctlpts1;
ctlpts[2] = ctlpts2;
ctlpts[3] = ctlpts3;
ctlpts[4] = ctlpts4;
ctlpts[5] = ctlpts5;
lib_tx_push();
lib_tx_rotate(Y, DEG2RAD(30.0));
lib_tx_rotate(X, DEG2RAD(-90.0));
SET_COORD3(vec, -2.0, -2.5, 0.0);
lib_tx_translate(vec);
PLATFORM_PROGRESS(0, 1, 2);
/* lib_output_nurb(4, 6, 4, 5, nknots, mknots, ctlpts, curve_format); */
lib_output_nurb(4, 6, 4, 5, NULL, NULL, ctlpts, curve_format);
PLATFORM_PROGRESS(0, 2, 2);
lib_tx_pop();
}
/* Main driver - looks the same as every other SPD file... */
int
main(argc, argv)
int argc;
char *argv[];
{
COORD4 from, at, up;
COORD4 center;
PLATFORM_INIT(SPD_NURBTST);
/* Start by defining which raytracer we will be using */
if ( lib_gen_get_opts( argc, argv,
&size_factor, &raytracer_format, &output_format ) ) {
return EXIT_FAIL;
}
if ( lib_open( raytracer_format, "NurbTst" ) ) {
return EXIT_FAIL;
}
lib_set_polygonalization(5, 5);
/* output background color */
/* NOTE: Do this BEFORE lib_output_viewpoint(), for display_init() */
lib_output_background_color( Black ) ;
SET_COORD3(from, 0, 5, -10);
SET_COORD3(at, 0, 0, 0);
SET_COORD3(up, 0, 1, 0);
lib_output_viewpoint(from, at, up, 30.0, 1.0, 0.001, 512, 512);
SET_COORD4(center, 0, 50, -10, 1.0);
lib_output_light(center);
create_a_nurb(output_format);
lib_close();
PLATFORM_SHUTDOWN();
return EXIT_SUCCESS;
}